aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java14
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableDictionary.java25
-rw-r--r--java/src/com/android/inputmethod/latin/UserHistoryDictionary.java4
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java22
4 files changed, 30 insertions, 35 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 9909638d4..c43683f2d 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -40,14 +40,13 @@ public class BinaryDictionary extends Dictionary {
public static final int MAX_WORDS = 18;
private static final String TAG = "BinaryDictionary";
- private static final int MAX_PROXIMITY_CHARS_SIZE = ProximityInfo.MAX_PROXIMITY_CHARS_SIZE;
private static final int MAX_BIGRAMS = 60;
private static final int TYPED_LETTER_MULTIPLIER = 2;
private int mDicTypeId;
private long mNativeDict;
- private final int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_PROXIMITY_CHARS_SIZE];
+ private final int[] mInputCodes = new int[MAX_WORD_LENGTH];
private final char[] mOutputChars = new char[MAX_WORD_LENGTH * MAX_WORDS];
private final char[] mOutputChars_bigrams = new char[MAX_WORD_LENGTH * MAX_BIGRAMS];
private final int[] mScores = new int[MAX_WORDS];
@@ -111,8 +110,7 @@ public class BinaryDictionary extends Dictionary {
}
private native long openNative(String sourceDir, long dictOffset, long dictSize,
- int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength,
- int maxWords, int maxAlternatives);
+ int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords);
private native void closeNative(long dict);
private native boolean isValidWordNative(long dict, char[] word, int wordLength);
private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates,
@@ -120,7 +118,7 @@ public class BinaryDictionary extends Dictionary {
int[] scores);
private native int getBigramsNative(long dict, char[] prevWord, int prevWordLength,
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
- int maxWordLength, int maxBigrams, int maxAlternatives);
+ int maxWordLength, int maxBigrams);
private static native double calcNormalizedScoreNative(
char[] before, int beforeLength, char[] after, int afterLength, int score);
private static native int editDistanceNative(
@@ -128,8 +126,7 @@ public class BinaryDictionary extends Dictionary {
private final void loadDictionary(String path, long startOffset, long length) {
mNativeDict = openNative(path, startOffset, length,
- TYPED_LETTER_MULTIPLIER, FULL_WORD_SCORE_MULTIPLIER,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_PROXIMITY_CHARS_SIZE);
+ TYPED_LETTER_MULTIPLIER, FULL_WORD_SCORE_MULTIPLIER, MAX_WORD_LENGTH, MAX_WORDS);
}
@Override
@@ -148,8 +145,7 @@ public class BinaryDictionary extends Dictionary {
}
int count = getBigramsNative(mNativeDict, chars, chars.length, mInputCodes, codesSize,
- mOutputChars_bigrams, mBigramScores, MAX_WORD_LENGTH, MAX_BIGRAMS,
- MAX_PROXIMITY_CHARS_SIZE);
+ mOutputChars_bigrams, mBigramScores, MAX_WORD_LENGTH, MAX_BIGRAMS);
if (count > MAX_BIGRAMS) {
count = MAX_BIGRAMS;
}
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index f8de029bd..098913bef 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -28,17 +28,12 @@ import java.util.LinkedList;
* be searched for suggestions and valid words.
*/
public class ExpandableDictionary extends Dictionary {
- /**
- * There is difference between what java and native code can handle.
- * It uses 32 because Java stack overflows when greater value is used.
- */
- 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 char[] mWordBuilder = new char[BinaryDictionary.MAX_WORD_LENGTH];
private int mDicTypeId;
private int mMaxDepth;
private int mInputLength;
@@ -113,7 +108,7 @@ public class ExpandableDictionary extends Dictionary {
public ExpandableDictionary(Context context, int dicTypeId) {
mContext = context;
clearDictionary();
- mCodes = new int[MAX_WORD_LENGTH][];
+ mCodes = new int[BinaryDictionary.MAX_WORD_LENGTH][];
mDicTypeId = dicTypeId;
}
@@ -151,10 +146,13 @@ public class ExpandableDictionary extends Dictionary {
}
public int getMaxWordLength() {
- return MAX_WORD_LENGTH;
+ return BinaryDictionary.MAX_WORD_LENGTH;
}
public void addWord(String word, int frequency) {
+ if (word.length() >= BinaryDictionary.MAX_WORD_LENGTH) {
+ return;
+ }
addWordRec(mRoots, word, 0, frequency, null);
}
@@ -201,6 +199,9 @@ public class ExpandableDictionary extends Dictionary {
// Currently updating contacts, don't return any results.
if (mUpdatingDictionary) return;
}
+ if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
+ return;
+ }
getWordsInner(codes, callback, proximityInfo);
}
@@ -488,7 +489,7 @@ public class ExpandableDictionary extends Dictionary {
}
// Local to reverseLookUp, but do not allocate each time.
- private final char[] mLookedUpString = new char[MAX_WORD_LENGTH];
+ private final char[] mLookedUpString = new char[BinaryDictionary.MAX_WORD_LENGTH];
/**
* reverseLookUp retrieves the full word given a list of terminal nodes and adds those words
@@ -502,15 +503,15 @@ public class ExpandableDictionary extends Dictionary {
for (NextWord nextWord : terminalNodes) {
node = nextWord.mWord;
freq = nextWord.getFrequency();
- int index = MAX_WORD_LENGTH;
+ int index = BinaryDictionary.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,
- Dictionary.BIGRAM);
+ callback.addWord(mLookedUpString, index, BinaryDictionary.MAX_WORD_LENGTH - index,
+ freq, mDicTypeId, Dictionary.BIGRAM);
}
}
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
index db2cdf967..62525c205 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
@@ -247,8 +247,8 @@ public class UserHistoryDictionary extends ExpandableDictionary {
// to recursive lookup
if (null == word1) {
super.addWord(word2, frequency);
- } else if (word1.length() < MAX_WORD_LENGTH
- && word2.length() < MAX_WORD_LENGTH) {
+ } else if (word1.length() < BinaryDictionary.MAX_WORD_LENGTH
+ && word2.length() < BinaryDictionary.MAX_WORD_LENGTH) {
super.setBigram(word1, word2, frequency);
}
cursor.moveToNext();
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 29a7e4816..555a49ef4 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -104,7 +104,11 @@ public class WordComposer {
return size() > 0;
}
+ // TODO: make sure that the index should not exceed MAX_WORD_LENGTH
public int getCodeAt(int index) {
+ if (index >= BinaryDictionary.MAX_WORD_LENGTH) {
+ return -1;
+ }
return mPrimaryKeyCodes[index];
}
@@ -123,7 +127,6 @@ public class WordComposer {
// TODO: remove input keyDetector
public void add(int primaryCode, int x, int y, KeyDetector keyDetector) {
- final int[] codes;
final int keyX;
final int keyY;
if (null == keyDetector
@@ -131,17 +134,13 @@ public class WordComposer {
|| y == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE
|| x == KeyboardActionListener.NOT_A_TOUCH_COORDINATE
|| y == KeyboardActionListener.NOT_A_TOUCH_COORDINATE) {
- codes = new int[] { primaryCode };
keyX = x;
keyY = y;
} else {
- final Key key = keyDetector.detectHitKey(x, y);
- // TODO: Pass an integer instead of an integer array
- codes = new int[] { key != null ? key.mCode : NOT_A_CODE };
keyX = keyDetector.getTouchX(x);
keyY = keyDetector.getTouchY(y);
}
- add(primaryCode, codes, keyX, keyY);
+ add(primaryCode, keyX, keyY);
}
/**
@@ -149,12 +148,13 @@ public class WordComposer {
* the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
* @param codes the array of unicode values
*/
- private void add(int primaryCode, int[] codes, int keyX, int keyY) {
+ private void add(int primaryCode, int keyX, int keyY) {
final int newIndex = size();
mTypedWord.appendCodePoint(primaryCode);
refreshSize();
- mPrimaryKeyCodes[newIndex] = codes[0];
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
+ mPrimaryKeyCodes[newIndex] = primaryCode >= Keyboard.CODE_SPACE
+ ? Character.toLowerCase(primaryCode) : primaryCode;
mXCoordinates[newIndex] = keyX;
mYCoordinates[newIndex] = keyY;
}
@@ -177,13 +177,11 @@ public class WordComposer {
if (key.mCode == codePoint) {
final int x = key.mX + key.mWidth / 2;
final int y = key.mY + key.mHeight / 2;
- // TODO: Pass an integer instead of an integer array
- add(codePoint, new int[] { key.mCode }, x, y);
+ add(codePoint, x, y);
return;
}
}
- add(codePoint, new int[] { codePoint },
- WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ add(codePoint, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
}
/**