Skip to content

Commit

Permalink
fix crashes, merge the duplicate sentences
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeandmore committed Jan 2, 2011
1 parent 271d503 commit fa7ec5f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/ime-core/imi_context.cpp
Expand Up @@ -502,14 +502,14 @@ bool CIMIContext::_backTracePaths(const std::vector<TLatticeState>& tail_states,
} else {
cwstr = end_fr.m_wstr.c_str();
}

CCandidate candi(start, end, bs->m_pLexiconState, cwstr,
bs->m_backTraceWordId);

end_fr.m_bwType |= CLatticeFrame::BESTWORD;
end_fr.m_bestWords[rank] = candi;
if (rank == 0) {
// select rank 0 sentence by default
end_fr.m_selWord = candi;
end_fr.m_selWord = candi; // select the first by default.
}
}

Expand Down Expand Up @@ -696,6 +696,8 @@ void CIMIContext::getCandidates (unsigned frIdx, CCandidates& result)
cp.m_candi.m_end = frIdx;
if (fr.m_bwType != CLatticeFrame::NO_BESTWORD) {
for (int i = 0; i < m_nBest; i++) {
if (fr.m_bestWords.find(i) == fr.m_bestWords.end())
continue;
if (fr.m_bestWords[i].m_start != m_candiStarts)
continue;
cp.m_candi = fr.m_bestWords[i];
Expand Down
47 changes: 30 additions & 17 deletions src/ime-core/imi_view_classic.cpp
Expand Up @@ -94,14 +94,23 @@ CIMIClassicView::updateWindows(unsigned mask)
wstring sentence;
unsigned word_num = m_pIC->getBestSentence (sentence,
i, m_candiFrIdx);
/*
if (word_num <= 1 || (!m_candiList.empty()
&& m_tailSentence == m_candiList[0].m_cwstr))
m_sentences[i].clear ();
*/
if (word_num > 1) {
m_sentences.push_back(sentence);
if (word_num <= 1) break; // when sentence is not worthy of

printf("%d ", i);
print_wide(sentence.c_str());
printf("\n");

for (int j = 0; j < m_sentences.size(); j++) {
if (sentence == m_sentences[j].second) goto stop;
}
for (int j = 0; j < m_candiList.size(); j++) {
if (sentence == m_candiList[j].m_cwstr) goto stop;
}
m_sentences.push_back(std::make_pair(i, sentence));
continue;

stop:
break; // sentence is not worthy of anymore
}
}

Expand Down Expand Up @@ -156,28 +165,29 @@ CIMIClassicView::onKeyEvent(const CKeyEvent& key)
changeMasks |= KEYEVENT_USED;
_moveRight (changeMasks);
}
} else if ( ((modifiers == 0 && keycode == IM_VK_PAGE_UP) ||
(m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey (key))) &&
!m_pIC->isEmpty() ) {
} else if ( ((modifiers == 0 && keycode == IM_VK_PAGE_UP)
|| (m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey (key)))
&& !m_pIC->isEmpty() ) {
changeMasks |= KEYEVENT_USED;
int sz = m_candiList.size() + m_sentences.size();
if (sz > 0 && m_candiPageFirst > 0) {
m_candiPageFirst -= m_candiWindowSize;
if (m_candiPageFirst < 0) m_candiPageFirst = 0;
changeMasks |= CANDIDATE_MASK;
}
} else if ( ((modifiers == 0 && keycode == IM_VK_PAGE_DOWN) ||
(m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey (key))) &&
!m_pIC->isEmpty() ) {
} else if (((modifiers == 0 && keycode == IM_VK_PAGE_DOWN)
|| (m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey (key)))
&& !m_pIC->isEmpty() ) {
changeMasks |= KEYEVENT_USED;
int sz = m_candiList.size() + m_sentences.size();
if (sz > 0 && m_candiPageFirst + m_candiWindowSize < sz) {
m_candiPageFirst += m_candiWindowSize;
changeMasks |= CANDIDATE_MASK;
}
}
else if (m_pHotkeyProfile && m_pHotkeyProfile->isCandiDeleteKey(key, m_candiWindowSize) &&
!m_pIC->isEmpty ()) {
else if (m_pHotkeyProfile
&& m_pHotkeyProfile->isCandiDeleteKey(key, m_candiWindowSize)
&& !m_pIC->isEmpty ()) {
changeMasks |= KEYEVENT_USED;
unsigned sel = (keyvalue == '0'? 9: keyvalue-'1');
_deleteCandidate (sel, changeMasks);
Expand Down Expand Up @@ -422,7 +432,7 @@ CIMIClassicView::getCandidateList(ICandidateList& cl, int start, int size)

//Loop used for future n-best sentence candidates usage
for (; start < tscount && size > 0; ++start, --size) {
css.push_back (m_sentences[start]);
css.push_back (m_sentences[start].second);
cts.push_back (ICandidateList::BEST_TAIL);
}

Expand Down Expand Up @@ -639,7 +649,10 @@ CIMIClassicView::_makeSelection (int candiIdx, unsigned& mask)
if (candiIdx < 0) {
// commit the best sentence
mask |= PREEDIT_MASK | CANDIDATE_MASK;
m_pIC->selectSentence (candiIdx + m_sentences.size());
printf("selecting sentence %d\n", candiIdx + m_sentences.size());
// get the rank of that sentence
int rank = m_sentences[candiIdx + m_sentences.size()].first;
m_pIC->selectSentence (rank);
_doCommit (candiIdx);
clearIC ();
} else if (candiIdx < m_candiList.size ()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ime-core/imi_view_classic.h
Expand Up @@ -68,8 +68,8 @@ class CIMIClassicView : public CIMIView

bool m_numeric_mode;

CCandidates m_candiList;
std::vector<wstring> m_sentences;
CCandidates m_candiList;
std::vector<std::pair<int, wstring> > m_sentences;

inline void _insert (unsigned keyvalue, unsigned& mask);
inline void _erase (bool backward, unsigned& mask);
Expand Down

0 comments on commit fa7ec5f

Please sign in to comment.