Deactivate the user unigram dictionary.
Bug: 3459274 Change-Id: I41b7617623b5b2e48c2e460dc7f2d5ff410c8a4c
This commit is contained in:
parent
faf913c1b2
commit
52f20d6a43
1 changed files with 18 additions and 6 deletions
|
@ -36,6 +36,8 @@ import java.util.Set;
|
||||||
* for suggesting and re-ordering of candidates.
|
* for suggesting and re-ordering of candidates.
|
||||||
*/
|
*/
|
||||||
public class UserUnigramDictionary extends ExpandableDictionary {
|
public class UserUnigramDictionary extends ExpandableDictionary {
|
||||||
|
static final boolean ENABLE_USER_UNIGRAM_DICTIONARY = false;
|
||||||
|
|
||||||
// Weight added to a user picking a new word from the suggestion strip
|
// Weight added to a user picking a new word from the suggestion strip
|
||||||
static final int FREQUENCY_FOR_PICKED = 3;
|
static final int FREQUENCY_FOR_PICKED = 3;
|
||||||
// Weight added to a user typing a new word that doesn't get corrected (or is reverted)
|
// Weight added to a user typing a new word that doesn't get corrected (or is reverted)
|
||||||
|
@ -71,17 +73,22 @@ public class UserUnigramDictionary extends ExpandableDictionary {
|
||||||
private static HashMap<String, String> sDictProjectionMap;
|
private static HashMap<String, String> sDictProjectionMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
if (ENABLE_USER_UNIGRAM_DICTIONARY) {
|
||||||
sDictProjectionMap = new HashMap<String, String>();
|
sDictProjectionMap = new HashMap<String, String>();
|
||||||
sDictProjectionMap.put(COLUMN_ID, COLUMN_ID);
|
sDictProjectionMap.put(COLUMN_ID, COLUMN_ID);
|
||||||
sDictProjectionMap.put(COLUMN_WORD, COLUMN_WORD);
|
sDictProjectionMap.put(COLUMN_WORD, COLUMN_WORD);
|
||||||
sDictProjectionMap.put(COLUMN_FREQUENCY, COLUMN_FREQUENCY);
|
sDictProjectionMap.put(COLUMN_FREQUENCY, COLUMN_FREQUENCY);
|
||||||
sDictProjectionMap.put(COLUMN_LOCALE, COLUMN_LOCALE);
|
sDictProjectionMap.put(COLUMN_LOCALE, COLUMN_LOCALE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static DatabaseHelper sOpenHelper = null;
|
private static DatabaseHelper sOpenHelper = null;
|
||||||
|
|
||||||
public UserUnigramDictionary(Context context, LatinIME ime, String locale, int dicTypeId) {
|
public UserUnigramDictionary(Context context, LatinIME ime, String locale, int dicTypeId) {
|
||||||
super(context, dicTypeId);
|
super(context, dicTypeId);
|
||||||
|
// Super must be first statement of the constructor... I'd like not to do it if the
|
||||||
|
// user unigram dictionary is not enabled, but Java won't let me.
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return;
|
||||||
mIme = ime;
|
mIme = ime;
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
if (sOpenHelper == null) {
|
if (sOpenHelper == null) {
|
||||||
|
@ -94,22 +101,25 @@ public class UserUnigramDictionary extends ExpandableDictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isValidWord(CharSequence word) {
|
public synchronized boolean isValidWord(CharSequence word) {
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return false;
|
||||||
final int frequency = getWordFrequency(word);
|
final int frequency = getWordFrequency(word);
|
||||||
return frequency >= VALIDITY_THRESHOLD;
|
return frequency >= VALIDITY_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
super.close();
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return;
|
||||||
flushPendingWrites();
|
flushPendingWrites();
|
||||||
// Don't close the database as locale changes will require it to be reopened anyway
|
// Don't close the database as locale changes will require it to be reopened anyway
|
||||||
// Also, the database is written to somewhat frequently, so it needs to be kept alive
|
// Also, the database is written to somewhat frequently, so it needs to be kept alive
|
||||||
// throughout the life of the process.
|
// throughout the life of the process.
|
||||||
// mOpenHelper.close();
|
// mOpenHelper.close();
|
||||||
super.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadDictionaryAsync() {
|
public void loadDictionaryAsync() {
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return;
|
||||||
// Load the words that correspond to the current input locale
|
// Load the words that correspond to the current input locale
|
||||||
Cursor cursor = query(COLUMN_LOCALE + "=?", new String[] { mLocale });
|
Cursor cursor = query(COLUMN_LOCALE + "=?", new String[] { mLocale });
|
||||||
try {
|
try {
|
||||||
|
@ -134,6 +144,7 @@ public class UserUnigramDictionary extends ExpandableDictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addWord(String newWord, int addFrequency) {
|
public void addWord(String newWord, int addFrequency) {
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return;
|
||||||
String word = newWord;
|
String word = newWord;
|
||||||
final int length = word.length();
|
final int length = word.length();
|
||||||
// Don't add very short or very long words.
|
// Don't add very short or very long words.
|
||||||
|
@ -156,6 +167,7 @@ public class UserUnigramDictionary extends ExpandableDictionary {
|
||||||
* Schedules a background thread to write any pending words to the database.
|
* Schedules a background thread to write any pending words to the database.
|
||||||
*/
|
*/
|
||||||
public void flushPendingWrites() {
|
public void flushPendingWrites() {
|
||||||
|
if (!ENABLE_USER_UNIGRAM_DICTIONARY) return;
|
||||||
synchronized (mPendingWritesLock) {
|
synchronized (mPendingWritesLock) {
|
||||||
// Nothing pending? Return
|
// Nothing pending? Return
|
||||||
if (mPendingWrites.isEmpty()) return;
|
if (mPendingWrites.isEmpty()) return;
|
||||||
|
|
Loading…
Reference in a new issue