aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-01-19 03:34:48 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-19 03:34:48 -0800
commitb7b83125544964bf128e07456edfd0170d889dc4 (patch)
treef508770da496b7969baed44975ee58fee9b81206 /java/src/com/android/inputmethod/latin/Suggest.java
parent7a614e9439c0ca752072bd357010517985cb9955 (diff)
parent9c383385d5fb82496d7e7ca57826fc21ec8a6bbd (diff)
downloadlatinime-b7b83125544964bf128e07456edfd0170d889dc4.tar.gz
latinime-b7b83125544964bf128e07456edfd0170d889dc4.tar.xz
latinime-b7b83125544964bf128e07456edfd0170d889dc4.zip
Merge "Merge remote branch 'goog/master' into merge" into froyo-ub-latinimegoogle
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 9ea9c2f3e..24c73e8ea 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -31,7 +31,7 @@ import java.util.Arrays;
*/
public class Suggest implements Dictionary.WordCallback {
- public static final String TAG = "Suggest";
+ public static final String TAG = Suggest.class.getSimpleName();
public static final int APPROX_MAX_WORD_LENGTH = 32;
@@ -64,6 +64,8 @@ public class Suggest implements Dictionary.WordCallback {
static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000;
+ private static boolean DBG = LatinImeLogger.sDBG;
+
private BinaryDictionary mMainDict;
private Dictionary mUserDictionary;
@@ -93,7 +95,7 @@ public class Suggest implements Dictionary.WordCallback {
private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>();
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
- private boolean mHaveCorrection;
+ private boolean mHaveAutoCorrection;
private String mLowerOriginalWord;
// TODO: Remove these member variables by passing more context to addWord() callback method
@@ -103,7 +105,7 @@ public class Suggest implements Dictionary.WordCallback {
private int mCorrectionMode = CORRECTION_BASIC;
public Suggest(Context context, int dictionaryResId) {
- mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN);
+ mMainDict = BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN);
initPool();
}
@@ -127,7 +129,7 @@ public class Suggest implements Dictionary.WordCallback {
}
public boolean hasMainDictionary() {
- return mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD;
+ return mMainDict != null && mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD;
}
public int getApproxMaxWordLength() {
@@ -198,7 +200,7 @@ public class Suggest implements Dictionary.WordCallback {
public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram);
- mHaveCorrection = false;
+ mHaveAutoCorrection = false;
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
mIsAllUpperCase = wordComposer.isAllUpperCase();
collectGarbage(mSuggestions, mPrefMaxSuggestions);
@@ -273,10 +275,13 @@ public class Suggest implements Dictionary.WordCallback {
if (mSuggestions.size() > 0 && isValidWord(typedWord)
&& (mCorrectionMode == CORRECTION_FULL
|| mCorrectionMode == CORRECTION_FULL_BIGRAM)) {
- mHaveCorrection = true;
+ if (DBG) {
+ Log.d(TAG, "Auto corrected by CORRECTION_FULL.");
+ }
+ mHaveAutoCorrection = true;
}
}
- mMainDict.getWords(wordComposer, this, mNextLettersFrequencies);
+ if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies);
if ((mCorrectionMode == CORRECTION_FULL || mCorrectionMode == CORRECTION_FULL_BIGRAM)
&& mSuggestions.size() > 0 && mPriorities.length > 0) {
// TODO: when the normalized score of the first suggestion is nearly equals to
@@ -289,7 +294,10 @@ public class Suggest implements Dictionary.WordCallback {
+ "(" + mAutoCorrectionThreshold + ")");
}
if (normalizedScore >= mAutoCorrectionThreshold) {
- mHaveCorrection = true;
+ if (DBG) {
+ Log.d(TAG, "Auto corrected by S-threthhold.");
+ }
+ mHaveAutoCorrection = true;
}
}
}
@@ -331,7 +339,10 @@ public class Suggest implements Dictionary.WordCallback {
canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i + 1));
}
if (canAdd) {
- mHaveCorrection = true;
+ if (DBG) {
+ Log.d(TAG, "Auto corrected by AUTOTEXT.");
+ }
+ mHaveAutoCorrection = true;
mSuggestions.add(i + 1, autoText);
i++;
}
@@ -374,7 +385,7 @@ public class Suggest implements Dictionary.WordCallback {
}
public boolean hasMinimalCorrection() {
- return mHaveCorrection;
+ return mHaveAutoCorrection;
}
private boolean compareCaseInsensitive(final String mLowerOriginalWord,
@@ -496,7 +507,7 @@ public class Suggest implements Dictionary.WordCallback {
}
public boolean isValidWord(final CharSequence word) {
- if (word == null || word.length() == 0) {
+ if (word == null || word.length() == 0 || mMainDict == null) {
return false;
}
return mMainDict.isValidWord(word)