diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Suggest.java | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index b02de9a4a..70751c107 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -38,8 +38,6 @@ import java.util.concurrent.ConcurrentHashMap; public class Suggest { public static final String TAG = Suggest.class.getSimpleName(); - public static final int APPROX_MAX_WORD_LENGTH = 32; - // TODO: rename this to CORRECTION_OFF public static final int CORRECTION_NONE = 0; // TODO: rename this to CORRECTION_ON @@ -132,10 +130,6 @@ public class Suggest { return mDictionaries; } - public static int getApproxMaxWordLength() { - return APPROX_MAX_WORD_LENGTH; - } - /** * Sets an optional user dictionary resource to be loaded. The user dictionary is consulted * before the main dictionary, if set. This refers to the system-managed user dictionary. @@ -166,6 +160,8 @@ public class Suggest { public SuggestedWords getSuggestedWords( final WordComposer wordComposer, CharSequence prevWordForBigram, final ProximityInfo proximityInfo, final boolean isCorrectionEnabled, + // TODO: remove isPrediction parameter. It effectively means the same thing + // as wordComposer.size() <= 1 final boolean isPrediction) { LatinImeLogger.onStartSuggestion(prevWordForBigram); final boolean isFirstCharCapitalized = @@ -225,14 +221,19 @@ public class Suggest { mWhiteListDictionary.getWhitelistedWord(consideredWord); final boolean hasAutoCorrection; - if (isCorrectionEnabled) { - final SuggestedWordInfo bestSuggestion = suggestionsSet.isEmpty() - ? null : suggestionsSet.first(); - final CharSequence autoCorrection = - AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer, - bestSuggestion, consideredWord, mAutoCorrectionThreshold, - whitelistedWord); - hasAutoCorrection = (null != autoCorrection); + if (!isCorrectionEnabled || wordComposer.isMostlyCaps() || wordComposer.isResumed()) { + hasAutoCorrection = false; + } else if (null != whitelistedWord) { + hasAutoCorrection = true; + } else if (!AutoCorrection.isWhitelistedOrNotAWord( + mDictionaries, consideredWord, wordComposer.isFirstCharCapitalized())) { + hasAutoCorrection = true; + } else if (suggestionsSet.isEmpty()) { + hasAutoCorrection = false; + } else if (AutoCorrection.suggestionExceedsAutoCorrectionThreshold(suggestionsSet.first(), + consideredWord, mAutoCorrectionThreshold)) { + hasAutoCorrection = !shouldBlockAutoCorrectionBySafetyNet(typedWord, + suggestionsSet.first().mWord); } else { hasAutoCorrection = false; } @@ -261,7 +262,7 @@ public class Suggest { LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(), wordInfo.mSourceDict); } - if (!isPrediction) { + if (!TextUtils.isEmpty(typedWord)) { suggestionsContainer.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, Dictionary.TYPE_USER_TYPED)); @@ -280,7 +281,7 @@ public class Suggest { // The whitelist should be case-insensitive, so it's not possible to be consistent with // a boolean flag. Right now this is handled with a slight hack in // WhitelistDictionary#shouldForciblyAutoCorrectFrom. - final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected( + final boolean allowsToBeAutoCorrected = AutoCorrection.isWhitelistedOrNotAWord( getUnigramDictionaries(), consideredWord, wordComposer.isFirstCharCapitalized()) // If we don't have a main dictionary, we never want to auto-correct. The reason for this // is, the user may have a contact whose name happens to match a valid word in their @@ -289,22 +290,12 @@ public class Suggest { // always auto-correct to "Will" which is unwanted. Hence, no main dict => no auto-correct. && hasMainDictionary(); - boolean autoCorrectionAvailable = hasAutoCorrection; - if (isCorrectionEnabled) { - autoCorrectionAvailable |= !allowsToBeAutoCorrected; - } - // Don't auto-correct words with multiple capital letter - autoCorrectionAvailable &= !wordComposer.isMostlyCaps(); - autoCorrectionAvailable &= !wordComposer.isResumed(); - if (allowsToBeAutoCorrected && suggestionsList.size() > 1 && mAutoCorrectionThreshold > 0 - && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord, - suggestionsList.get(1).mWord)) { - autoCorrectionAvailable = false; - } return new SuggestedWords(suggestionsList, + // 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. !isPrediction && !allowsToBeAutoCorrected /* typedWordValid */, - !isPrediction && autoCorrectionAvailable /* hasAutoCorrectionCandidate */, - !isPrediction && allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, + !isPrediction && hasAutoCorrection, /* hasAutoCorrectionCandidate */ false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, isPrediction); @@ -354,7 +345,7 @@ public class Suggest { private static SuggestedWordInfo getTransformedSuggestedWordInfo( final SuggestedWordInfo wordInfo, final Locale locale, final boolean isAllUpperCase, final boolean isFirstCharCapitalized, final int trailingSingleQuotesCount) { - final StringBuilder sb = new StringBuilder(getApproxMaxWordLength()); + final StringBuilder sb = new StringBuilder(wordInfo.mWord.length()); if (isAllUpperCase) { sb.append(wordInfo.mWord.toString().toUpperCase(locale)); } else if (isFirstCharCapitalized) { |