aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java53
1 files changed, 28 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index a6df187e6..a30ec1587 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -25,12 +25,10 @@ import android.view.View;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
/**
* This class loads a dictionary and provides a list of suggestions for a given sequence of
* characters. This includes corrections and completions.
- * @hide pending API Council Approval
*/
public class Suggest implements Dictionary.WordCallback {
@@ -83,7 +81,7 @@ public class Suggest implements Dictionary.WordCallback {
private boolean mAutoTextEnabled;
- private double mAutoCompleteThreshold;
+ private double mAutoCorrectionThreshold;
private int[] mPriorities = new int[mPrefMaxSuggestions];
private int[] mBigramPriorities = new int[PREF_MAX_BIGRAMS];
@@ -97,7 +95,6 @@ public class Suggest implements Dictionary.WordCallback {
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
private boolean mHaveCorrection;
- private CharSequence mOriginalWord;
private String mLowerOriginalWord;
// TODO: Remove these member variables by passing more context to addWord() callback method
@@ -166,8 +163,8 @@ public class Suggest implements Dictionary.WordCallback {
mUserBigramDictionary = userBigramDictionary;
}
- public void setAutoCompleteThreshold(double threshold) {
- mAutoCompleteThreshold = threshold;
+ public void setAutoCorrectionThreshold(double threshold) {
+ mAutoCorrectionThreshold = threshold;
}
/**
@@ -191,15 +188,21 @@ public class Suggest implements Dictionary.WordCallback {
}
/**
- * Returns a list of words that match the list of character codes passed in.
- * This list will be overwritten the next time this function is called.
+ * Returns a object which represents suggested words that match the list of character codes
+ * passed in. This object contents will be overwritten the next time this function is called.
* @param view a view for retrieving the context for AutoText
* @param wordComposer contains what is currently being typed
* @param prevWordForBigram previous word (used only for bigram)
- * @return list of suggestions.
+ * @return suggested words object.
*/
- public List<CharSequence> getSuggestions(View view, WordComposer wordComposer,
- boolean includeTypedWordIfValid, CharSequence prevWordForBigram) {
+ public SuggestedWords getSuggestions(View view, WordComposer wordComposer,
+ CharSequence prevWordForBigram) {
+ return getSuggestedWordBuilder(view, wordComposer, prevWordForBigram).build();
+ }
+
+ // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
+ public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
+ CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram);
mHaveCorrection = false;
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
@@ -209,13 +212,13 @@ public class Suggest implements Dictionary.WordCallback {
Arrays.fill(mNextLettersFrequencies, 0);
// Save a lowercase version of the original word
- mOriginalWord = wordComposer.getTypedWord();
- if (mOriginalWord != null) {
- final String mOriginalWordString = mOriginalWord.toString();
- mOriginalWord = mOriginalWordString;
- mLowerOriginalWord = mOriginalWordString.toLowerCase();
+ CharSequence typedWord = wordComposer.getTypedWord();
+ if (typedWord != null) {
+ final String typedWordString = typedWord.toString();
+ typedWord = typedWordString;
+ mLowerOriginalWord = typedWordString.toLowerCase();
// Treating USER_TYPED as UNIGRAM suggestion for logging now.
- LatinImeLogger.onAddSuggestedWord(mOriginalWordString, Suggest.DIC_USER_TYPED,
+ LatinImeLogger.onAddSuggestedWord(typedWordString, Suggest.DIC_USER_TYPED,
Dictionary.DataType.UNIGRAM);
} else {
mLowerOriginalWord = "";
@@ -273,7 +276,7 @@ public class Suggest implements Dictionary.WordCallback {
mContactsDictionary.getWords(wordComposer, this, mNextLettersFrequencies);
}
- if (mSuggestions.size() > 0 && isValidWord(mOriginalWord)
+ if (mSuggestions.size() > 0 && isValidWord(typedWord)
&& (mCorrectionMode == CORRECTION_FULL
|| mCorrectionMode == CORRECTION_FULL_BIGRAM)) {
mHaveCorrection = true;
@@ -285,19 +288,19 @@ public class Suggest implements Dictionary.WordCallback {
// TODO: when the normalized score of the first suggestion is nearly equals to
// the normalized score of the second suggestion, behave less aggressive.
final double normalizedScore = Utils.calcNormalizedScore(
- mOriginalWord, mSuggestions.get(0), mPriorities[0]);
+ typedWord, mSuggestions.get(0), mPriorities[0]);
if (LatinImeLogger.sDBG) {
- Log.d(TAG, "Normalized " + mOriginalWord + "," + mSuggestions.get(0) + ","
+ Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + ","
+ mPriorities[0] + normalizedScore
- + "(" + mAutoCompleteThreshold + ")");
+ + "(" + mAutoCorrectionThreshold + ")");
}
- if (normalizedScore >= mAutoCompleteThreshold) {
+ if (normalizedScore >= mAutoCorrectionThreshold) {
mHaveCorrection = true;
}
}
}
- if (mOriginalWord != null) {
- mSuggestions.add(0, mOriginalWord.toString());
+ if (typedWord != null) {
+ mSuggestions.add(0, typedWord.toString());
}
if (mAutoTextEnabled) {
int i = 0;
@@ -342,7 +345,7 @@ public class Suggest implements Dictionary.WordCallback {
}
}
removeDupes();
- return mSuggestions;
+ return new SuggestedWords.Builder().setWords(mSuggestions);
}
public int[] getNextLettersFrequencies() {