/** * /// Phoneticize a word * /// * /// @param entry * /// the word to phoneticize transformed to an ArrayList of Strings * /// (each element hold a single character) * /// @param nbest * /// the number of distinct pronunciations to return * /// @return the pronunciation(s) of the input word */ public List <Path> Phoneticize(List <String> entry, int nbest) { var efst = EntryToFsa(entry); var s = efst.Semiring; Compose.Augment(1, efst, s); ArcSort.Apply(efst, new OLabelCompare()); var 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) { result = NShortestPaths.Get(result, 1, false); } else { // Requesting 10 times more best paths than what was asking // as there might be several paths resolving to same pronunciation // due to epsilon transitions. // I really hate cosmological constants :) result = NShortestPaths.Get(result, nbest * 10, false); } // result = NShortestPaths.get(result, nbest, false); result = RmEpsilon.Get(result); var paths = FindAllPaths(result, nbest, _skipSeqs, Tie); return(paths); }
public virtual ArrayList phoneticize(ArrayList entry, int nbest) { Fst fst = this.entryToFSA(entry); Semiring semiring = fst.getSemiring(); Compose.augment(1, fst, semiring); ArcSort.apply(fst, new OLabelCompare()); Fst fst2 = Compose.compose(fst, this.epsilonFilter, semiring, true); ArcSort.apply(fst2, new OLabelCompare()); fst2 = Compose.compose(fst2, this.g2pmodel, semiring, true); Project.apply(fst2, ProjectType.__OUTPUT); if (nbest == 1) { fst2 = NShortestPaths.get(fst2, 1, false); } else { fst2 = NShortestPaths.get(fst2, nbest * 10, false); } fst2 = RmEpsilon.get(fst2); return(this.findAllPaths(fst2, nbest, this.skipSeqs, this.tie)); }