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.java74
1 files changed, 36 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 28d3b4437..3089625e7 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -239,7 +239,7 @@ public class Suggest implements Dictionary.WordCallback {
}
private static final WordComposer sEmptyWordComposer = new WordComposer();
- public SuggestedWords.Builder getBigramPredictionWordBuilder(CharSequence prevWordForBigram) {
+ public SuggestedWords getBigramPredictions(CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram);
mIsFirstCharCapitalized = false;
mIsAllUpperCase = false;
@@ -269,16 +269,15 @@ public class Suggest implements Dictionary.WordCallback {
StringUtils.removeDupes(mSuggestions);
- return new SuggestedWords.Builder(
- SuggestedWords.Builder.getFromCharSequenceList(mSuggestions),
+ return new SuggestedWords(SuggestedWords.getFromCharSequenceList(mSuggestions),
false /* typedWordValid */,
- false /* hasMinimalSuggestion */,
+ false /* hasAutoCorrectionCandidate */,
false /* allowsToBeAutoCorrected */,
false /* isPunctuationSuggestions */);
}
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
- public SuggestedWords.Builder getSuggestedWordBuilder(
+ public SuggestedWords getSuggestedWords(
final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo, final int correctionMode) {
LatinImeLogger.onStartSuggestion(prevWordForBigram);
@@ -344,21 +343,22 @@ public class Suggest implements Dictionary.WordCallback {
}
} else if (wordComposer.size() > 1) {
+ final WordComposer wordComposerForLookup;
+ if (mTrailingSingleQuotesCount > 0) {
+ wordComposerForLookup = new WordComposer(wordComposer);
+ for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
+ wordComposerForLookup.deleteLast();
+ }
+ } else {
+ wordComposerForLookup = wordComposer;
+ }
// At second character typed, search the unigrams (scores being affected by bigrams)
for (final String key : mUnigramDictionaries.keySet()) {
// Skip UserUnigramDictionary and WhitelistDictionary to lookup
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
continue;
final Dictionary dictionary = mUnigramDictionaries.get(key);
- if (mTrailingSingleQuotesCount > 0) {
- final WordComposer tmpWordComposer = new WordComposer(wordComposer);
- for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
- tmpWordComposer.deleteLast();
- }
- dictionary.getWords(tmpWordComposer, this, proximityInfo);
- } else {
- dictionary.getWords(wordComposer, this, proximityInfo);
- }
+ dictionary.getWords(wordComposerForLookup, this, proximityInfo);
}
}
@@ -392,42 +392,36 @@ public class Suggest implements Dictionary.WordCallback {
mSuggestions.add(0, typedWord);
StringUtils.removeDupes(mSuggestions);
- final SuggestedWords.Builder builder;
- final ArrayList<SuggestedWords.SuggestedWordInfo> scoreInfoList;
+ final ArrayList<SuggestedWords.SuggestedWordInfo> suggestionsList;
if (DBG) {
// TODO: this doesn't take into account the fact that removing dupes from mSuggestions
// may have made mScores[] and mSuggestions out of sync.
final CharSequence autoCorrectionSuggestion = mSuggestions.get(0);
- final int autoCorrectionSuggestionScore = mScores[0];
double normalizedScore = BinaryDictionary.calcNormalizedScore(
- typedWord, autoCorrectionSuggestion.toString(),
- autoCorrectionSuggestionScore);
- scoreInfoList = new ArrayList<SuggestedWords.SuggestedWordInfo>();
- scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(autoCorrectionSuggestion, "+",
+ typedWord, autoCorrectionSuggestion.toString(), mScores[0]);
+ suggestionsList = new ArrayList<SuggestedWords.SuggestedWordInfo>();
+ suggestionsList.add(new SuggestedWords.SuggestedWordInfo(autoCorrectionSuggestion, "+",
false));
final int suggestionsSize = mSuggestions.size();
// Note: i here is the index in mScores[], but the index in mSuggestions is one more
// than i because we added the typed word to mSuggestions without touching mScores.
for (int i = 0; i < mScores.length && i < suggestionsSize - 1; ++i) {
+ final String scoreInfoString;
if (normalizedScore > 0) {
- final String scoreThreshold = String.format("%d (%4.2f)", mScores[i],
- normalizedScore);
- scoreInfoList.add(
- new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
- scoreThreshold, false));
+ scoreInfoString = String.format("%d (%4.2f)", mScores[i], normalizedScore);
normalizedScore = 0.0;
} else {
- final String score = Integer.toString(mScores[i]);
- scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
- score, false));
+ scoreInfoString = Integer.toString(mScores[i]);
}
+ suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
+ scoreInfoString, false));
}
for (int i = mScores.length; i < suggestionsSize; ++i) {
- scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i),
+ suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i),
"--", false));
}
} else {
- scoreInfoList = SuggestedWords.Builder.getFromCharSequenceList(mSuggestions);
+ suggestionsList = SuggestedWords.getFromCharSequenceList(mSuggestions);
}
boolean autoCorrectionAvailable = hasAutoCorrection;
@@ -437,16 +431,20 @@ public class Suggest implements Dictionary.WordCallback {
}
// Don't auto-correct words with multiple capital letter
autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
- builder = new SuggestedWords.Builder(scoreInfoList,
+ final boolean shouldBlockAutoCorrectionBySatefyNet;
+ if (allowsToBeAutoCorrected && suggestionsList.size() > 1 && mAutoCorrectionThreshold > 0
+ && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord,
+ suggestionsList.get(1).mWord)) {
+ shouldBlockAutoCorrectionBySatefyNet = true;
+ } else {
+ shouldBlockAutoCorrectionBySatefyNet = false;
+ }
+ return new SuggestedWords(suggestionsList,
!allowsToBeAutoCorrected /* typedWordValid */,
- autoCorrectionAvailable /* hasMinimalSuggestion */,
+ autoCorrectionAvailable & !shouldBlockAutoCorrectionBySatefyNet
+ /* hasAutoCorrectionCandidate */,
allowsToBeAutoCorrected /* allowsToBeAutoCorrected */,
false /* isPunctuationSuggestions */);
- if (allowsToBeAutoCorrected && builder.size() > 1 && mAutoCorrectionThreshold > 0
- && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord, builder.getWord(1))) {
- builder.setShouldBlockAutoCorrectionBySafetyNet();
- }
- return builder;
}
@Override