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.java47
1 files changed, 35 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 439c8562e..5e74d75b0 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -20,6 +20,7 @@ import android.text.TextUtils;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
import com.android.inputmethod.latin.utils.BoundedTreeSet;
import com.android.inputmethod.latin.utils.CollectionUtils;
@@ -51,7 +52,6 @@ public final class Suggest {
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
private static final boolean DBG = LatinImeLogger.sDBG;
-
public final DictionaryFacilitatorForSuggest mDictionaryFacilitator;
private float mAutoCorrectionThreshold;
@@ -124,24 +124,40 @@ public final class Suggest {
} else {
wordComposerForLookup = wordComposer;
}
+ final ArrayList<SuggestedWordInfo> rawSuggestions;
+ if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
+ rawSuggestions = CollectionUtils.newArrayList();
+ } else {
+ rawSuggestions = null;
+ }
mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram,
proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING,
- suggestionsSet);
+ suggestionsSet, rawSuggestions);
+ final String firstSuggestion;
final String whitelistedWord;
if (suggestionsSet.isEmpty()) {
- whitelistedWord = null;
- } else if (SuggestedWordInfo.KIND_WHITELIST != suggestionsSet.first().mKind) {
- whitelistedWord = null;
+ whitelistedWord = firstSuggestion = null;
} else {
- whitelistedWord = suggestionsSet.first().mWord;
+ final SuggestedWordInfo firstSuggestedWordInfo = suggestionsSet.first();
+ firstSuggestion = firstSuggestedWordInfo.mWord;
+ if (SuggestedWordInfo.KIND_WHITELIST != firstSuggestedWordInfo.mKind) {
+ whitelistedWord = null;
+ } else {
+ whitelistedWord = firstSuggestion;
+ }
}
- // The word can be auto-corrected if it has a whitelist entry that is not itself,
- // or if it's a 2+ characters non-word (i.e. it's not in the dictionary).
+ // We allow auto-correction if we have a whitelisted word, or if the word is not a valid
+ // word of more than 1 char, except if the first suggestion is the same as the typed string
+ // because in this case if it's strong enough to auto-correct that will mistakenly designate
+ // the second candidate for auto-correction.
+ // TODO: stop relying on indices to find where is the auto-correction in the suggested
+ // words, and correct this test.
final boolean allowsToBeAutoCorrected = (null != whitelistedWord
&& !whitelistedWord.equals(consideredWord))
|| (consideredWord.length() > 1 && !mDictionaryFacilitator.isValidWord(
- consideredWord, wordComposer.isFirstCharCapitalized()));
+ consideredWord, wordComposer.isFirstCharCapitalized())
+ && !consideredWord.equals(firstSuggestion));
final boolean hasAutoCorrection;
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
@@ -205,7 +221,7 @@ public final class Suggest {
suggestionsList = suggestionsContainer;
}
- callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
+ callback.onGetSuggestedWords(new SuggestedWords(suggestionsList, rawSuggestions,
// TODO: this first argument is lying. If this is a whitelisted word which is an
// actual word, it says typedWordValid = false, which looks wrong. We should either
// rename the attribute or change the value.
@@ -225,8 +241,15 @@ public final class Suggest {
final OnGetSuggestedWordsCallback callback) {
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
SuggestedWords.MAX_SUGGESTIONS);
+ final ArrayList<SuggestedWordInfo> rawSuggestions;
+ if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
+ rawSuggestions = CollectionUtils.newArrayList();
+ } else {
+ rawSuggestions = null;
+ }
mDictionaryFacilitator.getSuggestions(wordComposer, prevWordForBigram, proximityInfo,
- blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet);
+ blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet,
+ rawSuggestions);
for (SuggestedWordInfo wordInfo : suggestionsSet) {
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType);
}
@@ -263,7 +286,7 @@ public final class Suggest {
// In the batch input mode, the most relevant suggested word should act as a "typed word"
// (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
- callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
+ callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, rawSuggestions,
true /* typedWordValid */,
false /* willAutoCorrect */,
false /* isPunctuationSuggestions */,