protected internal override GrammarNode createGrammar()
        {
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(this.path, true);
            GrammarNode             grammarNode             = this.createGrammarNode("<sil>");
            GrammarNode             grammarNode2            = this.createGrammarNode(false);
            GrammarNode             grammarNode3            = this.createGrammarNode("<sil>");

            grammarNode3.setFinalNode(true);
            LinkedList linkedList = new LinkedList();

            while (!extendedStreamTokenizer.isEOF())
            {
                string @string;
                while ((@string = extendedStreamTokenizer.getString()) != null)
                {
                    GrammarNode grammarNode4 = this.createGrammarNode(@string);
                    linkedList.add(grammarNode4);
                }
            }
            grammarNode.add(grammarNode2, 0f);
            float    logProbability = this.logMath.linearToLog((double)1f / (double)linkedList.size());
            Iterator iterator       = linkedList.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode5 = (GrammarNode)iterator.next();
                grammarNode2.add(grammarNode5, logProbability);
                grammarNode5.add(grammarNode3, 0f);
                if (this.isLooping)
                {
                    grammarNode5.add(grammarNode2, 0f);
                }
            }
            return(grammarNode);
        }
예제 #2
0
        protected internal override GrammarNode createGrammar()
        {
            if (this.lattice == null)
            {
                return(this.createGrammarNode("<s>"));
            }
            GrammarNode grammarNode = null;
            HashMap     hashMap     = new HashMap();
            Iterator    iterator    = this.lattice.getNodes().iterator();

            while (iterator.hasNext())
            {
                Node        node         = (Node)iterator.next();
                string      word         = node.getWord().toString();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                if (node.equals(this.lattice.getInitialNode()))
                {
                    grammarNode = grammarNode2;
                }
                if (node.equals(this.lattice.getTerminalNode()))
                {
                    grammarNode2.setFinalNode(true);
                }
                hashMap.put(node, grammarNode2);
            }
            if (grammarNode == null)
            {
                string text = "No lattice start found";

                throw new Error(text);
            }
            iterator = this.lattice.getEdges().iterator();
            while (iterator.hasNext())
            {
                Edge        edge           = (Edge)iterator.next();
                float       logProbability = (float)edge.getLMScore();
                GrammarNode grammarNode2   = (GrammarNode)hashMap.get(edge.getFromNode());
                GrammarNode node2          = (GrammarNode)hashMap.get(edge.getToNode());
                grammarNode2.add(node2, logProbability);
            }
            return(grammarNode);
        }
예제 #3
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);
        }
예제 #4
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);
        }