Example #1
0
        protected internal override GrammarNode createGrammar()
        {
            GrammarNode grammarNode = null;
            int         num         = this.createNodes(this.path);

            num++;
            GrammarNode grammarNode2 = this.createGrammarNode(num, "<sil>");

            grammarNode2.setFinalNode(true);
            num = this.expandWordNodes(num);
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(this.path, true);

            while (!extendedStreamTokenizer.isEOF())
            {
                extendedStreamTokenizer.skipwhite();
                string @string = extendedStreamTokenizer.getString();
                if (@string == null)
                {
                    break;
                }
                if (String.instancehelper_equals(@string, "I"))
                {
                    if (!FSTGrammar.assertionsDisabled && grammarNode != null)
                    {
                        throw new AssertionError();
                    }
                    int    @int = extendedStreamTokenizer.getInt("initial ID");
                    string text = new StringBuilder().append("G").append(@int).toString();
                    grammarNode = this.createGrammarNode(@int, "<sil>");
                    this.nodes.put(text, grammarNode);
                    if (this.addInitialSilenceNode)
                    {
                        num++;
                        GrammarNode grammarNode3 = this.createGrammarNode(num, "<sil>");
                        grammarNode.add(grammarNode3, 0f);
                        grammarNode3.add(grammarNode, 0f);
                    }
                }
                else if (String.instancehelper_equals(@string, "T"))
                {
                    int         @int         = extendedStreamTokenizer.getInt("this id");
                    int         int2         = extendedStreamTokenizer.getInt("next id");
                    GrammarNode grammarNode3 = this.get(@int);
                    GrammarNode grammarNode4 = this.get(int2);
                    if (this.hasEndNode(grammarNode3))
                    {
                        grammarNode3 = this.getEndNode(grammarNode3);
                    }
                    float  num2    = 0f;
                    string string2 = extendedStreamTokenizer.getString();
                    if (string2 == null || String.instancehelper_equals(string2, ","))
                    {
                        if (string2 != null && String.instancehelper_equals(string2, ","))
                        {
                            extendedStreamTokenizer.getString();
                            num2 = extendedStreamTokenizer.getFloat("probability");
                        }
                        if (this.hasEndNode(grammarNode4))
                        {
                            grammarNode4 = this.getEndNode(grammarNode4);
                        }
                    }
                    else
                    {
                        string string3 = extendedStreamTokenizer.getString();
                        num2 = extendedStreamTokenizer.getFloat("probability");
                        if (String.instancehelper_equals(string3, "<unknown>"))
                        {
                            continue;
                        }
                        if (!FSTGrammar.assertionsDisabled && !this.hasWord(grammarNode4))
                        {
                            throw new AssertionError();
                        }
                    }
                    grammarNode3.add(grammarNode4, this.convertProbability(num2));
                }
                else if (String.instancehelper_equals(@string, "F"))
                {
                    int         @int         = extendedStreamTokenizer.getInt("this id");
                    float       @float       = extendedStreamTokenizer.getFloat("probability");
                    GrammarNode grammarNode3 = this.get(@int);
                    GrammarNode grammarNode4 = grammarNode2;
                    if (this.hasEndNode(grammarNode3))
                    {
                        grammarNode3 = this.getEndNode(grammarNode3);
                    }
                    grammarNode3.add(grammarNode4, this.convertProbability(@float));
                }
            }
            extendedStreamTokenizer.close();
            if (!FSTGrammar.assertionsDisabled && grammarNode == null)
            {
                throw new AssertionError();
            }
            return(grammarNode);
        }
Example #2
0
 private bool hasWord(GrammarNode grammarNode)
 {
     return(grammarNode.getNumAlternatives() > 0);
 }
Example #3
0
        protected internal override GrammarNode createGrammar()
        {
            this.languageModel.allocate();
            TimerPool.getTimer(this, "LMGrammar.create").start();
            GrammarNode grammarNode = null;

            if (this.languageModel.getMaxDepth() > 2)
            {
                [email protected]("Warning: LMGrammar  limited to bigrams");
            }
            ArrayList arrayList  = new ArrayList();
            Set       vocabulary = this.languageModel.getVocabulary();
            Iterator  iterator   = vocabulary.iterator();

            while (iterator.hasNext())
            {
                string      word         = (string)iterator.next();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                if (grammarNode2 != null && !grammarNode2.isEmpty())
                {
                    if (grammarNode2.getWord().equals(this.getDictionary().getSentenceStartWord()))
                    {
                        grammarNode = grammarNode2;
                    }
                    else if (grammarNode2.getWord().equals(this.getDictionary().getSentenceEndWord()))
                    {
                        grammarNode2.setFinalNode(true);
                    }
                    arrayList.add(grammarNode2);
                }
            }
            if (grammarNode == null)
            {
                string text = "No sentence start found in language model";

                throw new Error(text);
            }
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                GrammarNode grammarNode3 = (GrammarNode)iterator.next();
                if (!grammarNode3.isFinalNode())
                {
                    Iterator iterator2 = arrayList.iterator();
                    while (iterator2.hasNext())
                    {
                        GrammarNode grammarNode4 = (GrammarNode)iterator2.next();
                        string      spelling     = grammarNode3.getWord().getSpelling();
                        string      spelling2    = grammarNode4.getWord().getSpelling();
                        Word[]      words        = new Word[]
                        {
                            this.getDictionary().getWord(spelling),
                            this.getDictionary().getWord(spelling2)
                        };
                        float probability = this.languageModel.getProbability(new WordSequence(words));
                        grammarNode3.add(grammarNode4, probability);
                    }
                }
            }
            TimerPool.getTimer(this, "LMGrammar.create").stop();
            this.languageModel.deallocate();
            return(grammarNode);
        }
Example #4
0
 private bool hasEndNode(GrammarNode grammarNode)
 {
     return(this.expandedNodes.contains(grammarNode));
 }
Example #5
0
        protected internal virtual GrammarNode createForcedAlignerGrammar(GrammarNode iNode, GrammarNode fNode, string transcript)
        {
            StringTokenizer stringTokenizer = new StringTokenizer(transcript);
            GrammarNode     grammarNode     = null;
            GrammarNode     grammarNode2    = null;

            while (stringTokenizer.hasMoreTokens())
            {
                string      word         = stringTokenizer.nextToken();
                GrammarNode grammarNode3 = grammarNode2;
                grammarNode2 = this.createGrammarNode(word);
                if (grammarNode == null)
                {
                    grammarNode = grammarNode2;
                }
                if (grammarNode3 != null)
                {
                    grammarNode3.add(grammarNode2, 0f);
                }
            }
            iNode.add(grammarNode, 0f);
            grammarNode2.add(fNode, 0f);
            return(grammarNode);
        }