Remove PersonalizationDictinoary.

Now, PersonalizationPredictionDictionary can be used not only
for prediction but also for suggestions.
We should rename PersonalizationPredictionDictionary to
PersonalizationDictionary.

Change-Id: Ifcf4459072f3523e3f3dc783f12e15b89cdbb12d
main
Keisuke Kuroyanagi 2013-12-11 11:09:52 +09:00
parent 7c8075c2ac
commit 499371a5ef
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";
// 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) {

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.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);

View File

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

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.
*/
public abstract class PersonalizationDictionaryUpdateSession {
// TODO: Use a dynamic binary dictionary instead
public WeakReference<PersonalizationDictionary> mDictionary;
public WeakReference<DecayingExpandableBinaryDictionaryBase> 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<PersonalizationDictionary>(dictionary);
}
public void setPredictionDictionary(DecayingExpandableBinaryDictionaryBase dictionary) {
mPredictionDictionary =
new WeakReference<DecayingExpandableBinaryDictionaryBase>(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<LanguageModelParam> languageModelParams,

View File

@ -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<String, SoftReference<UserHistoryDictionary>>
sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap();
private static final ConcurrentHashMap<String, SoftReference<PersonalizationDictionary>>
sLangPersonalizationDictCache = CollectionUtils.newConcurrentHashMap();
private static final ConcurrentHashMap<String,
SoftReference<PersonalizationPredictionDictionary>>
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<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(

View File

@ -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();