Loading native/jni/src/defines.h +3 −2 Original line number Diff line number Diff line Loading @@ -234,11 +234,12 @@ static inline void prof_out(void) { #define SUB_QUEUE_MAX_WORDS 1 #define SUB_QUEUE_MAX_COUNT 10 #define SUB_QUEUE_MIN_WORD_LENGTH 4 #define MULTIPLE_WORDS_SUGGESTION_MAX_WORDS 10 // TODO: Extend this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_WORDS 5 // TODO: Remove this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH 12 // TODO: Remove this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_TOTAL_TRAVERSE_COUNT 110 #define MULTIPLE_WORDS_SUGGESTION_MAX_TOTAL_TRAVERSE_COUNT 45 #define MULTIPLE_WORDS_DEMOTION_RATE 80 #define MIN_INPUT_LENGTH_FOR_THREE_OR_MORE_WORDS_CORRECTION 6 Loading native/jni/src/unigram_dictionary.cpp +42 −3 Original line number Diff line number Diff line Loading @@ -431,6 +431,48 @@ int UnigramDictionary::getSubStringSuggestion( const int inputWordStartPos, const int inputWordLength, const int outputWordStartPos, const bool isSpaceProximity, int *freqArray, int*wordLengthArray, unsigned short* outputWord, int *outputWordLength) { if (inputWordLength > MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH) { return FLAG_MULTIPLE_SUGGEST_ABORT; } ///////////////////////////////////////////// // safety net for multiple word suggestion // // TODO: Remove this safety net // ///////////////////////////////////////////// int smallWordCount = 0; int singleLetterWordCount = 0; if (inputWordLength == 1) { ++singleLetterWordCount; } if (inputWordLength <= 2) { // small word == single letter or 2-letter word ++smallWordCount; } for (int i = 0; i < currentWordIndex; ++i) { const int length = wordLengthArray[i]; if (length == 1) { ++singleLetterWordCount; // Safety net to avoid suggesting sequential single letter words if (i < (currentWordIndex - 1)) { if (wordLengthArray[i + 1] == 1) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } else if (inputWordLength == 1) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } if (length <= 2) { ++smallWordCount; } // Safety net to avoid suggesting multiple words with many (4 or more, for now) small words if (singleLetterWordCount >= 3 || smallWordCount >= 4) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } ////////////////////////////////////////////// // TODO: Remove the safety net above // ////////////////////////////////////////////// unsigned short* tempOutputWord = 0; int nextWordLength = 0; // TODO: Optimize init suggestion Loading Loading @@ -556,9 +598,6 @@ void UnigramDictionary::getMultiWordsSuggestionRec(ProximityInfo *proximityInfo, // Current word int inputWordStartPos = startInputPos; int inputWordLength = i - startInputPos; if (inputWordLength > MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH) { break; } const int suggestionFlag = getSubStringSuggestion(proximityInfo, xcoordinates, ycoordinates, codes, useFullEditDistance, correction, queuePool, inputLength, hasAutoCorrectionCandidate, startWordIndex, inputWordStartPos, inputWordLength, Loading Loading
native/jni/src/defines.h +3 −2 Original line number Diff line number Diff line Loading @@ -234,11 +234,12 @@ static inline void prof_out(void) { #define SUB_QUEUE_MAX_WORDS 1 #define SUB_QUEUE_MAX_COUNT 10 #define SUB_QUEUE_MIN_WORD_LENGTH 4 #define MULTIPLE_WORDS_SUGGESTION_MAX_WORDS 10 // TODO: Extend this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_WORDS 5 // TODO: Remove this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH 12 // TODO: Remove this limitation #define MULTIPLE_WORDS_SUGGESTION_MAX_TOTAL_TRAVERSE_COUNT 110 #define MULTIPLE_WORDS_SUGGESTION_MAX_TOTAL_TRAVERSE_COUNT 45 #define MULTIPLE_WORDS_DEMOTION_RATE 80 #define MIN_INPUT_LENGTH_FOR_THREE_OR_MORE_WORDS_CORRECTION 6 Loading
native/jni/src/unigram_dictionary.cpp +42 −3 Original line number Diff line number Diff line Loading @@ -431,6 +431,48 @@ int UnigramDictionary::getSubStringSuggestion( const int inputWordStartPos, const int inputWordLength, const int outputWordStartPos, const bool isSpaceProximity, int *freqArray, int*wordLengthArray, unsigned short* outputWord, int *outputWordLength) { if (inputWordLength > MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH) { return FLAG_MULTIPLE_SUGGEST_ABORT; } ///////////////////////////////////////////// // safety net for multiple word suggestion // // TODO: Remove this safety net // ///////////////////////////////////////////// int smallWordCount = 0; int singleLetterWordCount = 0; if (inputWordLength == 1) { ++singleLetterWordCount; } if (inputWordLength <= 2) { // small word == single letter or 2-letter word ++smallWordCount; } for (int i = 0; i < currentWordIndex; ++i) { const int length = wordLengthArray[i]; if (length == 1) { ++singleLetterWordCount; // Safety net to avoid suggesting sequential single letter words if (i < (currentWordIndex - 1)) { if (wordLengthArray[i + 1] == 1) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } else if (inputWordLength == 1) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } if (length <= 2) { ++smallWordCount; } // Safety net to avoid suggesting multiple words with many (4 or more, for now) small words if (singleLetterWordCount >= 3 || smallWordCount >= 4) { return FLAG_MULTIPLE_SUGGEST_ABORT; } } ////////////////////////////////////////////// // TODO: Remove the safety net above // ////////////////////////////////////////////// unsigned short* tempOutputWord = 0; int nextWordLength = 0; // TODO: Optimize init suggestion Loading Loading @@ -556,9 +598,6 @@ void UnigramDictionary::getMultiWordsSuggestionRec(ProximityInfo *proximityInfo, // Current word int inputWordStartPos = startInputPos; int inputWordLength = i - startInputPos; if (inputWordLength > MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH) { break; } const int suggestionFlag = getSubStringSuggestion(proximityInfo, xcoordinates, ycoordinates, codes, useFullEditDistance, correction, queuePool, inputLength, hasAutoCorrectionCandidate, startWordIndex, inputWordStartPos, inputWordLength, Loading