diff options
author | 2015-02-25 15:57:59 -0800 | |
---|---|---|
committer | 2015-02-25 17:59:58 -0800 | |
commit | 5551302d275e3f54da9d86bcea633556ad12db8e (patch) | |
tree | 546240c21be53d829fe1521b6db126671e8e3594 /java/src/com/android/inputmethod/latin/SuggestedWords.java | |
parent | ed378c78a15757c7386d84c6cd7470d56ed00c76 (diff) | |
download | latinime-5551302d275e3f54da9d86bcea633556ad12db8e.tar.gz latinime-5551302d275e3f54da9d86bcea633556ad12db8e.tar.xz latinime-5551302d275e3f54da9d86bcea633556ad12db8e.zip |
Don't assume that correctable words are invalid
Currently, the Delight3DictionaryFacilitator sets a boolean flag when the top
suggestion score exceeds the auto-correction threshold. This flag is used to
trigger auto-correction of the typed word. Also, the existing logic assumes
that if allowsToBeAutoCorrected then the word is invalid, which is no longer
true after we stopped using whitelists.
Bug 19518376.
Change-Id: Ifa7f6a09c07d25ac68c6cf3aec91f358bd88689f
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SuggestedWords.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/SuggestedWords.java | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 913b63a61..3816c0870 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -17,6 +17,7 @@ package com.android.inputmethod.latin; import android.text.TextUtils; +import android.util.Log; import android.view.inputmethod.CompletionInfo; import com.android.inputmethod.annotations.UsedForTesting; @@ -375,31 +376,45 @@ public class SuggestedWords { return mWord + " (" + mDebugString + ")"; } - // This will always remove the higher index if a duplicate is found. - public static void removeDups(@Nullable final String typedWord, - @Nonnull ArrayList<SuggestedWordInfo> candidates) { + /** + * This will always remove the higher index if a duplicate is found. + * + * @return position of typed word in the candidate list + */ + public static int removeDups( + @Nullable final String typedWord, + @Nonnull final ArrayList<SuggestedWordInfo> candidates) { if (candidates.isEmpty()) { - return; + return -1; } + int firstOccurrenceOfWord = -1; if (!TextUtils.isEmpty(typedWord)) { - removeSuggestedWordInfoFromList(typedWord, candidates, -1 /* startIndexExclusive */); + firstOccurrenceOfWord = removeSuggestedWordInfoFromList( + typedWord, candidates, -1 /* startIndexExclusive */); } for (int i = 0; i < candidates.size(); ++i) { - removeSuggestedWordInfoFromList(candidates.get(i).mWord, candidates, - i /* startIndexExclusive */); + removeSuggestedWordInfoFromList( + candidates.get(i).mWord, candidates, i /* startIndexExclusive */); } + return firstOccurrenceOfWord; } - private static void removeSuggestedWordInfoFromList( - @Nonnull final String word, @Nonnull final ArrayList<SuggestedWordInfo> candidates, + private static int removeSuggestedWordInfoFromList( + @Nonnull final String word, + @Nonnull final ArrayList<SuggestedWordInfo> candidates, final int startIndexExclusive) { + int firstOccurrenceOfWord = -1; for (int i = startIndexExclusive + 1; i < candidates.size(); ++i) { final SuggestedWordInfo previous = candidates.get(i); if (word.equals(previous.mWord)) { + if (firstOccurrenceOfWord == -1) { + firstOccurrenceOfWord = i; + } candidates.remove(i); --i; } } + return firstOccurrenceOfWord; } } |