am a9e1930a: Merge "Conditionally store the raw suggestions."

* commit 'a9e1930a6a9ce2e53cf9b47e8b0033b763416183':
  Conditionally store the raw suggestions.
main
Jean Chalard 2014-02-05 23:35:20 -08:00 committed by Android Git Automerger
commit cf398ac4f5
7 changed files with 49 additions and 21 deletions

View File

@ -430,12 +430,19 @@ public class DictionaryFacilitatorForSuggest {
public void getSuggestions(final WordComposer composer, public void getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo, final String prevWord, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions, 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()) { for (final String key : mDictionaries.keySet()) {
final Dictionary dictionary = mDictionaries.get(key); final Dictionary dictionary = mDictionaries.get(key);
if (null == dictionary) continue; if (null == dictionary) continue;
suggestionSet.addAll(dictionary.getSuggestionsWithSessionId(composer, prevWord, final ArrayList<SuggestedWordInfo> dictionarySuggestions =
proximityInfo, blockOffensiveWords, additionalFeaturesOptions, sessionId)); dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, sessionId);
if (null == dictionarySuggestions) continue;
suggestionSet.addAll(dictionarySuggestions);
if (null != rawSuggestions) {
rawSuggestions.addAll(dictionarySuggestions);
}
} }
} }

View File

@ -998,7 +998,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
SuggestedWords.getFromApplicationSpecifiedCompletions( SuggestedWords.getFromApplicationSpecifiedCompletions(
applicationSpecifiedCompletions); applicationSpecifiedCompletions);
final SuggestedWords suggestedWords = new SuggestedWords( final SuggestedWords suggestedWords = new SuggestedWords(
applicationSuggestedWords, applicationSuggestedWords, null /* rawSuggestions */,
false /* typedWordValid */, false /* typedWordValid */,
false /* willAutoCorrect */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,
@ -1418,7 +1418,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
? SuggestedWords.EMPTY : previousSuggestedWords; ? SuggestedWords.EMPTY : previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
false /* typedWordValid */, false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */, false /* hasAutoCorrectionCandidate */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,

View File

@ -51,6 +51,7 @@ public final class Suggest {
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000; private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
private static final boolean DBG = LatinImeLogger.sDBG; private static final boolean DBG = LatinImeLogger.sDBG;
private static final boolean INCLUDE_RAW_SUGGESTIONS = false;
public final DictionaryFacilitatorForSuggest mDictionaryFacilitator; public final DictionaryFacilitatorForSuggest mDictionaryFacilitator;
@ -124,9 +125,15 @@ public final class Suggest {
} else { } else {
wordComposerForLookup = wordComposer; wordComposerForLookup = wordComposer;
} }
final ArrayList<SuggestedWordInfo> rawSuggestions;
if (INCLUDE_RAW_SUGGESTIONS) {
rawSuggestions = CollectionUtils.newArrayList();
} else {
rawSuggestions = null;
}
mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram, mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram,
proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING, proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING,
suggestionsSet); suggestionsSet, rawSuggestions);
final String firstSuggestion; final String firstSuggestion;
final String whitelistedWord; final String whitelistedWord;
if (suggestionsSet.isEmpty()) { if (suggestionsSet.isEmpty()) {
@ -215,7 +222,7 @@ public final class Suggest {
suggestionsList = suggestionsContainer; 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 // 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 // actual word, it says typedWordValid = false, which looks wrong. We should either
// rename the attribute or change the value. // rename the attribute or change the value.
@ -235,8 +242,15 @@ public final class Suggest {
final OnGetSuggestedWordsCallback callback) { final OnGetSuggestedWordsCallback callback) {
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator, final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
SuggestedWords.MAX_SUGGESTIONS); SuggestedWords.MAX_SUGGESTIONS);
final ArrayList<SuggestedWordInfo> rawSuggestions;
if (INCLUDE_RAW_SUGGESTIONS) {
rawSuggestions = CollectionUtils.newArrayList();
} else {
rawSuggestions = null;
}
mDictionaryFacilitator.getSuggestions(wordComposer, prevWordForBigram, proximityInfo, mDictionaryFacilitator.getSuggestions(wordComposer, prevWordForBigram, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet); blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet,
rawSuggestions);
for (SuggestedWordInfo wordInfo : suggestionsSet) { for (SuggestedWordInfo wordInfo : suggestionsSet) {
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType); LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType);
} }
@ -273,7 +287,7 @@ public final class Suggest {
// In the batch input mode, the most relevant suggested word should act as a "typed word" // 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). // (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, rawSuggestions,
true /* typedWordValid */, true /* typedWordValid */,
false /* willAutoCorrect */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,

View File

@ -37,7 +37,7 @@ public final class SuggestedWords {
private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST = private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST =
CollectionUtils.newArrayList(0); CollectionUtils.newArrayList(0);
public static final SuggestedWords EMPTY = new SuggestedWords( 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 String mTypedWord;
public final boolean mTypedWordValid; public final boolean mTypedWordValid;
@ -50,25 +50,29 @@ public final class SuggestedWords {
public final boolean mIsPrediction; public final boolean mIsPrediction;
public final int mSequenceNumber; // Sequence number for auto-commit. public final int mSequenceNumber; // Sequence number for auto-commit.
private final ArrayList<SuggestedWordInfo> mSuggestedWordInfoList; private final ArrayList<SuggestedWordInfo> mSuggestedWordInfoList;
public final ArrayList<SuggestedWordInfo> mRawSuggestions;
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList, public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
final ArrayList<SuggestedWordInfo> rawSuggestions,
final boolean typedWordValid, final boolean typedWordValid,
final boolean willAutoCorrect, final boolean willAutoCorrect,
final boolean isPunctuationSuggestions, final boolean isPunctuationSuggestions,
final boolean isObsoleteSuggestions, final boolean isObsoleteSuggestions,
final boolean isPrediction) { final boolean isPrediction) {
this(suggestedWordInfoList, typedWordValid, willAutoCorrect, isPunctuationSuggestions, this(suggestedWordInfoList, rawSuggestions, typedWordValid, willAutoCorrect,
isObsoleteSuggestions, isPrediction, NOT_A_SEQUENCE_NUMBER); isPunctuationSuggestions, isObsoleteSuggestions, isPrediction,
NOT_A_SEQUENCE_NUMBER);
} }
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList, public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
final ArrayList<SuggestedWordInfo> rawSuggestions,
final boolean typedWordValid, final boolean typedWordValid,
final boolean willAutoCorrect, final boolean willAutoCorrect,
final boolean isPunctuationSuggestions, final boolean isPunctuationSuggestions,
final boolean isObsoleteSuggestions, final boolean isObsoleteSuggestions,
final boolean isPrediction, final boolean isPrediction,
final int sequenceNumber) { final int sequenceNumber) {
this(suggestedWordInfoList, this(suggestedWordInfoList, rawSuggestions,
suggestedWordInfoList.isEmpty() ? null suggestedWordInfoList.isEmpty() ? null
: suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord, : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
typedWordValid, willAutoCorrect, isPunctuationSuggestions, typedWordValid, willAutoCorrect, isPunctuationSuggestions,
@ -76,6 +80,7 @@ public final class SuggestedWords {
} }
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList, public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
final ArrayList<SuggestedWordInfo> rawSuggestions,
final String typedWord, final String typedWord,
final boolean typedWordValid, final boolean typedWordValid,
final boolean willAutoCorrect, final boolean willAutoCorrect,
@ -84,6 +89,7 @@ public final class SuggestedWords {
final boolean isPrediction, final boolean isPrediction,
final int sequenceNumber) { final int sequenceNumber) {
mSuggestedWordInfoList = suggestedWordInfoList; mSuggestedWordInfoList = suggestedWordInfoList;
mRawSuggestions = rawSuggestions;
mTypedWordValid = typedWordValid; mTypedWordValid = typedWordValid;
mWillAutoCorrect = willAutoCorrect; mWillAutoCorrect = willAutoCorrect;
mIsPunctuationSuggestions = isPunctuationSuggestions; 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, // 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. // no auto-correction should take place hence willAutoCorrect = false.
return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */, return new SuggestedWords(newSuggestions, null /* rawSuggestions */, typedWord,
false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions, true /* typedWordValid */, false /* willAutoCorrect */, mIsPunctuationSuggestions,
mIsPrediction, NOT_A_SEQUENCE_NUMBER); mIsObsoleteSuggestions, mIsPrediction, NOT_A_SEQUENCE_NUMBER);
} }
// Creates a new SuggestedWordInfo from the currently suggested words that removes all but the // 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, info.mSourceDict, SuggestedWordInfo.NOT_AN_INDEX,
SuggestedWordInfo.NOT_A_CONFIDENCE)); SuggestedWordInfo.NOT_A_CONFIDENCE));
} }
return new SuggestedWords(newSuggestions, mTypedWordValid, return new SuggestedWords(newSuggestions, null /* rawSuggestions */, mTypedWordValid,
mWillAutoCorrect, mIsPunctuationSuggestions, mIsObsoleteSuggestions, mWillAutoCorrect, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
mIsPrediction); mIsPrediction);
} }

View File

@ -1332,7 +1332,8 @@ public final class InputLogic {
} else { } else {
// We found suggestion spans in the word. We'll create the SuggestedWords out of // We found suggestion spans in the word. We'll create the SuggestedWords out of
// them, and make willAutoCorrect false. // 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 */, true /* typedWordValid */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER); false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER);

View File

@ -75,7 +75,7 @@ public final class SpacingAndPunctuations {
final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList(); final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
if (puncs != null) { if (puncs != null) {
for (final String puncSpec : puncs) { for (final String puncSpec : puncs) {
// TODO: Stop using KeySpceParser.getLabel(). // TODO: Stop using KeySpecParser.getLabel().
// TODO: Punctuation suggestions should honor RTL languages. // TODO: Punctuation suggestions should honor RTL languages.
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec), puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED, SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED,
@ -84,7 +84,7 @@ public final class SpacingAndPunctuations {
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */)); SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
} }
} }
return new SuggestedWords(puncList, return new SuggestedWords(puncList, null /* rawSuggestions */,
false /* typedWordValid */, false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */, false /* hasAutoCorrectionCandidate */,
true /* isPunctuationSuggestions */, true /* isPunctuationSuggestions */,

View File

@ -46,7 +46,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
} }
final SuggestedWords words = new SuggestedWords( final SuggestedWords words = new SuggestedWords(
list, list, null /* rawSuggestions */,
false /* typedWordValid */, false /* typedWordValid */,
false /* willAutoCorrect */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,