コード例 #1
0
        /**
         * /// 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);
        }
コード例 #2
0
 private void init()
 {
     this.skipSeqs.add(this.eps);
     this.skipSeqs.add(this.sb);
     this.skipSeqs.add(this.se);
     this.skipSeqs.add(this.skip);
     this.skipSeqs.add("-");
     Compose.augment(0, this.g2pmodel, this.g2pmodel.getSemiring());
     ArcSort.apply(this.g2pmodel, new ILabelCompare());
     string[] isyms = this.g2pmodel.getIsyms();
     this.loadClusters(isyms);
     this.epsilonFilter = Compose.getFilter(this.g2pmodel.getIsyms(), this.g2pmodel.getSemiring());
     ArcSort.apply(this.epsilonFilter, new ILabelCompare());
 }
コード例 #3
0
        public void ArcSort_Test()
        {
            // Input label sort test
            var fst1 = CreateUnsorted();
            var fst2 = CreateIsorted();

            Assert.AreNotEqual(fst1, fst2);
            ArcSort.Apply(fst1, new ILabelCompare());
            Assert.AreEqual(fst1, fst2);

            // Output label sort test
            fst1 = CreateUnsorted();
            fst2 = CreateOsorted();
            Assert.AreNotEqual(fst1, fst2);
            ArcSort.Apply(fst1, new OLabelCompare());
            Assert.AreEqual(fst1, fst2);
        }
コード例 #4
0
        ///**
        ///// Create a decoder by loading the serialized model from a specified
        ///// filename
        /////
        ///// @param g2pmodel_file
        /////            the filename of the serialized model
        // */
        //public G2PConverter(String g2pmodel_file)
        //{
        //    g2pmodel = ImmutableFst.loadModel(g2pmodel_file);
        //    init();
        //}

        /**
         * /// 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.Semiring);
            ArcSort.Apply(_g2Pmodel, new ILabelCompare());

            var isyms = _g2Pmodel.Isyms;

            LoadClusters(isyms);

            // get epsilon filter for composition
            _epsilonFilter = Compose.GetFilter(_g2Pmodel.Isyms, _g2Pmodel.Semiring);
            ArcSort.Apply(_epsilonFilter, new ILabelCompare());
        }
コード例 #5
0
        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));
        }