aboutsummaryrefslogtreecommitdiffstats
path: root/dictionary/src/dictionary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dictionary/src/dictionary.cpp')
-rw-r--r--dictionary/src/dictionary.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/dictionary/src/dictionary.cpp b/dictionary/src/dictionary.cpp
index cc711f419..306aff527 100644
--- a/dictionary/src/dictionary.cpp
+++ b/dictionary/src/dictionary.cpp
@@ -51,6 +51,7 @@ Dictionary::~Dictionary()
int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
int maxWordLength, int maxWords, int maxAlternatives, int skipPos)
{
+ int suggWords;
mFrequencies = frequencies;
mOutputChars = outWords;
mInputCodes = codes;
@@ -58,14 +59,16 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
mMaxAlternatives = maxAlternatives;
mMaxWordLength = maxWordLength;
mMaxWords = maxWords;
- mWords = 0;
mSkipPos = skipPos;
mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2;
getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0);
- if (DEBUG_DICT) LOGI("Returning %d words", mWords);
- return mWords;
+ // Get the word count
+ suggWords = 0;
+ while (suggWords < mMaxWords && mFrequencies[suggWords] > 0) suggWords++;
+ if (DEBUG_DICT) LOGI("Returning %d words", suggWords);
+ return suggWords;
}
unsigned short
@@ -138,8 +141,6 @@ Dictionary::addWord(unsigned short *word, int length, int frequency)
*dest++ = *word++;
}
*dest = 0; // NULL terminate
- // Update the word count
- if (insertAt + 1 > mWords) mWords = insertAt + 1;
if (DEBUG_DICT) LOGI("Added word at %d\n", insertAt);
return true;
}