void CIMIContext::clear () { _clearFrom (1); _clearBestPaths (); m_tailIdx = 1; m_candiStarts = m_candiEnds = 0; }
bool CIMIContext::searchFrom (unsigned idx) { bool affectCandidates = (idx <= m_candiEnds); _clearBestPaths (); for (; idx<=m_tailIdx; ++idx) { CLatticeFrame &fr = m_lattice[idx]; if (fr.m_type == CLatticeFrame::UNUSED) continue; fr.m_latticeStates.clear (); /* user selected word might be cut in next step */ if (fr.m_bwType & CLatticeFrame::USER_SELECTED) _transferBetween (fr.m_bestWord.m_start, idx, fr.m_bestWord.m_pLexiconState, fr.m_bestWord.m_wordId); CLexiconStates::iterator it = fr.m_lexiconStates.begin (); CLexiconStates::iterator ite = fr.m_lexiconStates.end (); for (; it != ite; ++it) { unsigned word_num = 0; TLexiconState &lxst = *it; const CPinyinTrie::TWordIdInfo *words = lxst.getWords (word_num); if (!word_num) continue; if (lxst.m_start == m_candiStarts && idx > m_candiEnds) affectCandidates = true; /* only selected the word with higher unigram probablities */ int maxsz = it->m_bFuzzy? MAX_LEXICON_TRIES>1: MAX_LEXICON_TRIES; int sz = word_num<maxsz? word_num: maxsz; int i = 0, count = 0; double ic = it->m_bFuzzy? 0.5: 1.0; for (i = 0; count < sz && i < sz && (words[i].m_bSeen || count < 2); ++i) { if (m_csLevel >= words[i].m_csLevel) { _transferBetween (lxst.m_start, idx, &lxst, words[i].m_id, ic); ++ count; } } /* try extra words in history cache */ if (m_pHistory) { for (; i < word_num; ++i) { if (m_csLevel >= words[i].m_csLevel && m_pHistory->seenBefore (words[i].m_id)) _transferBetween (lxst.m_start, idx, &lxst, words[i].m_id, ic); } } } } _backTraceBestPaths (); return affectCandidates; }