/** * /// Returns the list of successors to this state * * /// @return a list of SearchState objects */ public override ISearchStateArc[] GetSuccessors() { ISearchStateArc[] arcs = GetCachedArcs(); if (arcs == null) { arcs = LexTreeLinguist.EmptyArc; WordNode wordNode = (WordNode)GetNode(); if (wordNode.GetWord() != Parent.SentenceEndWord) { int index = 0; List <Node> list = new List <Node>(); Unit[] rc = _lastNode.GetRC(); Unit left = wordNode.LastUnit; foreach (Unit unit in rc) { Node[] epList = Parent.HMMTree.GetEntryPoint(left, unit); foreach (Node n in epList) { list.Add(n); } } //this.LogDebug("NodeList: {0}",list.Count); // add a link to every possible entry point as well // as link to the </s> node arcs = new ISearchStateArc[list.Count + 1]; foreach (Node node in list) { arcs[index++] = CreateUnitStateArc((HMMNode)node, this); } // now add the link to the end of sentence arc: arcs[index++] = CreateWordStateArc(Parent.HMMTree.SentenceEndWordNode, _lastNode, this); } PutCachedArcs(arcs); } return(arcs); }
/** * /// Creates a word search state for the given word node * * /// @param wordNode the wordNode * * * /// @return the search state for the wordNode */ protected ISearchStateArc CreateWordStateArc(WordNode wordNode, HMMNode lastUnit, LexTreeState previous) { //TODO: UNCOMMENT DURING RELEASE //this.LogInfo("CWSA " + wordNode + " fup " /*+ fixupProb*/); float languageProbability = Parent.LogOne; Word nextWord = wordNode.GetWord(); float smearTerm = previous.SmearTerm; if (nextWord.IsFiller && !Equals(nextWord, Parent.SentenceEndWord)) { return(new LexTreeWordState(wordNode, lastUnit, _wordSequence, smearTerm, Parent.LogOne, languageProbability, Parent)); } WordSequence nextWordSequence = _wordSequence.AddWord(nextWord, Parent.MaxDepth); float probability = Parent.LanguageModel.GetProbability(nextWordSequence) * Parent.LanguageWeight; smearTerm = Parent.GetSmearTermFromLanguageModel(nextWordSequence); //this.LogInfo("LP " + nextWordSequence + " " /*+ logProbability*/); // subtract off the previously applied smear probability languageProbability = probability - previous.SmearProb; //Boolean collapse = (probability.depth < parent.maxDepth - 1) || !parent.fullWordHistories; if (Equals(nextWord, Parent.SentenceEndWord)) { return(new LexTreeEndWordState(wordNode, lastUnit, nextWordSequence.Trim(Parent.MaxDepth - 1), smearTerm, Parent.LogOne, languageProbability, Parent)); } return(new LexTreeWordState(wordNode, lastUnit, nextWordSequence.Trim(Parent.MaxDepth - 1), smearTerm, Parent.LogOne, languageProbability, Parent)); }