diff options
Diffstat (limited to 'native/src')
-rw-r--r-- | native/src/dictionary.cpp | 31 | ||||
-rw-r--r-- | native/src/dictionary.h | 6 |
2 files changed, 31 insertions, 6 deletions
diff --git a/native/src/dictionary.cpp b/native/src/dictionary.cpp index a1a632faa..1a39f585b4 100644 --- a/native/src/dictionary.cpp +++ b/native/src/dictionary.cpp @@ -387,13 +387,17 @@ Dictionary::getBigramFreq(int *pos) int -Dictionary::getBigrams(unsigned short *prevWord, int prevWordLength, unsigned short *bigramChars, - int *bigramFreq, int maxWordLength, int maxBigrams) +Dictionary::getBigrams(unsigned short *prevWord, int prevWordLength, int *codes, int codesSize, + unsigned short *bigramChars, int *bigramFreq, int maxWordLength, int maxBigrams, + int maxAlternatives) { mBigramFreq = bigramFreq; mBigramChars = bigramChars; + mInputCodes = codes; + mInputLength = codesSize; mMaxWordLength = maxWordLength; mMaxBigrams = maxBigrams; + mMaxAlternatives = maxAlternatives; if (mBigram == 1 && checkIfDictVersionIsLatest()) { int pos = isValidWordRec(DICTIONARY_HEADER_SIZE, prevWord, 0, prevWordLength); @@ -406,7 +410,7 @@ Dictionary::getBigrams(unsigned short *prevWord, int prevWordLength, unsigned sh int bigramExist = (mDict[pos] & FLAG_BIGRAM_READ); if (bigramExist > 0) { int nextBigramExist = 1; - while (nextBigramExist > 0) { + while (nextBigramExist > 0 && bigramCount < maxBigrams) { int bigramAddress = getBigramAddress(&pos, true); int frequency = (FLAG_BIGRAM_FREQ & mDict[pos]); // search for all bigrams and store them @@ -521,8 +525,27 @@ Dictionary::searchForTerminalNode(int addressLookingFor, int frequency) break; } } + if (checkFirstCharacter(word)) { + addWordBigram(word, depth, frequency); + } +} - addWordBigram(word, depth, frequency); +bool +Dictionary::checkFirstCharacter(unsigned short *word) +{ + // Checks whether this word starts with same character or neighboring characters of + // what user typed. + + int *inputCodes = mInputCodes; + int maxAlt = mMaxAlternatives; + while (maxAlt > 0) { + if ((unsigned int) *inputCodes == (unsigned int) *word) { + return true; + } + inputCodes++; + maxAlt--; + } + return false; } bool diff --git a/native/src/dictionary.h b/native/src/dictionary.h index 2c574290f..d13496e01 100644 --- a/native/src/dictionary.h +++ b/native/src/dictionary.h @@ -39,8 +39,9 @@ public: int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, int maxWordLength, int maxWords, int maxAlternatives, int skipPos, int *nextLetters, int nextLettersSize); - int getBigrams(unsigned short *word, int length, unsigned short *outWords, int *frequencies, - int maxWordLength, int maxBigrams); + int getBigrams(unsigned short *word, int length, int *codes, int codesSize, + unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams, + int maxAlternatives); bool isValidWord(unsigned short *word, int length); void setAsset(void *asset) { mAsset = asset; } void *getAsset() { return mAsset; } @@ -64,6 +65,7 @@ private: int wideStrLen(unsigned short *str); bool sameAsTyped(unsigned short *word, int length); + bool checkFirstCharacter(unsigned short *word); bool addWord(unsigned short *word, int length, int frequency); bool addWordBigram(unsigned short *word, int length, int frequency); unsigned short toLowerCase(unsigned short c); |