Rename the user history dictionary.
UserBigramDictionary -> UserHistoryDictionary. Also update all methods, strings and comments, except those needed for backward compatibility (which only include the name of the database file). Change-Id: I0bccea29880dc566b90100575b83baaa947b03aemain
parent
660776e09b
commit
9ffb94fa13
|
@ -202,7 +202,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
private boolean mShouldSwitchToLastSubtype = true;
|
||||
|
||||
private UserDictionary mUserDictionary;
|
||||
private UserBigramDictionary mUserBigramDictionary;
|
||||
private UserHistoryDictionary mUserHistoryDictionary;
|
||||
private boolean mIsUserDictionaryAvailable;
|
||||
|
||||
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
||||
|
@ -526,11 +526,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
|
||||
resetContactsDictionary(oldContactsDictionary);
|
||||
|
||||
// TODO: rename UserBigramDictionary into UserHistoryDictionary
|
||||
mUserBigramDictionary
|
||||
= new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER_BIGRAM);
|
||||
mSuggest.setUserUnigramDictionary(mUserBigramDictionary);
|
||||
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
||||
mUserHistoryDictionary
|
||||
= new UserHistoryDictionary(this, this, localeStr, Suggest.DIC_USER_HISTORY);
|
||||
mSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
|
||||
|
||||
LocaleUtils.setSystemLocale(res, savedLocale);
|
||||
}
|
||||
|
@ -772,7 +770,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
|
||||
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
||||
if (inputView != null) inputView.closing();
|
||||
if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites();
|
||||
if (mUserHistoryDictionary != null) mUserHistoryDictionary.flushPendingWrites();
|
||||
}
|
||||
|
||||
private void onFinishInputViewInternal(boolean finishingInput) {
|
||||
|
@ -1990,9 +1988,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the UserBigramDictionary and/or UserUnigramDictionary
|
||||
*/
|
||||
private void addToUserHistoryDictionary(final CharSequence suggestion) {
|
||||
if (suggestion == null || suggestion.length() < 1) return;
|
||||
|
||||
|
@ -2004,16 +1999,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
return;
|
||||
}
|
||||
|
||||
if (mUserBigramDictionary != null) {
|
||||
mUserBigramDictionary.addUnigram(suggestion.toString());
|
||||
if (mUserHistoryDictionary != null) {
|
||||
final InputConnection ic = getCurrentInputConnection();
|
||||
final CharSequence prevWord;
|
||||
if (null != ic) {
|
||||
final CharSequence prevWord =
|
||||
EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
|
||||
if (null != prevWord) {
|
||||
mUserBigramDictionary.addBigramPair(prevWord.toString(), suggestion.toString());
|
||||
}
|
||||
prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
|
||||
} else {
|
||||
prevWord = null;
|
||||
}
|
||||
mUserHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(),
|
||||
suggestion.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,9 +62,8 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
public static final int DIC_USER_TYPED = 0;
|
||||
public static final int DIC_MAIN = 1;
|
||||
public static final int DIC_USER = 2;
|
||||
public static final int DIC_USER_UNIGRAM = 3;
|
||||
public static final int DIC_USER_HISTORY = 3;
|
||||
public static final int DIC_CONTACTS = 4;
|
||||
public static final int DIC_USER_BIGRAM = 5;
|
||||
public static final int DIC_WHITELIST = 6;
|
||||
// If you add a type of dictionary, increment DIC_TYPE_LAST_ID
|
||||
// TODO: this value seems unused. Remove it?
|
||||
|
@ -73,10 +72,10 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
public static final String DICT_KEY_CONTACTS = "contacts";
|
||||
// User dictionary, the system-managed one.
|
||||
public static final String DICT_KEY_USER = "user";
|
||||
// User unigram dictionary, internal to LatinIME
|
||||
public static final String DICT_KEY_USER_UNIGRAM = "user_unigram";
|
||||
// User bigram dictionary, internal to LatinIME
|
||||
public static final String DICT_KEY_USER_BIGRAM = "user_bigram";
|
||||
// User history dictionary for the unigram map, internal to LatinIME
|
||||
public static final String DICT_KEY_USER_HISTORY_UNIGRAM = "history_unigram";
|
||||
// User history dictionary for the bigram map, internal to LatinIME
|
||||
public static final String DICT_KEY_USER_HISTORY_BIGRAM = "history_bigram";
|
||||
public static final String DICT_KEY_WHITELIST ="whitelist";
|
||||
|
||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||
|
@ -203,12 +202,11 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_CONTACTS, contactsDictionary);
|
||||
}
|
||||
|
||||
public void setUserUnigramDictionary(Dictionary userUnigramDictionary) {
|
||||
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_USER_UNIGRAM, userUnigramDictionary);
|
||||
}
|
||||
|
||||
public void setUserBigramDictionary(Dictionary userBigramDictionary) {
|
||||
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_USER_BIGRAM, userBigramDictionary);
|
||||
public void setUserHistoryDictionary(Dictionary userHistoryDictionary) {
|
||||
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_USER_HISTORY_UNIGRAM,
|
||||
userHistoryDictionary);
|
||||
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_USER_HISTORY_BIGRAM,
|
||||
userHistoryDictionary);
|
||||
}
|
||||
|
||||
public void setAutoCorrectionThreshold(double threshold) {
|
||||
|
@ -347,7 +345,7 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
// At second character typed, search the unigrams (scores being affected by bigrams)
|
||||
for (final String key : mUnigramDictionaries.keySet()) {
|
||||
// Skip UserUnigramDictionary and WhitelistDictionary to lookup
|
||||
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
||||
if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
||||
continue;
|
||||
final Dictionary dictionary = mUnigramDictionaries.get(key);
|
||||
dictionary.getWords(wordComposerForLookup, this, proximityInfo);
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.BaseColumns;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -32,12 +31,11 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Stores all the pairs user types in databases. Prune the database if the size
|
||||
* gets too big. Unlike AutoDictionary, it even stores the pairs that are already
|
||||
* in the dictionary.
|
||||
* 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.
|
||||
*/
|
||||
public class UserBigramDictionary extends ExpandableDictionary {
|
||||
private static final String TAG = "UserBigramDictionary";
|
||||
public class UserHistoryDictionary extends ExpandableDictionary {
|
||||
private static final String TAG = "UserHistoryDictionary";
|
||||
|
||||
/** Any pair being typed or picked */
|
||||
private static final int FREQUENCY_FOR_TYPED = 2;
|
||||
|
@ -46,14 +44,14 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
private static final int FREQUENCY_MAX = 127;
|
||||
|
||||
/** Maximum number of pairs. Pruning will start when databases goes above this number. */
|
||||
private static int sMaxUserBigrams = 10000;
|
||||
private static int sMaxHistoryBigrams = 10000;
|
||||
|
||||
/**
|
||||
* When it hits maximum bigram pair, it will delete until you are left with
|
||||
* only (sMaxUserBigrams - sDeleteUserBigrams) pairs.
|
||||
* only (sMaxHistoryBigrams - sDeleteHistoryBigrams) pairs.
|
||||
* Do not keep this number small to avoid deleting too often.
|
||||
*/
|
||||
private static int sDeleteUserBigrams = 1000;
|
||||
private static int sDeleteHistoryBigrams = 1000;
|
||||
|
||||
/**
|
||||
* Database version should increase if the database structure changes
|
||||
|
@ -65,7 +63,7 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
/** Name of the words table in the database */
|
||||
private static final String MAIN_TABLE_NAME = "main";
|
||||
// TODO: Consume less space by using a unique id for locale instead of the whole
|
||||
// 2-5 character string. (Same TODO from AutoDictionary)
|
||||
// 2-5 character string.
|
||||
private static final String MAIN_COLUMN_ID = BaseColumns._ID;
|
||||
private static final String MAIN_COLUMN_WORD1 = "word1";
|
||||
private static final String MAIN_COLUMN_WORD2 = "word2";
|
||||
|
@ -133,15 +131,15 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
}
|
||||
}
|
||||
|
||||
public void setDatabaseMax(int maxUserBigram) {
|
||||
sMaxUserBigrams = maxUserBigram;
|
||||
public void setDatabaseMax(int maxHistoryBigram) {
|
||||
sMaxHistoryBigrams = maxHistoryBigram;
|
||||
}
|
||||
|
||||
public void setDatabaseDelete(int deleteUserBigram) {
|
||||
sDeleteUserBigrams = deleteUserBigram;
|
||||
public void setDatabaseDelete(int deleteHistoryBigram) {
|
||||
sDeleteHistoryBigrams = deleteHistoryBigram;
|
||||
}
|
||||
|
||||
public UserBigramDictionary(Context context, LatinIME ime, String locale, int dicTypeId) {
|
||||
public UserHistoryDictionary(Context context, LatinIME ime, String locale, int dicTypeId) {
|
||||
super(context, dicTypeId);
|
||||
mIme = ime;
|
||||
mLocale = locale;
|
||||
|
@ -172,16 +170,6 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single word without context.
|
||||
*
|
||||
* This is a temporary method to match the interface to UserUnigramDictionary. In the end
|
||||
* this should be merged with addBigramPair.
|
||||
*/
|
||||
public void addUnigram(final String newWord) {
|
||||
addBigramPair(null, newWord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pair will be added to the user history dictionary.
|
||||
*
|
||||
|
@ -190,11 +178,12 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
* context, as in beginning of a sentence for example.
|
||||
* The second word may not be null (a NullPointerException would be thrown).
|
||||
*/
|
||||
public int addBigramPair(final String word1, String word2) {
|
||||
public int addToUserHistory(final String word1, String word2) {
|
||||
// remove caps if second word is autocapitalized
|
||||
if (mIme != null && mIme.isAutoCapitalized()) {
|
||||
word2 = Character.toLowerCase(word2.charAt(0)) + word2.substring(1);
|
||||
}
|
||||
super.addWord(word2, FREQUENCY_FOR_TYPED);
|
||||
// Do not insert a word as a bigram of itself
|
||||
if (word2.equals(word1)) {
|
||||
return 0;
|
||||
|
@ -203,7 +192,6 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
int freq;
|
||||
if (null == word1) {
|
||||
freq = FREQUENCY_FOR_TYPED;
|
||||
super.addWord(word2, FREQUENCY_FOR_TYPED);
|
||||
} else {
|
||||
freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED);
|
||||
}
|
||||
|
@ -366,8 +354,8 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
|||
try {
|
||||
int totalRowCount = c.getCount();
|
||||
// prune out old data if we have too much data
|
||||
if (totalRowCount > sMaxUserBigrams) {
|
||||
int numDeleteRows = (totalRowCount - sMaxUserBigrams) + sDeleteUserBigrams;
|
||||
if (totalRowCount > sMaxHistoryBigrams) {
|
||||
int numDeleteRows = (totalRowCount - sMaxHistoryBigrams) + sDeleteHistoryBigrams;
|
||||
int pairIdColumnId = c.getColumnIndex(FREQ_COLUMN_PAIR_ID);
|
||||
c.moveToFirst();
|
||||
int count = 0;
|
Loading…
Reference in New Issue