Exemple #1
0
        protected internal virtual Collection compileGrammar()
        {
            this.initialGrammarState = this.grammar.getInitialNode();
            this.nodeStateMap        = new HashMap();
            this.arcPool             = new Cache();
            ArrayList arrayList = new ArrayList();

            TimerPool.getTimer(this, "Compile").start();
            TimerPool.getTimer(this, "Create States").start();
            Iterator iterator = this.grammar.getGrammarNodes().iterator();

            while (iterator.hasNext())
            {
                GrammarNode         grammarNode = (GrammarNode)iterator.next();
                FlatLinguist.GState gstate      = this.createGState(grammarNode);
                arrayList.add(gstate);
            }
            TimerPool.getTimer(this, "Create States").stop();
            this.addStartingPath();
            TimerPool.getTimer(this, "Collect Contexts").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.collectContexts();
            }
            TimerPool.getTimer(this, "Collect Contexts").stop();
            TimerPool.getTimer(this, "Expand States").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.expand();
            }
            TimerPool.getTimer(this, "Expand States").stop();
            TimerPool.getTimer(this, "Connect Nodes").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.connect();
            }
            TimerPool.getTimer(this, "Connect Nodes").stop();
            SentenceHMMState sentenceHMMState = this.findStartingState();

            if (this.addOutOfGrammarBranch)
            {
                CIPhoneLoop      ciphoneLoop = new CIPhoneLoop(this.phoneLoopAcousticModel, this.logPhoneInsertionProbability);
                SentenceHMMState nextState   = (SentenceHMMState)ciphoneLoop.getSearchGraph().getInitialState();
                sentenceHMMState.connect(this.getArc(nextState, 0f, this.logOutOfGrammarBranchProbability));
            }
            this.searchGraph = new FlatLinguist.FlatSearchGraph(this, sentenceHMMState);
            TimerPool.getTimer(this, "Compile").stop();
            if (this.dumpGStates)
            {
                Iterator iterator2 = this.grammar.getGrammarNodes().iterator();
                while (iterator2.hasNext())
                {
                    GrammarNode         node    = (GrammarNode)iterator2.next();
                    FlatLinguist.GState gstate3 = this.getGState(node);
                    gstate3.dumpInfo();
                }
            }
            this.nodeStateMap = null;
            this.arcPool      = null;
            return(SentenceHMMState.collectStates(sentenceHMMState));
        }