diff options
author | 2011-04-13 18:51:21 +0900 | |
---|---|---|
committer | 2011-04-13 18:51:21 +0900 | |
commit | d05c6e88347c9129dabe40eebf785c4758d0816c (patch) | |
tree | 1175bc6a611cbdcc56d3d408d87175d755ec3759 /java/src/com/android/inputmethod/latin/ExpandableDictionary.java | |
parent | cc6131053f34f5d69f463ea4513cebb93453fa49 (diff) | |
parent | a6abb1f87c0061d7a409066586ba99d8fdbd86e2 (diff) | |
download | latinime-d05c6e88347c9129dabe40eebf785c4758d0816c.tar.gz latinime-d05c6e88347c9129dabe40eebf785c4758d0816c.tar.xz latinime-d05c6e88347c9129dabe40eebf785c4758d0816c.zip |
Merge remote-tracking branch 'goog/master' into merge
Conflicts:
java/res/xml/method.xml
Change-Id: I033d512e23c84d6c803805c9b05eec88969f97df
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ExpandableDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ExpandableDictionary.java | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index d87fbce51..be2c6b21b 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -32,12 +32,14 @@ public class ExpandableDictionary extends Dictionary { */ protected static final int MAX_WORD_LENGTH = 32; + // Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8. + protected static final int BIGRAM_MAX_FREQUENCY = 255; + private Context mContext; private char[] mWordBuilder = new char[MAX_WORD_LENGTH]; private int mDicTypeId; private int mMaxDepth; private int mInputLength; - private StringBuilder sb = new StringBuilder(MAX_WORD_LENGTH); private static final char QUOTE = '\''; @@ -98,6 +100,7 @@ public class ExpandableDictionary extends Dictionary { public int addFrequency(int add) { mFrequency += add; + if (mFrequency > BIGRAM_MAX_FREQUENCY) mFrequency = BIGRAM_MAX_FREQUENCY; return mFrequency; } } @@ -462,6 +465,9 @@ public class ExpandableDictionary extends Dictionary { } } + // Local to reverseLookUp, but do not allocate each time. + private final char[] mLookedUpString = new char[MAX_WORD_LENGTH]; + /** * reverseLookUp retrieves the full word given a list of terminal nodes and adds those words * through callback. @@ -474,18 +480,15 @@ public class ExpandableDictionary extends Dictionary { for (NextWord nextWord : terminalNodes) { node = nextWord.mWord; freq = nextWord.getFrequency(); - // TODO Not the best way to limit suggestion threshold - if (freq >= UserBigramDictionary.SUGGEST_THRESHOLD) { - sb.setLength(0); - do { - sb.insert(0, node.mCode); - node = node.mParent; - } while(node != null); - - // TODO better way to feed char array? - callback.addWord(sb.toString().toCharArray(), 0, sb.length(), freq, mDicTypeId, - DataType.BIGRAM); - } + int index = MAX_WORD_LENGTH; + do { + --index; + mLookedUpString[index] = node.mCode; + node = node.mParent; + } while (node != null); + + callback.addWord(mLookedUpString, index, MAX_WORD_LENGTH - index, freq, mDicTypeId, + DataType.BIGRAM); } } |