/** Gets the initial grammar node from the linguist and creates a GrammarNodeToken */ protected void localStart() { ISearchGraph searchGraph = linguist.getSearchGraph(); currentFrameNumber = 0; curTokensScored.value = 0; numStateOrder = searchGraph.getNumStateOrder(); activeListManager.setNumStateOrder(numStateOrder); if (buildWordLattice) { loserManager = new AlternateHypothesisManager(maxLatticeEdges); } ISearchState state = searchGraph.getInitialState(); activeList = activeListManager.getEmittingList(); activeList.add(new Token(state, currentFrameNumber)); clearCollectors(); growBranches(); growNonEmittingBranches(); // tokenTracker.setEnabled(false); // tokenTracker.startUtterance(); }
/** Compiles the n-gram into a lex tree that is used during the search */ private void CompileGrammar() { TimerPool.GetTimer(this, "Compile").Start(); SentenceEndWord = Dictionary.GetSentenceEndWord(); _sentenceStartWordArray = new Word[1]; _sentenceStartWordArray[0] = Dictionary.GetSentenceStartWord(); MaxDepth = LanguageModel.MaxDepth; GenerateHmmTree(); TimerPool.GetTimer(this, "Compile").Stop(); // Now that we are all done, dump out some interesting // information about the process _searchGraph = new LexTreeSearchGraph(GetInitialSearchState()); }
/// <summary> /// Compiles the grammar into a sentence HMM. A GrammarJob is created for the /// initial grammar node and added to the GrammarJob queue. While there are /// jobs left on the grammar job queue, a job is removed from the queue and /// the associated grammar node is expanded and attached to the tails. /// GrammarJobs for the successors are added to the grammar job queue. /// </summary> /// <returns></returns> protected HashSet <SentenceHMMState> CompileGrammar() { InitialGrammarState = Grammar.InitialNode; NodeStateMap = new HashMap <GrammarNode, GState>(); // create in declaration section (22.12.2014) ArcPool = new Cache <SentenceHMMStateArc>(); var gstateList = new List <GState>(); TimerPool.GetTimer(this, "Compile").Start(); // get the nodes from the grammar and create states // for them. Add the non-empty gstates to the gstate list. TimerPool.GetTimer(this, "Create States").Start(); foreach (var grammarNode in Grammar.GrammarNodes) { var gstate = CreateGState(grammarNode); gstateList.Add(gstate); } TimerPool.GetTimer(this, "Create States").Stop(); AddStartingPath(); // ensures an initial path to the start state // Prep all the gstates, by gathering all of the contexts up // this allows each gstate to know about its surrounding contexts TimerPool.GetTimer(this, "Collect Contexts").Start(); foreach (var gstate in gstateList) { gstate.CollectContexts(); } TimerPool.GetTimer(this, "Collect Contexts").Stop(); // now all gstates know all about their contexts, we can expand them fully TimerPool.GetTimer(this, "Expand States").Start(); foreach (var gstate in gstateList) { gstate.Expand(); } TimerPool.GetTimer(this, "Expand States").Stop(); // now that all states are expanded fully, we can connect all the states up TimerPool.GetTimer(this, "Connect Nodes").Start(); foreach (var gstate in gstateList) { gstate.Connect(); } TimerPool.GetTimer(this, "Connect Nodes").Stop(); var initialState = FindStartingState(); // add an out-of-grammar branch if configured to do so if (AddOutOfGrammarBranch) { var phoneLoop = new CIPhoneLoop(PhoneLoopAcousticModel, LogPhoneInsertionProbability); var firstBranchState = (SentenceHMMState)phoneLoop.GetSearchGraph().InitialState; initialState.Connect(GetArc(firstBranchState, LogOne, LogOutOfGrammarBranchProbability)); } _searchGraph = new FlatSearchGraph(initialState); TimerPool.GetTimer(this, "Compile").Stop(); // Now that we are all done, dump out some interesting // information about the process if (_dumpGStates) { foreach (var grammarNode in Grammar.GrammarNodes) { var gstate = GetGState(grammarNode); gstate.DumpInfo(); } } NodeStateMap = null; ArcPool = null; return(SentenceHMMState.CollectStates(initialState)); }