From 499371a5efdd5e3b76d12370fcd63fb7963a2488 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Wed, 11 Dec 2013 11:09:52 +0900 Subject: [PATCH] Remove PersonalizationDictinoary. Now, PersonalizationPredictionDictionary can be used not only for prediction but also for suggestions. We should rename PersonalizationPredictionDictionary to PersonalizationDictionary. Change-Id: Ifcf4459072f3523e3f3dc783f12e15b89cdbb12d --- .../android/inputmethod/latin/Dictionary.java | 9 +-- .../android/inputmethod/latin/LatinIME.java | 7 -- .../android/inputmethod/latin/Suggest.java | 8 --- .../PersonalizationDictionary.java | 68 ------------------- ...ersonalizationDictionaryUpdateSession.java | 29 -------- .../PersonalizationHelper.java | 29 -------- .../PersonalizationPredictionDictionary.java | 1 + 7 files changed, 4 insertions(+), 147 deletions(-) delete mode 100644 java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index fa79f5af7..d2b32cd77 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -52,13 +52,10 @@ public abstract class Dictionary { public static final String TYPE_CONTACTS = "contacts"; // User dictionary, the system-managed one. public static final String TYPE_USER = "user"; - // User history dictionary internal to LatinIME. This assumes bigram prediction for now. + // User history dictionary internal to LatinIME. public static final String TYPE_USER_HISTORY = "history"; - // Personalization binary dictionary internal to LatinIME. - public static final String TYPE_PERSONALIZATION = "personalization"; - // Personalization prediction dictionary internal to LatinIME's Java code. - public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA = - "personalization_prediction_in_java"; + // Personalization dictionary. + public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA = "personalization"; public final String mDictType; public Dictionary(final String dictType) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b3e711690..416e78b03 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -77,7 +77,6 @@ import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.personalization.DictionaryDecayBroadcastReciever; -import com.android.inputmethod.latin.personalization.PersonalizationDictionary; import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister; import com.android.inputmethod.latin.personalization.PersonalizationHelper; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; @@ -183,7 +182,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private UserBinaryDictionary mUserDictionary; private UserHistoryDictionary mUserHistoryDictionary; private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary; - private PersonalizationDictionary mPersonalizationDictionary; private boolean mIsUserDictionaryAvailable; private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; @@ -644,14 +642,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mIsUserDictionaryAvailable = mUserDictionary.isEnabled(); newSuggest.setUserDictionary(mUserDictionary); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary( this, subtypeLocale); newSuggest.setUserHistoryDictionary(mUserHistoryDictionary); - mPersonalizationDictionary = - PersonalizationHelper.getPersonalizationDictionary(this, subtypeLocale); - newSuggest.setPersonalizationDictionary(mPersonalizationDictionary); mPersonalizationPredictionDictionary = PersonalizationHelper.getPersonalizationPredictionDictionary(this, subtypeLocale); newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 53f04b118..043faafd5 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -24,7 +24,6 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.personalization.PersonalizationDictionary; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.settings.Settings; @@ -89,7 +88,6 @@ public final class Suggest { if (Settings.readUseOnlyPersonalizationDictionaryForDebug( PreferenceManager.getDefaultSharedPreferences(context))) { mOnlyDictionarySetForDebug = new HashSet(); - mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION); mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA); } } @@ -200,12 +198,6 @@ public final class Suggest { personalizationPredictionDictionary); } - public void setPersonalizationDictionary( - final PersonalizationDictionary personalizationDictionary) { - addOrReplaceDictionaryInternal(Dictionary.TYPE_PERSONALIZATION, - personalizationDictionary); - } - public void setAutoCorrectionThreshold(float threshold) { mAutoCorrectionThreshold = threshold; } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java deleted file mode 100644 index 8d3dcc31c..000000000 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.latin.personalization; - -import com.android.inputmethod.latin.Dictionary; -import com.android.inputmethod.latin.ExpandableBinaryDictionary; -import com.android.inputmethod.latin.utils.CollectionUtils; - -import android.content.Context; - -import java.util.ArrayList; -import java.util.Locale; - -/** - * This class is a dictionary for the personalized language model that uses binary dictionary. - */ -public class PersonalizationDictionary extends ExpandableBinaryDictionary { - private static final String NAME = "personalization"; - private final ArrayList mSessions = - CollectionUtils.newArrayList(); - - public PersonalizationDictionary(final Context context, final Locale locale) { - // TODO: Make isUpdatable true. - super(context, getFilenameWithLocale(NAME, locale), locale, - Dictionary.TYPE_PERSONALIZATION, false /* isUpdatable */); - // TODO: Restore last updated time - loadDictionary(); - } - - @Override - protected void loadDictionaryAsync() { - // TODO: Implement - } - - @Override - protected boolean hasContentChanged() { - return false; - } - - @Override - protected boolean needsToReloadBeforeWriting() { - return false; - } - - public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) { - session.setDictionary(this); - mSessions.add(session); - session.onDictionaryReady(); - } - - public void unRegisterUpdateSession(PersonalizationDictionaryUpdateSession session) { - mSessions.remove(session); - } -} diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java index 3eb8bf4bb..0187a383d 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java @@ -30,8 +30,6 @@ import java.util.Locale; * dictionary. */ public abstract class PersonalizationDictionaryUpdateSession { - // TODO: Use a dynamic binary dictionary instead - public WeakReference mDictionary; public WeakReference mPredictionDictionary; public final Locale mSystemLocale; @@ -43,31 +41,15 @@ public abstract class PersonalizationDictionaryUpdateSession { public abstract void onDictionaryClosed(Context context); - public void setDictionary(PersonalizationDictionary dictionary) { - mDictionary = new WeakReference(dictionary); - } - public void setPredictionDictionary(DecayingExpandableBinaryDictionaryBase dictionary) { mPredictionDictionary = new WeakReference(dictionary); } - protected PersonalizationDictionary getDictionary() { - return mDictionary == null ? null : mDictionary.get(); - } - protected DecayingExpandableBinaryDictionaryBase getPredictionDictionary() { return mPredictionDictionary == null ? null : mPredictionDictionary.get(); } - private void unsetDictionary() { - final PersonalizationDictionary dictionary = getDictionary(); - if (dictionary == null) { - return; - } - dictionary.unRegisterUpdateSession(this); - } - private void unsetPredictionDictionary() { final DecayingExpandableBinaryDictionaryBase dictionary = getPredictionDictionary(); if (dictionary == null) { @@ -85,21 +67,10 @@ public abstract class PersonalizationDictionaryUpdateSession { } public void closeSession(Context context) { - unsetDictionary(); unsetPredictionDictionary(); onDictionaryClosed(context); } - // TODO: Support multi locale to add bigram - public void addBigramToPersonalizationDictionary(String word0, String word1, boolean isValid, - int frequency, int timestamp) { - final DecayingExpandableBinaryDictionaryBase dictionary = getPredictionDictionary(); - if (dictionary == null) { - return; - } - dictionary.addToDictionary(word0, word1, isValid, timestamp); - } - // TODO: Support multi locale. public void addMultipleDictionaryEntriesToPersonalizationDictionary( final ArrayList languageModelParams, diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java index f73bb28af..56a857439 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java @@ -19,8 +19,6 @@ package com.android.inputmethod.latin.personalization; import com.android.inputmethod.latin.utils.CollectionUtils; import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.util.Log; import java.lang.ref.SoftReference; @@ -33,9 +31,6 @@ public class PersonalizationHelper { private static final ConcurrentHashMap> sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap(); - private static final ConcurrentHashMap> - sLangPersonalizationDictCache = CollectionUtils.newConcurrentHashMap(); - private static final ConcurrentHashMap> sLangPersonalizationPredictionDictCache = @@ -81,30 +76,6 @@ public class PersonalizationHelper { final PersonalizationPredictionDictionary predictionDictionary = getPersonalizationPredictionDictionary(context, locale); predictionDictionary.registerUpdateSession(session); - final PersonalizationDictionary dictionary = getPersonalizationDictionary(context, locale); - dictionary.registerUpdateSession(session); - } - - public static PersonalizationDictionary getPersonalizationDictionary( - final Context context, final Locale locale) { - final String localeStr = locale.toString(); - synchronized (sLangPersonalizationDictCache) { - if (sLangPersonalizationDictCache.containsKey(localeStr)) { - final SoftReference ref = - sLangPersonalizationDictCache.get(localeStr); - final PersonalizationDictionary dict = ref == null ? null : ref.get(); - if (dict != null) { - if (DEBUG) { - Log.w(TAG, "Use cached PersonalizationDictCache for " + locale); - } - return dict; - } - } - final PersonalizationDictionary dict = new PersonalizationDictionary(context, locale); - sLangPersonalizationDictCache.put( - localeStr, new SoftReference(dict)); - return dict; - } } public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary( diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationPredictionDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationPredictionDictionary.java index 6d947162d..6e0f25305 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationPredictionDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationPredictionDictionary.java @@ -23,6 +23,7 @@ import java.util.Locale; import android.content.Context; +// TODO: Rename to PersonalizationDictionary. public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase { private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName();