From 46b26d9ff6f3e071b17003f024669fe037ec00b6 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 17 Jun 2011 12:45:17 +0900 Subject: [PATCH 1/2] Fix a bug where bigram search would never return Bug: 4690487 Change-Id: Ie8f3f651508cc48bbb043a0b308f7e0d1524371c --- native/src/bigram_dictionary.cpp | 2 +- native/src/dictionary.cpp | 8 ++++++++ native/src/dictionary.h | 3 +++ native/src/unigram_dictionary.cpp | 9 +++++---- native/src/unigram_dictionary.h | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/native/src/bigram_dictionary.cpp b/native/src/bigram_dictionary.cpp index 4bc436537..11e6dc250 100644 --- a/native/src/bigram_dictionary.cpp +++ b/native/src/bigram_dictionary.cpp @@ -111,7 +111,7 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i mMaxBigrams = maxBigrams; if (HAS_BIGRAM && IS_LATEST_DICT_VERSION) { - int pos = mParentDictionary->isValidWord(prevWord, prevWordLength); + int pos = mParentDictionary->getBigramPosition(prevWord, prevWordLength); if (DEBUG_DICT) { LOGI("Pos -> %d", pos); } diff --git a/native/src/dictionary.cpp b/native/src/dictionary.cpp index a49769bdb..9e32ee80f 100644 --- a/native/src/dictionary.cpp +++ b/native/src/dictionary.cpp @@ -57,4 +57,12 @@ bool Dictionary::isValidWord(unsigned short *word, int length) { return mUnigramDictionary->isValidWord(word, length); } +int Dictionary::getBigramPosition(unsigned short *word, int length) { + if (IS_LATEST_DICT_VERSION) { + return mUnigramDictionary->getBigramPosition(DICTIONARY_HEADER_SIZE, word, 0, length); + } else { + return mUnigramDictionary->getBigramPosition(0, word, 0, length); + } +} + } // namespace latinime diff --git a/native/src/dictionary.h b/native/src/dictionary.h index 3b360d93a..1b41f69dd 100644 --- a/native/src/dictionary.h +++ b/native/src/dictionary.h @@ -62,6 +62,9 @@ public: const int pos, unsigned short *c, int *childrenPosition, bool *terminal, int *freq); + // TODO: delete this + int getBigramPosition(unsigned short *word, int length); + private: bool hasBigram(); diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp index 7bcdbb498..c294cf3b5 100644 --- a/native/src/unigram_dictionary.cpp +++ b/native/src/unigram_dictionary.cpp @@ -932,15 +932,16 @@ inline bool UnigramDictionary::processCurrentNodeForExactMatch(const int firstCh // TODO: use uint32_t instead of unsigned short bool UnigramDictionary::isValidWord(unsigned short *word, int length) { if (IS_LATEST_DICT_VERSION) { - return (getFrequency(DICTIONARY_HEADER_SIZE, word, 0, length) != NOT_VALID_WORD); + return (getBigramPosition(DICTIONARY_HEADER_SIZE, word, 0, length) != NOT_VALID_WORD); } else { - return (getFrequency(0, word, 0, length) != NOT_VALID_WORD); + return (getBigramPosition(0, word, 0, length) != NOT_VALID_WORD); } } // Require strict exact match. -int UnigramDictionary::getFrequency(int pos, unsigned short *word, int offset, int length) const { +int UnigramDictionary::getBigramPosition(int pos, unsigned short *word, int offset, + int length) const { // returns address of bigram data of that word // return -99 if not found @@ -957,7 +958,7 @@ int UnigramDictionary::getFrequency(int pos, unsigned short *word, int offset, i } } else { if (childPos != 0) { - int t = getFrequency(childPos, word, offset + 1, length); + int t = getBigramPosition(childPos, word, offset + 1, length); if (t > 0) { return t; } diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h index b8e4914fa..c47db1ad2 100644 --- a/native/src/unigram_dictionary.h +++ b/native/src/unigram_dictionary.h @@ -40,6 +40,7 @@ public: int fullWordMultiplier, int maxWordLength, int maxWords, int maxProximityChars, const bool isLatestDictVersion); bool isValidWord(unsigned short *word, int length); + int getBigramPosition(int pos, unsigned short *word, int offset, int length) const; int getSuggestions(const ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates, const int *codes, const int codesSize, const int flags, unsigned short *outWords, int *frequencies); @@ -59,7 +60,6 @@ private: void getSuggestionCandidates(const int skipPos, const int excessivePos, const int transposedPos, int *nextLetters, const int nextLettersSize, const int maxDepth); - int getFrequency(int pos, unsigned short *word, int offset, int length) const; void getVersionNumber(); bool checkIfDictVersionIsLatest(); int getAddress(int *pos); From 9bb59adf27d28a2d4e146c127683c06a3dca600b Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 21 Jun 2011 02:31:33 +0900 Subject: [PATCH 2/2] Fix NPE Bug: 4727778 Change-Id: I08f1204d5f77251c197dda7d2b332441f9f7123d --- java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 8657768ee..1218a5abd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -186,7 +186,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void onSizeChanged() { final int width = mInputMethodService.getWindow().getWindow().getDecorView().getWidth(); - if (width == 0) + if (width == 0 || mCurrentId == null) return; mKeyboardWidth = width; // Set keyboard with new width.