Conditionally store the raw suggestions.
Bug: 12913520 Change-Id: Ie15f97d90c142c51089280252b35b5ad1d226e19main
parent
58eed6360d
commit
a49f61f8a7
|
@ -430,12 +430,19 @@ public class DictionaryFacilitatorForSuggest {
|
|||
public void getSuggestions(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final int sessionId, final Set<SuggestedWordInfo> suggestionSet) {
|
||||
final int sessionId, final Set<SuggestedWordInfo> suggestionSet,
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions) {
|
||||
for (final String key : mDictionaries.keySet()) {
|
||||
final Dictionary dictionary = mDictionaries.get(key);
|
||||
if (null == dictionary) continue;
|
||||
suggestionSet.addAll(dictionary.getSuggestionsWithSessionId(composer, prevWord,
|
||||
proximityInfo, blockOffensiveWords, additionalFeaturesOptions, sessionId));
|
||||
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
||||
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
|
||||
blockOffensiveWords, additionalFeaturesOptions, sessionId);
|
||||
if (null == dictionarySuggestions) continue;
|
||||
suggestionSet.addAll(dictionarySuggestions);
|
||||
if (null != rawSuggestions) {
|
||||
rawSuggestions.addAll(dictionarySuggestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -997,7 +997,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
||||
applicationSpecifiedCompletions);
|
||||
final SuggestedWords suggestedWords = new SuggestedWords(
|
||||
applicationSuggestedWords,
|
||||
applicationSuggestedWords, null /* rawSuggestions */,
|
||||
false /* typedWordValid */,
|
||||
false /* willAutoCorrect */,
|
||||
false /* isPunctuationSuggestions */,
|
||||
|
@ -1417,7 +1417,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
? SuggestedWords.EMPTY : previousSuggestedWords;
|
||||
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
||||
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
|
||||
return new SuggestedWords(typedWordAndPreviousSuggestions,
|
||||
return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
|
||||
false /* typedWordValid */,
|
||||
false /* hasAutoCorrectionCandidate */,
|
||||
false /* isPunctuationSuggestions */,
|
||||
|
|
|
@ -51,6 +51,7 @@ public final class Suggest {
|
|||
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
|
||||
|
||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||
private static final boolean INCLUDE_RAW_SUGGESTIONS = false;
|
||||
|
||||
public final DictionaryFacilitatorForSuggest mDictionaryFacilitator;
|
||||
|
||||
|
@ -124,9 +125,15 @@ public final class Suggest {
|
|||
} else {
|
||||
wordComposerForLookup = wordComposer;
|
||||
}
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions;
|
||||
if (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()) {
|
||||
|
@ -217,7 +224,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.
|
||||
|
@ -237,8 +244,15 @@ public final class Suggest {
|
|||
final OnGetSuggestedWordsCallback callback) {
|
||||
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
|
||||
SuggestedWords.MAX_SUGGESTIONS);
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions;
|
||||
if (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);
|
||||
}
|
||||
|
@ -275,7 +289,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 */,
|
||||
|
|
|
@ -37,7 +37,7 @@ public final class SuggestedWords {
|
|||
private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST =
|
||||
CollectionUtils.newArrayList(0);
|
||||
public static final SuggestedWords EMPTY = new SuggestedWords(
|
||||
EMPTY_WORD_INFO_LIST, false, false, false, false, false);
|
||||
EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false, false, false, false, false);
|
||||
|
||||
public final String mTypedWord;
|
||||
public final boolean mTypedWordValid;
|
||||
|
@ -50,25 +50,29 @@ public final class SuggestedWords {
|
|||
public final boolean mIsPrediction;
|
||||
public final int mSequenceNumber; // Sequence number for auto-commit.
|
||||
private final ArrayList<SuggestedWordInfo> mSuggestedWordInfoList;
|
||||
public final ArrayList<SuggestedWordInfo> mRawSuggestions;
|
||||
|
||||
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions,
|
||||
final boolean typedWordValid,
|
||||
final boolean willAutoCorrect,
|
||||
final boolean isPunctuationSuggestions,
|
||||
final boolean isObsoleteSuggestions,
|
||||
final boolean isPrediction) {
|
||||
this(suggestedWordInfoList, typedWordValid, willAutoCorrect, isPunctuationSuggestions,
|
||||
isObsoleteSuggestions, isPrediction, NOT_A_SEQUENCE_NUMBER);
|
||||
this(suggestedWordInfoList, rawSuggestions, typedWordValid, willAutoCorrect,
|
||||
isPunctuationSuggestions, isObsoleteSuggestions, isPrediction,
|
||||
NOT_A_SEQUENCE_NUMBER);
|
||||
}
|
||||
|
||||
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions,
|
||||
final boolean typedWordValid,
|
||||
final boolean willAutoCorrect,
|
||||
final boolean isPunctuationSuggestions,
|
||||
final boolean isObsoleteSuggestions,
|
||||
final boolean isPrediction,
|
||||
final int sequenceNumber) {
|
||||
this(suggestedWordInfoList,
|
||||
this(suggestedWordInfoList, rawSuggestions,
|
||||
suggestedWordInfoList.isEmpty() ? null
|
||||
: suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
|
||||
typedWordValid, willAutoCorrect, isPunctuationSuggestions,
|
||||
|
@ -76,6 +80,7 @@ public final class SuggestedWords {
|
|||
}
|
||||
|
||||
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
||||
final ArrayList<SuggestedWordInfo> rawSuggestions,
|
||||
final String typedWord,
|
||||
final boolean typedWordValid,
|
||||
final boolean willAutoCorrect,
|
||||
|
@ -84,6 +89,7 @@ public final class SuggestedWords {
|
|||
final boolean isPrediction,
|
||||
final int sequenceNumber) {
|
||||
mSuggestedWordInfoList = suggestedWordInfoList;
|
||||
mRawSuggestions = rawSuggestions;
|
||||
mTypedWordValid = typedWordValid;
|
||||
mWillAutoCorrect = willAutoCorrect;
|
||||
mIsPunctuationSuggestions = isPunctuationSuggestions;
|
||||
|
@ -306,9 +312,9 @@ public final class SuggestedWords {
|
|||
}
|
||||
// We should never autocorrect, so we say the typed word is valid. Also, in this case,
|
||||
// no auto-correction should take place hence willAutoCorrect = false.
|
||||
return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */,
|
||||
false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
|
||||
mIsPrediction, NOT_A_SEQUENCE_NUMBER);
|
||||
return new SuggestedWords(newSuggestions, null /* rawSuggestions */, typedWord,
|
||||
true /* typedWordValid */, false /* willAutoCorrect */, mIsPunctuationSuggestions,
|
||||
mIsObsoleteSuggestions, mIsPrediction, NOT_A_SEQUENCE_NUMBER);
|
||||
}
|
||||
|
||||
// Creates a new SuggestedWordInfo from the currently suggested words that removes all but the
|
||||
|
@ -326,7 +332,7 @@ public final class SuggestedWords {
|
|||
info.mSourceDict, SuggestedWordInfo.NOT_AN_INDEX,
|
||||
SuggestedWordInfo.NOT_A_CONFIDENCE));
|
||||
}
|
||||
return new SuggestedWords(newSuggestions, mTypedWordValid,
|
||||
return new SuggestedWords(newSuggestions, null /* rawSuggestions */, mTypedWordValid,
|
||||
mWillAutoCorrect, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
|
||||
mIsPrediction);
|
||||
}
|
||||
|
|
|
@ -1332,7 +1332,8 @@ public final class InputLogic {
|
|||
} else {
|
||||
// We found suggestion spans in the word. We'll create the SuggestedWords out of
|
||||
// them, and make willAutoCorrect false.
|
||||
final SuggestedWords suggestedWords = new SuggestedWords(suggestions, typedWord,
|
||||
final SuggestedWords suggestedWords = new SuggestedWords(suggestions,
|
||||
null /* rawSuggestions */, typedWord,
|
||||
true /* typedWordValid */, false /* willAutoCorrect */,
|
||||
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
|
||||
false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
|
||||
|
|
|
@ -75,7 +75,7 @@ public final class SpacingAndPunctuations {
|
|||
final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
|
||||
if (puncs != null) {
|
||||
for (final String puncSpec : puncs) {
|
||||
// TODO: Stop using KeySpceParser.getLabel().
|
||||
// TODO: Stop using KeySpecParser.getLabel().
|
||||
// TODO: Punctuation suggestions should honor RTL languages.
|
||||
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
|
||||
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED,
|
||||
|
@ -84,7 +84,7 @@ public final class SpacingAndPunctuations {
|
|||
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
|
||||
}
|
||||
}
|
||||
return new SuggestedWords(puncList,
|
||||
return new SuggestedWords(puncList, null /* rawSuggestions */,
|
||||
false /* typedWordValid */,
|
||||
false /* hasAutoCorrectionCandidate */,
|
||||
true /* isPunctuationSuggestions */,
|
||||
|
|
|
@ -46,7 +46,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
|
|||
}
|
||||
|
||||
final SuggestedWords words = new SuggestedWords(
|
||||
list,
|
||||
list, null /* rawSuggestions */,
|
||||
false /* typedWordValid */,
|
||||
false /* willAutoCorrect */,
|
||||
false /* isPunctuationSuggestions */,
|
||||
|
|
Loading…
Reference in New Issue