[AC2] Reference a dict rather than a string in suggestion infos
Bug: 9059617 Change-Id: Ic17bc0fd5d812268fd37d7fd35b4e9ebfb95fa5emain
parent
ef1e363016
commit
e8ef095670
|
@ -179,7 +179,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
// TODO: check that all users of the `kind' parameter are ready to accept
|
// TODO: check that all users of the `kind' parameter are ready to accept
|
||||||
// flags too and pass mOutputTypes[j] instead of kind
|
// flags too and pass mOutputTypes[j] instead of kind
|
||||||
suggestions.add(new SuggestedWordInfo(new String(mOutputCodePoints, start, len),
|
suggestions.add(new SuggestedWordInfo(new String(mOutputCodePoints, start, len),
|
||||||
score, kind, mDictType,
|
score, kind, this /* sourceDict */,
|
||||||
mSpaceIndices[0] /* indexOfTouchPointOfSecondWord */));
|
mSpaceIndices[0] /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,26 @@ import java.util.ArrayList;
|
||||||
public abstract class Dictionary {
|
public abstract class Dictionary {
|
||||||
public static final int NOT_A_PROBABILITY = -1;
|
public static final int NOT_A_PROBABILITY = -1;
|
||||||
|
|
||||||
|
// The following types do not actually come from real dictionary instances, so we create
|
||||||
|
// corresponding instances.
|
||||||
public static final String TYPE_USER_TYPED = "user_typed";
|
public static final String TYPE_USER_TYPED = "user_typed";
|
||||||
|
public static final Dictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);
|
||||||
|
|
||||||
public static final String TYPE_APPLICATION_DEFINED = "application_defined";
|
public static final String TYPE_APPLICATION_DEFINED = "application_defined";
|
||||||
|
public static final Dictionary DICTIONARY_APPLICATION_DEFINED =
|
||||||
|
new PhonyDictionary(TYPE_APPLICATION_DEFINED);
|
||||||
|
|
||||||
public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such
|
public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such
|
||||||
|
public static final Dictionary DICTIONARY_HARDCODED =
|
||||||
|
new PhonyDictionary(TYPE_HARDCODED);
|
||||||
|
|
||||||
|
// Spawned by resuming suggestions. Comes from a span that was in the TextView.
|
||||||
|
public static final String TYPE_RESUMED = "resumed";
|
||||||
|
public static final Dictionary DICTIONARY_RESUMED =
|
||||||
|
new PhonyDictionary(TYPE_RESUMED);
|
||||||
|
|
||||||
|
// The following types of dictionary have actual functional instances. We don't need final
|
||||||
|
// phony dictionary instances for them.
|
||||||
public static final String TYPE_MAIN = "main";
|
public static final String TYPE_MAIN = "main";
|
||||||
public static final String TYPE_CONTACTS = "contacts";
|
public static final String TYPE_CONTACTS = "contacts";
|
||||||
// User dictionary, the system-managed one.
|
// User dictionary, the system-managed one.
|
||||||
|
@ -42,9 +59,7 @@ public abstract class Dictionary {
|
||||||
// Personalization prediction dictionary internal to LatinIME's Java code.
|
// Personalization prediction dictionary internal to LatinIME's Java code.
|
||||||
public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA =
|
public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA =
|
||||||
"personalization_prediction_in_java";
|
"personalization_prediction_in_java";
|
||||||
// Spawned by resuming suggestions. Comes from a span that was in the TextView.
|
public final String mDictType;
|
||||||
public static final String TYPE_RESUMED = "resumed";
|
|
||||||
protected final String mDictType;
|
|
||||||
|
|
||||||
public Dictionary(final String dictType) {
|
public Dictionary(final String dictType) {
|
||||||
mDictType = dictType;
|
mDictType = dictType;
|
||||||
|
@ -114,8 +129,30 @@ public abstract class Dictionary {
|
||||||
/**
|
/**
|
||||||
* Subclasses may override to indicate that this Dictionary is not yet properly initialized.
|
* Subclasses may override to indicate that this Dictionary is not yet properly initialized.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not a true dictionary. A placeholder used to indicate suggestions that don't come from any
|
||||||
|
* real dictionary.
|
||||||
|
*/
|
||||||
|
private static class PhonyDictionary extends Dictionary {
|
||||||
|
// This class is not publicly instantiable.
|
||||||
|
private PhonyDictionary(final String type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
|
final boolean blockOffensiveWords) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidWord(String word) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
// the respective size of the typed word and the suggestion if it matters sometime
|
// the respective size of the typed word and the suggestion if it matters sometime
|
||||||
// in the future.
|
// in the future.
|
||||||
suggestions.add(new SuggestedWordInfo(new String(word, 0, depth + 1), finalFreq,
|
suggestions.add(new SuggestedWordInfo(new String(word, 0, depth + 1), finalFreq,
|
||||||
SuggestedWordInfo.KIND_CORRECTION, mDictType,
|
SuggestedWordInfo.KIND_CORRECTION, this /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
if (suggestions.size() >= Suggest.MAX_SUGGESTIONS) return false;
|
if (suggestions.size() >= Suggest.MAX_SUGGESTIONS) return false;
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
for (int shortcutIndex = 0; shortcutIndex < length; ++shortcutIndex) {
|
for (int shortcutIndex = 0; shortcutIndex < length; ++shortcutIndex) {
|
||||||
final char[] shortcut = node.mShortcutTargets.get(shortcutIndex);
|
final char[] shortcut = node.mShortcutTargets.get(shortcutIndex);
|
||||||
suggestions.add(new SuggestedWordInfo(new String(shortcut, 0, shortcut.length),
|
suggestions.add(new SuggestedWordInfo(new String(shortcut, 0, shortcut.length),
|
||||||
finalFreq, SuggestedWordInfo.KIND_SHORTCUT, mDictType,
|
finalFreq, SuggestedWordInfo.KIND_SHORTCUT, this /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
if (suggestions.size() > Suggest.MAX_SUGGESTIONS) return false;
|
if (suggestions.size() > Suggest.MAX_SUGGESTIONS) return false;
|
||||||
}
|
}
|
||||||
|
@ -659,8 +659,8 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
if (freq >= 0 && node == null) {
|
if (freq >= 0 && node == null) {
|
||||||
suggestions.add(new SuggestedWordInfo(new String(mLookedUpString, index,
|
suggestions.add(new SuggestedWordInfo(new String(mLookedUpString, index,
|
||||||
Constants.DICTIONARY_MAX_WORD_LENGTH - index),
|
Constants.DICTIONARY_MAX_WORD_LENGTH - index),
|
||||||
freq, SuggestedWordInfo.KIND_CORRECTION, mDictType,
|
freq, SuggestedWordInfo.KIND_CORRECTION, this /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2455,7 +2455,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||||
ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion,
|
ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion,
|
||||||
mWordComposer.isBatchMode(), suggestionInfo.mScore, suggestionInfo.mKind,
|
mWordComposer.isBatchMode(), suggestionInfo.mScore, suggestionInfo.mKind,
|
||||||
suggestionInfo.mSourceDict);
|
suggestionInfo.mSourceDict.mDictType);
|
||||||
}
|
}
|
||||||
mConnection.endBatchEdit();
|
mConnection.endBatchEdit();
|
||||||
// Don't allow cancellation of manual pick
|
// Don't allow cancellation of manual pick
|
||||||
|
@ -2584,7 +2584,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (!TextUtils.equals(s, typedWord)) {
|
if (!TextUtils.equals(s, typedWord)) {
|
||||||
suggestions.add(new SuggestedWordInfo(s,
|
suggestions.add(new SuggestedWordInfo(s,
|
||||||
SuggestionStripView.MAX_SUGGESTIONS - i,
|
SuggestionStripView.MAX_SUGGESTIONS - i,
|
||||||
SuggestedWordInfo.KIND_RESUMED, Dictionary.TYPE_RESUMED,
|
SuggestedWordInfo.KIND_RESUMED, Dictionary.DICTIONARY_RESUMED,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,13 +303,14 @@ public final class Suggest {
|
||||||
|
|
||||||
for (int i = 0; i < suggestionsCount; ++i) {
|
for (int i = 0; i < suggestionsCount; ++i) {
|
||||||
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
||||||
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(), wordInfo.mSourceDict);
|
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(),
|
||||||
|
wordInfo.mSourceDict.mDictType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(typedWord)) {
|
if (!TextUtils.isEmpty(typedWord)) {
|
||||||
suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
|
suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
|
||||||
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED,
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED,
|
||||||
Dictionary.TYPE_USER_TYPED,
|
Dictionary.DICTIONARY_USER_TYPED,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
SuggestedWordInfo.removeDups(suggestionsContainer);
|
SuggestedWordInfo.removeDups(suggestionsContainer);
|
||||||
|
@ -353,7 +354,7 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SuggestedWordInfo wordInfo : suggestionsSet) {
|
for (SuggestedWordInfo wordInfo : suggestionsSet) {
|
||||||
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict);
|
LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
||||||
|
|
|
@ -113,7 +113,7 @@ public final class SuggestedWords {
|
||||||
if (null == text) continue;
|
if (null == text) continue;
|
||||||
final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
|
final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
|
||||||
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
|
||||||
Dictionary.TYPE_APPLICATION_DEFINED,
|
Dictionary.DICTIONARY_APPLICATION_DEFINED,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */);
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */);
|
||||||
result.add(suggestedWordInfo);
|
result.add(suggestedWordInfo);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public final class SuggestedWords {
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsList = CollectionUtils.newArrayList();
|
final ArrayList<SuggestedWordInfo> suggestionsList = CollectionUtils.newArrayList();
|
||||||
final HashSet<String> alreadySeen = CollectionUtils.newHashSet();
|
final HashSet<String> alreadySeen = CollectionUtils.newHashSet();
|
||||||
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
||||||
SuggestedWordInfo.KIND_TYPED, Dictionary.TYPE_USER_TYPED,
|
SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
alreadySeen.add(typedWord.toString());
|
alreadySeen.add(typedWord.toString());
|
||||||
final int previousSize = previousSuggestions.size();
|
final int previousSize = previousSuggestions.size();
|
||||||
|
@ -169,7 +169,7 @@ public final class SuggestedWords {
|
||||||
public final int mScore;
|
public final int mScore;
|
||||||
public final int mKind; // one of the KIND_* constants above
|
public final int mKind; // one of the KIND_* constants above
|
||||||
public final int mCodePointCount;
|
public final int mCodePointCount;
|
||||||
public final String mSourceDict;
|
public final Dictionary mSourceDict;
|
||||||
// For auto-commit. This keeps track of the index inside the touch coordinates array
|
// For auto-commit. This keeps track of the index inside the touch coordinates array
|
||||||
// passed to native code to get suggestions for a gesture that corresponds to the first
|
// passed to native code to get suggestions for a gesture that corresponds to the first
|
||||||
// letter of the second word.
|
// letter of the second word.
|
||||||
|
@ -177,7 +177,7 @@ public final class SuggestedWords {
|
||||||
private String mDebugString = "";
|
private String mDebugString = "";
|
||||||
|
|
||||||
public SuggestedWordInfo(final String word, final int score, final int kind,
|
public SuggestedWordInfo(final String word, final int score, final int kind,
|
||||||
final String sourceDict, final int indexOfTouchPointOfSecondWord) {
|
final Dictionary sourceDict, final int indexOfTouchPointOfSecondWord) {
|
||||||
mWord = word;
|
mWord = word;
|
||||||
mScore = score;
|
mScore = score;
|
||||||
mKind = kind;
|
mKind = kind;
|
||||||
|
@ -186,7 +186,6 @@ public final class SuggestedWords {
|
||||||
mIndexOfTouchPointOfSecondWord = indexOfTouchPointOfSecondWord;
|
mIndexOfTouchPointOfSecondWord = indexOfTouchPointOfSecondWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setDebugString(final String str) {
|
public void setDebugString(final String str) {
|
||||||
if (null == str) throw new NullPointerException("Debug info is null");
|
if (null == str) throw new NullPointerException("Debug info is null");
|
||||||
mDebugString = str;
|
mDebugString = str;
|
||||||
|
|
|
@ -298,7 +298,7 @@ public final class SettingsValues {
|
||||||
// TODO: Stop using KeySpceParser.getLabel().
|
// TODO: Stop using KeySpceParser.getLabel().
|
||||||
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,
|
||||||
Dictionary.TYPE_HARDCODED,
|
Dictionary.DICTIONARY_HARDCODED,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ import java.util.Map;
|
||||||
jsonWriter.name("word").value(wordInfo.toString());
|
jsonWriter.name("word").value(wordInfo.toString());
|
||||||
jsonWriter.name("score").value(wordInfo.mScore);
|
jsonWriter.name("score").value(wordInfo.mScore);
|
||||||
jsonWriter.name("kind").value(wordInfo.mKind);
|
jsonWriter.name("kind").value(wordInfo.mKind);
|
||||||
jsonWriter.name("sourceDict").value(wordInfo.mSourceDict);
|
jsonWriter.name("sourceDict").value(wordInfo.mSourceDict.mDictType);
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
}
|
}
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||||
|
|
||||||
protected void pickSuggestionManually(final int index, final String suggestion) {
|
protected void pickSuggestionManually(final int index, final String suggestion) {
|
||||||
mLatinIME.pickSuggestionManually(index, new SuggestedWordInfo(suggestion, 1,
|
mLatinIME.pickSuggestionManually(index, new SuggestedWordInfo(suggestion, 1,
|
||||||
SuggestedWordInfo.KIND_CORRECTION, "main",
|
SuggestedWordInfo.KIND_CORRECTION, null /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,11 @@ public class SuggestedWordsTests extends AndroidTestCase {
|
||||||
final int NUMBER_OF_ADDED_SUGGESTIONS = 5;
|
final int NUMBER_OF_ADDED_SUGGESTIONS = 5;
|
||||||
final ArrayList<SuggestedWordInfo> list = CollectionUtils.newArrayList();
|
final ArrayList<SuggestedWordInfo> list = CollectionUtils.newArrayList();
|
||||||
list.add(new SuggestedWordInfo(TYPED_WORD, TYPED_WORD_FREQ,
|
list.add(new SuggestedWordInfo(TYPED_WORD, TYPED_WORD_FREQ,
|
||||||
SuggestedWordInfo.KIND_TYPED, "",
|
SuggestedWordInfo.KIND_TYPED, null /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
for (int i = 0; i < NUMBER_OF_ADDED_SUGGESTIONS; ++i) {
|
for (int i = 0; i < NUMBER_OF_ADDED_SUGGESTIONS; ++i) {
|
||||||
list.add(new SuggestedWordInfo("" + i, 1, SuggestedWordInfo.KIND_CORRECTION, "",
|
list.add(new SuggestedWordInfo("" + i, 1, SuggestedWordInfo.KIND_CORRECTION,
|
||||||
|
null /* sourceDict */,
|
||||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue