am 499371a5: Remove PersonalizationDictinoary.

* commit '499371a5efdd5e3b76d12370fcd63fb7963a2488':
  Remove PersonalizationDictinoary.
main
Keisuke Kuroyanagi 2013-12-10 19:01:48 -08:00 committed by Android Git Automerger
commit 1171004b65
7 changed files with 4 additions and 147 deletions

View File

@ -52,13 +52,10 @@ public abstract class Dictionary {
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.
public static final String TYPE_USER = "user"; 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"; public static final String TYPE_USER_HISTORY = "history";
// Personalization binary dictionary internal to LatinIME. // Personalization dictionary.
public static final String TYPE_PERSONALIZATION = "personalization"; public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA = "personalization";
// Personalization prediction dictionary internal to LatinIME's Java code.
public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA =
"personalization_prediction_in_java";
public final String mDictType; public final String mDictType;
public Dictionary(final String dictType) { public Dictionary(final String dictType) {

View File

@ -77,7 +77,6 @@ import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
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.DictionaryDecayBroadcastReciever; 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.PersonalizationDictionarySessionRegister;
import com.android.inputmethod.latin.personalization.PersonalizationHelper; import com.android.inputmethod.latin.personalization.PersonalizationHelper;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
@ -183,7 +182,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private UserBinaryDictionary mUserDictionary; private UserBinaryDictionary mUserDictionary;
private UserHistoryDictionary mUserHistoryDictionary; private UserHistoryDictionary mUserHistoryDictionary;
private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary; private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
private PersonalizationDictionary mPersonalizationDictionary;
private boolean mIsUserDictionaryAvailable; private boolean mIsUserDictionaryAvailable;
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
@ -644,14 +642,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mIsUserDictionaryAvailable = mUserDictionary.isEnabled(); mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
newSuggest.setUserDictionary(mUserDictionary); newSuggest.setUserDictionary(mUserDictionary);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary( mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(
this, subtypeLocale); this, subtypeLocale);
newSuggest.setUserHistoryDictionary(mUserHistoryDictionary); newSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
mPersonalizationDictionary =
PersonalizationHelper.getPersonalizationDictionary(this, subtypeLocale);
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
mPersonalizationPredictionDictionary = mPersonalizationPredictionDictionary =
PersonalizationHelper.getPersonalizationPredictionDictionary(this, subtypeLocale); PersonalizationHelper.getPersonalizationPredictionDictionary(this, subtypeLocale);
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary); newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);

View File

@ -24,7 +24,6 @@ import android.util.Log;
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.PersonalizationDictionary;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
@ -89,7 +88,6 @@ public final class Suggest {
if (Settings.readUseOnlyPersonalizationDictionaryForDebug( if (Settings.readUseOnlyPersonalizationDictionaryForDebug(
PreferenceManager.getDefaultSharedPreferences(context))) { PreferenceManager.getDefaultSharedPreferences(context))) {
mOnlyDictionarySetForDebug = new HashSet<String>(); mOnlyDictionarySetForDebug = new HashSet<String>();
mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION);
mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA); mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA);
} }
} }
@ -200,12 +198,6 @@ public final class Suggest {
personalizationPredictionDictionary); personalizationPredictionDictionary);
} }
public void setPersonalizationDictionary(
final PersonalizationDictionary personalizationDictionary) {
addOrReplaceDictionaryInternal(Dictionary.TYPE_PERSONALIZATION,
personalizationDictionary);
}
public void setAutoCorrectionThreshold(float threshold) { public void setAutoCorrectionThreshold(float threshold) {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }

View File

@ -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<PersonalizationDictionaryUpdateSession> 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);
}
}

View File

@ -30,8 +30,6 @@ import java.util.Locale;
* dictionary. * dictionary.
*/ */
public abstract class PersonalizationDictionaryUpdateSession { public abstract class PersonalizationDictionaryUpdateSession {
// TODO: Use a dynamic binary dictionary instead
public WeakReference<PersonalizationDictionary> mDictionary;
public WeakReference<DecayingExpandableBinaryDictionaryBase> mPredictionDictionary; public WeakReference<DecayingExpandableBinaryDictionaryBase> mPredictionDictionary;
public final Locale mSystemLocale; public final Locale mSystemLocale;
@ -43,31 +41,15 @@ public abstract class PersonalizationDictionaryUpdateSession {
public abstract void onDictionaryClosed(Context context); public abstract void onDictionaryClosed(Context context);
public void setDictionary(PersonalizationDictionary dictionary) {
mDictionary = new WeakReference<PersonalizationDictionary>(dictionary);
}
public void setPredictionDictionary(DecayingExpandableBinaryDictionaryBase dictionary) { public void setPredictionDictionary(DecayingExpandableBinaryDictionaryBase dictionary) {
mPredictionDictionary = mPredictionDictionary =
new WeakReference<DecayingExpandableBinaryDictionaryBase>(dictionary); new WeakReference<DecayingExpandableBinaryDictionaryBase>(dictionary);
} }
protected PersonalizationDictionary getDictionary() {
return mDictionary == null ? null : mDictionary.get();
}
protected DecayingExpandableBinaryDictionaryBase getPredictionDictionary() { protected DecayingExpandableBinaryDictionaryBase getPredictionDictionary() {
return mPredictionDictionary == null ? null : mPredictionDictionary.get(); return mPredictionDictionary == null ? null : mPredictionDictionary.get();
} }
private void unsetDictionary() {
final PersonalizationDictionary dictionary = getDictionary();
if (dictionary == null) {
return;
}
dictionary.unRegisterUpdateSession(this);
}
private void unsetPredictionDictionary() { private void unsetPredictionDictionary() {
final DecayingExpandableBinaryDictionaryBase dictionary = getPredictionDictionary(); final DecayingExpandableBinaryDictionaryBase dictionary = getPredictionDictionary();
if (dictionary == null) { if (dictionary == null) {
@ -85,21 +67,10 @@ public abstract class PersonalizationDictionaryUpdateSession {
} }
public void closeSession(Context context) { public void closeSession(Context context) {
unsetDictionary();
unsetPredictionDictionary(); unsetPredictionDictionary();
onDictionaryClosed(context); 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. // TODO: Support multi locale.
public void addMultipleDictionaryEntriesToPersonalizationDictionary( public void addMultipleDictionaryEntriesToPersonalizationDictionary(
final ArrayList<LanguageModelParam> languageModelParams, final ArrayList<LanguageModelParam> languageModelParams,

View File

@ -19,8 +19,6 @@ package com.android.inputmethod.latin.personalization;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
@ -33,9 +31,6 @@ public class PersonalizationHelper {
private static final ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>> private static final ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>>
sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap(); sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap();
private static final ConcurrentHashMap<String, SoftReference<PersonalizationDictionary>>
sLangPersonalizationDictCache = CollectionUtils.newConcurrentHashMap();
private static final ConcurrentHashMap<String, private static final ConcurrentHashMap<String,
SoftReference<PersonalizationPredictionDictionary>> SoftReference<PersonalizationPredictionDictionary>>
sLangPersonalizationPredictionDictCache = sLangPersonalizationPredictionDictCache =
@ -81,30 +76,6 @@ public class PersonalizationHelper {
final PersonalizationPredictionDictionary predictionDictionary = final PersonalizationPredictionDictionary predictionDictionary =
getPersonalizationPredictionDictionary(context, locale); getPersonalizationPredictionDictionary(context, locale);
predictionDictionary.registerUpdateSession(session); 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<PersonalizationDictionary> 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<PersonalizationDictionary>(dict));
return dict;
}
} }
public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary( public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(

View File

@ -23,6 +23,7 @@ import java.util.Locale;
import android.content.Context; import android.content.Context;
// TODO: Rename to PersonalizationDictionary.
public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase { public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase {
private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName(); private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName();