am 503b7902: Merge "Connect the personalization dictionary"

* commit '503b79029a41d672f6a4c22e2d4f24709a1dfc80':
  Connect the personalization dictionary
main
Satoshi Kataoka 2013-08-01 00:39:39 -07:00 committed by Android Git Automerger
commit 3f30c09d88
3 changed files with 48 additions and 9 deletions

View File

@ -76,6 +76,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.personalization.PersonalizationDictionaryHelper; import com.android.inputmethod.latin.personalization.PersonalizationDictionaryHelper;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary; import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsActivity; import com.android.inputmethod.latin.settings.SettingsActivity;
@ -170,6 +171,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private boolean mIsMainDictionaryAvailable; private boolean mIsMainDictionaryAvailable;
private UserBinaryDictionary mUserDictionary; private UserBinaryDictionary mUserDictionary;
private UserHistoryPredictionDictionary mUserHistoryPredictionDictionary; private UserHistoryPredictionDictionary mUserHistoryPredictionDictionary;
private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
private boolean mIsUserDictionaryAvailable; private boolean mIsUserDictionaryAvailable;
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
@ -560,6 +562,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mUserHistoryPredictionDictionary = PersonalizationDictionaryHelper mUserHistoryPredictionDictionary = PersonalizationDictionaryHelper
.getUserHistoryPredictionDictionary(this, localeStr, prefs); .getUserHistoryPredictionDictionary(this, localeStr, prefs);
newSuggest.setUserHistoryPredictionDictionary(mUserHistoryPredictionDictionary); newSuggest.setUserHistoryPredictionDictionary(mUserHistoryPredictionDictionary);
mPersonalizationPredictionDictionary = PersonalizationDictionaryHelper
.getPersonalizationPredictionDictionary(this, localeStr, prefs);
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);
final Suggest oldSuggest = mSuggest; final Suggest oldSuggest = mSuggest;
resetContactsDictionary(null != oldSuggest ? oldSuggest.getContactsDictionary() : null); resetContactsDictionary(null != oldSuggest ? oldSuggest.getContactsDictionary() : null);
@ -2509,9 +2514,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
if (!currentSettings.mCorrectionEnabled) return null; if (!currentSettings.mCorrectionEnabled) return null;
final UserHistoryPredictionDictionary userHistoryDictionary = final UserHistoryPredictionDictionary userHistoryPredictionDictionary =
mUserHistoryPredictionDictionary; mUserHistoryPredictionDictionary;
if (userHistoryDictionary == null) return null; if (userHistoryPredictionDictionary == null) return null;
final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2); final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2);
final String secondWord; final String secondWord;
@ -2525,7 +2530,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int maxFreq = AutoCorrectionUtils.getMaxFrequency( final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
suggest.getUnigramDictionaries(), suggestion); suggest.getUnigramDictionaries(), suggestion);
if (maxFreq == 0) return null; if (maxFreq == 0) return null;
userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); userHistoryPredictionDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
return prevWord; return prevWord;
} }

View File

@ -22,6 +22,7 @@ import android.text.TextUtils;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary; import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
import com.android.inputmethod.latin.utils.BoundedTreeSet; import com.android.inputmethod.latin.utils.BoundedTreeSet;
@ -174,6 +175,12 @@ public final class Suggest {
userHistoryPredictionDictionary); userHistoryPredictionDictionary);
} }
public void setPersonalizationPredictionDictionary(
final PersonalizationPredictionDictionary personalizationPredictionDictionary) {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA,
personalizationPredictionDictionary);
}
public void setAutoCorrectionThreshold(float threshold) { public void setAutoCorrectionThreshold(float threshold) {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }

View File

@ -30,25 +30,52 @@ public class PersonalizationDictionaryHelper {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final ConcurrentHashMap<String, SoftReference<UserHistoryPredictionDictionary>> private static final ConcurrentHashMap<String, SoftReference<UserHistoryPredictionDictionary>>
sLangDictCache = CollectionUtils.newConcurrentHashMap(); sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap();
private static final ConcurrentHashMap<String,
SoftReference<PersonalizationPredictionDictionary>>
sLangPersonalizationDictCache = CollectionUtils.newConcurrentHashMap();
public static UserHistoryPredictionDictionary getUserHistoryPredictionDictionary( public static UserHistoryPredictionDictionary getUserHistoryPredictionDictionary(
final Context context, final String locale, final SharedPreferences sp) { final Context context, final String locale, final SharedPreferences sp) {
synchronized (sLangDictCache) { synchronized (sLangUserHistoryDictCache) {
if (sLangDictCache.containsKey(locale)) { if (sLangUserHistoryDictCache.containsKey(locale)) {
final SoftReference<UserHistoryPredictionDictionary> ref = final SoftReference<UserHistoryPredictionDictionary> ref =
sLangDictCache.get(locale); sLangUserHistoryDictCache.get(locale);
final UserHistoryPredictionDictionary dict = ref == null ? null : ref.get(); final UserHistoryPredictionDictionary dict = ref == null ? null : ref.get();
if (dict != null) { if (dict != null) {
if (DEBUG) { if (DEBUG) {
Log.w(TAG, "Use cached UserHistoryDictionary for " + locale); Log.w(TAG, "Use cached UserHistoryPredictionDictionary for " + locale);
} }
return dict; return dict;
} }
} }
final UserHistoryPredictionDictionary dict = final UserHistoryPredictionDictionary dict =
new UserHistoryPredictionDictionary(context, locale, sp); new UserHistoryPredictionDictionary(context, locale, sp);
sLangDictCache.put(locale, new SoftReference<UserHistoryPredictionDictionary>(dict)); sLangUserHistoryDictCache.put(
locale, new SoftReference<UserHistoryPredictionDictionary>(dict));
return dict;
}
}
public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(
final Context context, final String locale, final SharedPreferences sp) {
synchronized (sLangPersonalizationDictCache) {
if (sLangPersonalizationDictCache.containsKey(locale)) {
final SoftReference<PersonalizationPredictionDictionary> ref =
sLangPersonalizationDictCache.get(locale);
final PersonalizationPredictionDictionary dict = ref == null ? null : ref.get();
if (dict != null) {
if (DEBUG) {
Log.w(TAG, "Use cached PersonalizationPredictionDictionary for " + locale);
}
return dict;
}
}
final PersonalizationPredictionDictionary dict =
new PersonalizationPredictionDictionary(context, locale, sp);
sLangPersonalizationDictCache.put(
locale, new SoftReference<PersonalizationPredictionDictionary>(dict));
return dict; return dict;
} }
} }