/** * Computes the composition of two Fsts. The two Fsts are augmented in order * to avoid multiple epsilon paths in the resulting Fst * * @param fst1 the first Fst * @param fst2 the second Fst * @param semiring the semiring to use in the operation * @return the composed Fst */ public static Fst get(Fst fst1, Fst fst2, Semiring semiring) { if ((fst1 == null) || (fst2 == null)) { return null; } if (!Arrays.equals(fst1.getOsyms(), fst2.getIsyms())) { // symboltables do not match return null; } Fst filter = getFilter(fst1.getOsyms(), semiring); augment(1, fst1, semiring); augment(0, fst2, semiring); Fst tmp = Compose.compose(fst1, filter, semiring, false); Fst res = Compose.compose(tmp, fst2, semiring, false); // Connect.apply(res); return res; }
@Test public void testCompose() throws NumberFormatException, IOException, URISyntaxException { URL url = getClass().getResource("algorithms/composeeps/A.fst.txt"); File parent = new File(url.toURI()).getParentFile(); String path = new File(parent, "A").getPath(); Fst fstA = importFst(path, new TropicalSemiring()); path = new File(parent, "B").getPath(); Fst fstB = importFst(path, new TropicalSemiring()); path = new File(parent, "fstcomposeeps").getPath(); Fst fstC = importFst(path, new TropicalSemiring()); Fst fstComposed = get(fstA, fstB, new TropicalSemiring()); assertThat(fstC, equalTo(fstComposed)); }
/** * Initialize the decoder */ private void init() { skipSeqs.add(eps); skipSeqs.add(sb); skipSeqs.add(se); skipSeqs.add(skip); skipSeqs.add("-"); // keep an augmented copy (for compose) Compose.augment(0, g2pmodel, g2pmodel.getSemiring()); ArcSort.apply(g2pmodel, new ILabelCompare()); String[] isyms = g2pmodel.getIsyms(); loadClusters(isyms); // get epsilon filter for composition epsilonFilter = Compose.getFilter(g2pmodel.getIsyms(), g2pmodel.getSemiring()); ArcSort.apply(epsilonFilter, new ILabelCompare()); }
Fst efst = entryToFSA(entry); Semiring s = efst.getSemiring(); Compose.augment(1, efst, s); ArcSort.apply(efst, new OLabelCompare()); Fst result = Compose.compose(efst, epsilonFilter, s, true); ArcSort.apply(result, new OLabelCompare()); result = Compose.compose(result, g2pmodel, s, true); Project.apply(result, ProjectType.OUTPUT); if (nbest == 1) {
/** * Initialize the decoder */ private void init() { skipSeqs.add(eps); skipSeqs.add(sb); skipSeqs.add(se); skipSeqs.add(skip); skipSeqs.add("-"); // keep an augmented copy (for compose) Compose.augment(0, g2pmodel, g2pmodel.getSemiring()); ArcSort.apply(g2pmodel, new ILabelCompare()); String[] isyms = g2pmodel.getIsyms(); loadClusters(isyms); // get epsilon filter for composition epsilonFilter = Compose.getFilter(g2pmodel.getIsyms(), g2pmodel.getSemiring()); ArcSort.apply(epsilonFilter, new ILabelCompare()); }
Fst efst = entryToFSA(entry); Semiring s = efst.getSemiring(); Compose.augment(1, efst, s); ArcSort.apply(efst, new OLabelCompare()); Fst result = Compose.compose(efst, epsilonFilter, s, true); ArcSort.apply(result, new OLabelCompare()); result = Compose.compose(result, g2pmodel, s, true); Project.apply(result, ProjectType.OUTPUT); if (nbest == 1) {
/** * Computes the composition of two Fsts. The two Fsts are augmented in order * to avoid multiple epsilon paths in the resulting Fst * * @param fst1 the first Fst * @param fst2 the second Fst * @param semiring the semiring to use in the operation * @return the composed Fst */ public static Fst get(Fst fst1, Fst fst2, Semiring semiring) { if ((fst1 == null) || (fst2 == null)) { return null; } if (!Arrays.equals(fst1.getOsyms(), fst2.getIsyms())) { // symboltables do not match return null; } Fst filter = getFilter(fst1.getOsyms(), semiring); augment(1, fst1, semiring); augment(0, fst2, semiring); Fst tmp = Compose.compose(fst1, filter, semiring, false); Fst res = Compose.compose(tmp, fst2, semiring, false); // Connect.apply(res); return res; }
@Test public void testCompose() throws NumberFormatException, IOException, ClassNotFoundException, URISyntaxException { String path = "algorithms/compose/fstcompose.fst.ser"; URL url = getClass().getResource(path); File parent = new File(url.toURI()).getParentFile(); path = new File(parent, "A").getPath(); Fst fstA = importFst(path, new TropicalSemiring()); path = new File(parent, "B").getPath(); Fst fstB = importFst(path, new TropicalSemiring()); path = new File(parent, "fstcompose.fst.ser").getPath(); Fst composed = Fst.loadModel(path); Fst fstComposed = Compose.get(fstA, fstB, new TropicalSemiring()); assertThat(composed, equalTo(fstComposed)); } }