aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-11-05 11:57:39 +0900
committerJean Chalard <jchalard@google.com>2014-11-20 18:31:01 +0900
commita7efe062087049609af801e95257e555d9394aef (patch)
treeb6e95f8f5dd7ab7124cde385d68e666e21e517c5 /java/src/com/android/inputmethod/latin/Suggest.java
parenta94733cbca5bc3544fa73fa1649bbb1dadf31356 (diff)
downloadlatinime-a7efe062087049609af801e95257e555d9394aef.tar.gz
latinime-a7efe062087049609af801e95257e555d9394aef.tar.xz
latinime-a7efe062087049609af801e95257e555d9394aef.zip
Annotate the typed word with its source dictionary
...when applicable of course. This will allow for informing the language switching authorities that the typed word was a specific language, instead of leaving them in the dark. Bug: 18063142 Bug: 18130489 Bug: 18132240 Bug: 18136721 Bug: 18200415 Change-Id: Ice3e7026a68c3018f54d730ec84f6762bf55899b
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 4df1d6505..2d0ec42a6 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -32,6 +32,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
+import javax.annotation.Nullable;
+
/**
* This class loads a dictionary and provides a list of suggestions for a given sequence of
* characters. This includes corrections and completions.
@@ -143,14 +145,16 @@ public final class Suggest {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer, ngramContext, proximityInfo.getNativeProximityInfo(),
settingsValuesForSuggestion, SESSION_ID_TYPING);
+ final Locale mostProbableLocale = mDictionaryFacilitator.getMostProbableLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer =
getTransformedSuggestedWordInfoList(wordComposer, suggestionResults,
trailingSingleQuotesCount,
// For transforming suggestions that don't come for any dictionary, we
// use the currently most probable locale as it's our best bet.
- mDictionaryFacilitator.getMostProbableLocale());
- final boolean didRemoveTypedWord =
- SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer);
+ mostProbableLocale);
+ @Nullable final Dictionary sourceDictionaryOfRemovedWord =
+ SuggestedWordInfo.removeDupsAndReturnSourceOfTypedWord(wordComposer.getTypedWord(),
+ mostProbableLocale /* preferredLocale */, suggestionsContainer);
final String whitelistedWord = getWhitelistedWordOrNull(suggestionsContainer);
final boolean resultsArePredictions = !wordComposer.isComposingWord();
@@ -158,7 +162,7 @@ public final class Suggest {
// We allow auto-correction if we have a whitelisted word, or if the word had more than
// one char and was not suggested.
final boolean allowsToBeAutoCorrected = (null != whitelistedWord)
- || (consideredWord.length() > 1 && !didRemoveTypedWord);
+ || (consideredWord.length() > 1 && (null == sourceDictionaryOfRemovedWord));
final boolean hasAutoCorrection;
// If correction is not enabled, we never auto-correct. This is for example for when
@@ -209,7 +213,8 @@ public final class Suggest {
final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo(typedWordString,
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED,
- Dictionary.DICTIONARY_USER_TYPED,
+ null == sourceDictionaryOfRemovedWord ? Dictionary.DICTIONARY_USER_TYPED
+ : sourceDictionaryOfRemovedWord,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
if (!TextUtils.isEmpty(typedWordString)) {
@@ -275,7 +280,8 @@ public final class Suggest {
final SuggestedWordInfo rejected = suggestionsContainer.remove(0);
suggestionsContainer.add(1, rejected);
}
- SuggestedWordInfo.removeDups(null /* typedWord */, suggestionsContainer);
+ SuggestedWordInfo.removeDupsAndReturnSourceOfTypedWord(null /* typedWord */,
+ null /* preferredLocale */, suggestionsContainer);
// For some reason some suggestions with MIN_VALUE are making their way here.
// TODO: Find a more robust way to detect distracters.