Merge "Neutralize Suggest#addWords (A12)"

main
Jean Chalard 2012-06-26 01:52:32 -07:00 committed by Android (Google) Code Review
commit a4bd4e442e
1 changed files with 39 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -63,6 +64,18 @@ public class Suggest implements Dictionary.WordCallback {
// User history dictionary for the bigram map, internal to LatinIME // User history dictionary for the bigram map, internal to LatinIME
public static final String DICT_KEY_USER_HISTORY_BIGRAM = "history_bigram"; public static final String DICT_KEY_USER_HISTORY_BIGRAM = "history_bigram";
public static final String DICT_KEY_WHITELIST ="whitelist"; public static final String DICT_KEY_WHITELIST ="whitelist";
// TODO: remove this map. This only serves as backward compatibility with a feature
// that has never been used and has been broken for a while.
private static final HashMap<String, Integer> sDictKeyToDictIndex
= new HashMap<String, Integer>();
static {
sDictKeyToDictIndex.put(DICT_KEY_MAIN, DIC_MAIN);
sDictKeyToDictIndex.put(DICT_KEY_USER, DIC_USER);
sDictKeyToDictIndex.put(DICT_KEY_USER_HISTORY_UNIGRAM, DIC_USER_HISTORY);
sDictKeyToDictIndex.put(DICT_KEY_USER_HISTORY_BIGRAM, DIC_USER_HISTORY);
sDictKeyToDictIndex.put(DICT_KEY_CONTACTS, DIC_CONTACTS);
sDictKeyToDictIndex.put(DICT_KEY_WHITELIST, DIC_WHITELIST);
}
private static final boolean DBG = LatinImeLogger.sDBG; private static final boolean DBG = LatinImeLogger.sDBG;
@ -247,10 +260,18 @@ public class Suggest implements Dictionary.WordCallback {
lowerPrevWord = null; lowerPrevWord = null;
} }
for (final String key : mBigramDictionaries.keySet()) { for (final String key : mBigramDictionaries.keySet()) {
final int dicTypeId = sDictKeyToDictIndex.get(key);
final Dictionary dictionary = mBigramDictionaries.get(key); final Dictionary dictionary = mBigramDictionaries.get(key);
final ArrayList<SuggestedWordInfo> suggestions =
dictionary.getBigrams(wordComposer, prevWordForBigram, this); dictionary.getBigrams(wordComposer, prevWordForBigram, this);
if (null != lowerPrevWord) { if (null != lowerPrevWord) {
dictionary.getBigrams(wordComposer, lowerPrevWord, this); suggestions.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord,
this));
}
for (final SuggestedWordInfo suggestion : suggestions) {
final String suggestionStr = suggestion.mWord.toString();
oldAddWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(),
suggestion.mScore, dicTypeId, Dictionary.BIGRAM);
} }
} }
} }
@ -269,8 +290,16 @@ public class Suggest implements Dictionary.WordCallback {
// Skip UserUnigramDictionary and WhitelistDictionary to lookup // Skip UserUnigramDictionary and WhitelistDictionary to lookup
if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST)) if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
continue; continue;
final int dicTypeId = sDictKeyToDictIndex.get(key);
final Dictionary dictionary = mUnigramDictionaries.get(key); final Dictionary dictionary = mUnigramDictionaries.get(key);
dictionary.getWords(wordComposerForLookup, prevWordForBigram, this, proximityInfo); final ArrayList<SuggestedWordInfo> suggestions =
dictionary.getWords(wordComposerForLookup, prevWordForBigram, this,
proximityInfo);
for (final SuggestedWordInfo suggestion : suggestions) {
final String suggestionStr = suggestion.mWord.toString();
oldAddWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(),
suggestion.mScore, dicTypeId, Dictionary.UNIGRAM);
}
} }
} }
@ -376,10 +405,16 @@ public class Suggest implements Dictionary.WordCallback {
return suggestionsList; return suggestionsList;
} }
// TODO: Use codepoint instead of char // TODO: Remove this method
@Override @Override
public boolean addWord(final char[] word, int[] indices, final int offset, final int length, public boolean addWord(final char[] word, int[] indices, final int offset, final int length,
int score, final int dicTypeId, final int dataType) { int score, final int dicTypeId, final int dataType) {
return true;
}
// TODO: Use codepoint instead of char
public boolean oldAddWord(final char[] word, int[] indices, final int offset, final int length,
int score, final int dicTypeId, final int dataType) {
int dataTypeForLog = dataType; int dataTypeForLog = dataType;
final ArrayList<SuggestedWordInfo> suggestions; final ArrayList<SuggestedWordInfo> suggestions;
final int prefMaxSuggestions; final int prefMaxSuggestions;