/// <summary> /// Gets the initial grammar node from the linguist and creates a GrammarNodeToken. /// </summary> protected virtual void LocalStart() { var searchGraph = Linguist.SearchGraph; CurrentFrameNumber = 0; CurTokensScored.Value = 0; _numStateOrder = searchGraph.NumStateOrder; _activeListManager.SetNumStateOrder(_numStateOrder); if (BuildWordLattice) { LoserManager = new AlternateHypothesisManager(_maxLatticeEdges); } var state = searchGraph.InitialState; ActiveList = _activeListManager.GetEmittingList(); ActiveList.Add(new Token(state, CurrentFrameNumber)); ClearCollectors(); GrowBranches(); GrowNonEmittingBranches(); // tokenTracker.setEnabled(false); // tokenTracker.startUtterance(); }
/// <summary> /// Gets the initial grammar node from the linguist and creates a GrammarNodeToken. /// </summary> protected void LocalStart() { CurrentFrameNumber = 0; _curTokensScored.Value = 0; ActiveList newActiveList = ActiveListFactory.NewInstance(); ISearchState state = Linguist.SearchGraph.InitialState; newActiveList.Add(new Token(state, CurrentFrameNumber)); ActiveList = newActiveList; GrowBranches(); }
/** * /// Adds the given token to the list * * /// @param token the token to add */ public override void Add(Token token) { ActiveList activeList = FindListFor(token); if (activeList == null) { throw new Exception("Cannot find ActiveList for " + token.SearchState.GetType().Name); } //this.LogDebug("Token '{0}' to activeList of Size {1}", token, activeList.size()); activeList.Add(token); }
/// <summary> /// Gets the initial grammar node from the linguist and creates a GrammarNodeToken /// </summary> protected override void LocalStart() { _currentFastMatchFrameNumber = 0; if (_loader is Sphinx3Loader && ((Sphinx3Loader)_loader).HasTiedMixtures()) { ((Sphinx3Loader)_loader).ClearGauScores(); } // prepare fast match active list FastmatchActiveList = _fastmatchActiveListFactory.NewInstance(); var fmInitState = _fastmatchLinguist.SearchGraph.InitialState; FastmatchActiveList.Add(new Token(fmInitState, _currentFastMatchFrameNumber)); CreateFastMatchBestTokenMap(); GrowFastmatchBranches(); _fastmatchStreamEnd = false; for (var i = 0; (i < _lookaheadWindow - 1) && !_fastmatchStreamEnd; i++) { FastMatchRecognize(); } base.LocalStart(); }
/** * /// Collects the next set of emitting tokens from a token and accumulates them in the active or result lists * * /// @param token the token to collect successors from */ protected void CollectSuccessorTokens(Token token) { ISearchState state = token.SearchState; // If this is a final state, add it to the final list if (token.IsFinal) { ResultList.Add(token); } if (token.Score < _threshold) { return; } if (state is IWordSearchState && token.Score < _wordThreshold) { return; } ISearchStateArc[] arcs = state.GetSuccessors(); //this.LogDebug("Arcs Count: {0}", arcs.Length); // For each successor // calculate the entry score for the token based upon the // predecessor token score and the transition probabilities // if the score is better than the best score encountered for // the SearchState and frame then create a new token, add // it to the lattice and the SearchState. // If the token is an emitting token add it to the list, // otherwise recursively collect the new tokens successors. foreach (ISearchStateArc arc in arcs) { ISearchState nextState = arc.State; // this.LogDebug("Next State: {0}",nextState); // We're actually multiplying the variables, but since // these come in log(), multiply gets converted to add float logEntryScore = token.Score + arc.GetProbability(); //this.LogDebug("LogEntryScore: {0}", logEntryScore); if (_wantEntryPruning) { // false by default if (logEntryScore < _threshold) { continue; } if (nextState is IWordSearchState && logEntryScore < _wordThreshold) { continue; } } Token predecessor = GetResultListPredecessor(token); // this.LogDebug("Predecessor: {0}", predecessor); // if not emitting, check to see if we've already visited // this state during this frame. Expand the token only if we // haven't visited it already. This prevents the search // from getting stuck in a loop of states with no // intervening emitting nodes. This can happen with nasty // jsgf grammars such as ((foo*)*)* if (!nextState.IsEmitting) { Token newToken = new Token(predecessor, nextState, logEntryScore, arc.InsertionProbability, arc.LanguageProbability, CurrentFrameNumber); TokensCreated.Value++; if (!IsVisited(newToken)) { CollectSuccessorTokens(newToken); } continue; } Token bestToken = GetBestToken(nextState); // this.LogDebug("BestToken: {0}", bestToken); if (bestToken == null) { Token newToken = new Token(predecessor, nextState, logEntryScore, arc.InsertionProbability, arc.LanguageProbability, CurrentFrameNumber); TokensCreated.Value++; SetBestToken(newToken, nextState); //this.LogDebug("Adding Token: {0}", newToken); ActiveList.Add(newToken); } else { if (bestToken.Score <= logEntryScore) { bestToken.Update(predecessor, nextState, logEntryScore, arc.InsertionProbability, arc.LanguageProbability, CurrentFrameNumber); _viterbiPruned.Value++; } else { _viterbiPruned.Value++; } } } }