Refactor the personalization dictionary
Bug: 9429906 Bug: 4192129 Change-Id: I9f094bc5a6ce4652e310e090f1536e43f1f24ad1main
parent
883bd364eb
commit
853d0fd122
|
@ -46,14 +46,14 @@ import java.util.ArrayList;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a dictionary for the personalized prediction language model implemented in Java.
|
* This class is a base class of a dictionary for the personalized prediction language model.
|
||||||
*/
|
*/
|
||||||
public abstract class PersonalizationPredictionDictionary extends ExpandableDictionary {
|
public abstract class DynamicPredictionDictionaryBase extends ExpandableDictionary {
|
||||||
public static void registerUpdateListener(PersonalizationDictionaryUpdateListener listener) {
|
public static void registerUpdateListener(PersonalizationDictionaryUpdateListener listener) {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = PersonalizationPredictionDictionary.class.getSimpleName();
|
private static final String TAG = DynamicPredictionDictionaryBase.class.getSimpleName();
|
||||||
public static final boolean DBG_SAVE_RESTORE = false;
|
public static final boolean DBG_SAVE_RESTORE = false;
|
||||||
private static final boolean DBG_STRESS_TEST = false;
|
private static final boolean DBG_STRESS_TEST = false;
|
||||||
private static final boolean PROFILE_SAVE_RESTORE = LatinImeLogger.sDBG;
|
private static final boolean PROFILE_SAVE_RESTORE = LatinImeLogger.sDBG;
|
||||||
|
@ -78,7 +78,7 @@ public abstract class PersonalizationPredictionDictionary extends ExpandableDict
|
||||||
// Should always be false except when we use this class for test
|
// Should always be false except when we use this class for test
|
||||||
@UsedForTesting boolean isTest = false;
|
@UsedForTesting boolean isTest = false;
|
||||||
|
|
||||||
/* package */ PersonalizationPredictionDictionary(final Context context, final String locale,
|
/* package */ DynamicPredictionDictionaryBase(final Context context, final String locale,
|
||||||
final SharedPreferences sp, final String dictionaryType) {
|
final SharedPreferences sp, final String dictionaryType) {
|
||||||
super(context, dictionaryType);
|
super(context, dictionaryType);
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
|
@ -279,16 +279,16 @@ public abstract class PersonalizationPredictionDictionary extends ExpandableDict
|
||||||
private final UserHistoryDictionaryBigramList mBigramList;
|
private final UserHistoryDictionaryBigramList mBigramList;
|
||||||
private final boolean mAddLevel0Bigrams;
|
private final boolean mAddLevel0Bigrams;
|
||||||
private final String mLocale;
|
private final String mLocale;
|
||||||
private final PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
|
private final DynamicPredictionDictionaryBase mDynamicPredictionDictionary;
|
||||||
private final SharedPreferences mPrefs;
|
private final SharedPreferences mPrefs;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public UpdateBinaryTask(final UserHistoryDictionaryBigramList pendingWrites,
|
public UpdateBinaryTask(final UserHistoryDictionaryBigramList pendingWrites,
|
||||||
final String locale, final PersonalizationPredictionDictionary dict,
|
final String locale, final DynamicPredictionDictionaryBase dict,
|
||||||
final SharedPreferences prefs, final Context context) {
|
final SharedPreferences prefs, final Context context) {
|
||||||
mBigramList = pendingWrites;
|
mBigramList = pendingWrites;
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mPersonalizationPredictionDictionary = dict;
|
mDynamicPredictionDictionary = dict;
|
||||||
mPrefs = prefs;
|
mPrefs = prefs;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mAddLevel0Bigrams = mBigramList.size() <= MAX_HISTORY_BIGRAMS;
|
mAddLevel0Bigrams = mBigramList.size() <= MAX_HISTORY_BIGRAMS;
|
||||||
|
@ -296,19 +296,19 @@ public abstract class PersonalizationPredictionDictionary extends ExpandableDict
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(final Void... v) {
|
protected Void doInBackground(final Void... v) {
|
||||||
if (mPersonalizationPredictionDictionary.isTest) {
|
if (mDynamicPredictionDictionary.isTest) {
|
||||||
// If isTest == true, wait until the lock is released.
|
// If isTest == true, wait until the lock is released.
|
||||||
mPersonalizationPredictionDictionary.mBigramListLock.lock();
|
mDynamicPredictionDictionary.mBigramListLock.lock();
|
||||||
try {
|
try {
|
||||||
doWriteTaskLocked();
|
doWriteTaskLocked();
|
||||||
} finally {
|
} finally {
|
||||||
mPersonalizationPredictionDictionary.mBigramListLock.unlock();
|
mDynamicPredictionDictionary.mBigramListLock.unlock();
|
||||||
}
|
}
|
||||||
} else if (mPersonalizationPredictionDictionary.mBigramListLock.tryLock()) {
|
} else if (mDynamicPredictionDictionary.mBigramListLock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
doWriteTaskLocked();
|
doWriteTaskLocked();
|
||||||
} finally {
|
} finally {
|
||||||
mPersonalizationPredictionDictionary.mBigramListLock.unlock();
|
mDynamicPredictionDictionary.mBigramListLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -327,7 +327,7 @@ public abstract class PersonalizationPredictionDictionary extends ExpandableDict
|
||||||
|
|
||||||
final long now = PROFILE_SAVE_RESTORE ? System.currentTimeMillis() : 0;
|
final long now = PROFILE_SAVE_RESTORE ? System.currentTimeMillis() : 0;
|
||||||
final String fileName =
|
final String fileName =
|
||||||
mPersonalizationPredictionDictionary.getDictionaryFileName();
|
mDynamicPredictionDictionary.getDictionaryFileName();
|
||||||
final File file = new File(mContext.getFilesDir(), fileName);
|
final File file = new File(mContext.getFilesDir(), fileName);
|
||||||
FileOutputStream out = null;
|
FileOutputStream out = null;
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ public abstract class PersonalizationPredictionDictionary extends ExpandableDict
|
||||||
final byte prevFc = mBigramList.getBigrams(word1).get(word2);
|
final byte prevFc = mBigramList.getBigrams(word1).get(word2);
|
||||||
} else { // bigram
|
} else { // bigram
|
||||||
final NextWord nw =
|
final NextWord nw =
|
||||||
mPersonalizationPredictionDictionary.getBigramWord(word1, word2);
|
mDynamicPredictionDictionary.getBigramWord(word1, word2);
|
||||||
if (nw != null) {
|
if (nw != null) {
|
||||||
final ForgettingCurveParams fcp = nw.getFcParams();
|
final ForgettingCurveParams fcp = nw.getFcParams();
|
||||||
final byte prevFc = mBigramList.getBigrams(word1).get(word2);
|
final byte prevFc = mBigramList.getBigrams(word1).get(word2);
|
|
@ -25,10 +25,8 @@ import android.content.SharedPreferences;
|
||||||
* Locally gathers stats about the words user types and various other signals like auto-correction
|
* Locally gathers stats about the words user types and various other signals like auto-correction
|
||||||
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
|
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
|
||||||
*/
|
*/
|
||||||
public class UserHistoryPredictionDictionary extends PersonalizationPredictionDictionary {
|
public class UserHistoryPredictionDictionary extends DynamicPredictionDictionaryBase {
|
||||||
private static final String TAG = UserHistoryPredictionDictionary.class.getSimpleName();
|
|
||||||
private static final String NAME = UserHistoryPredictionDictionary.class.getSimpleName();
|
private static final String NAME = UserHistoryPredictionDictionary.class.getSimpleName();
|
||||||
|
|
||||||
/* package */ UserHistoryPredictionDictionary(final Context context, final String locale,
|
/* package */ UserHistoryPredictionDictionary(final Context context, final String locale,
|
||||||
final SharedPreferences sp) {
|
final SharedPreferences sp) {
|
||||||
super(context, locale, sp, Dictionary.TYPE_USER_HISTORY);
|
super(context, locale, sp, Dictionary.TYPE_USER_HISTORY);
|
||||||
|
|
Loading…
Reference in New Issue