Merge "Deactivate the user unigram dictionary."
This commit is contained in:
commit
494ab16396
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 {
|
||||||
sDictProjectionMap = new HashMap<String, String>();
|
if (ENABLE_USER_UNIGRAM_DICTIONARY) {
|
||||||
sDictProjectionMap.put(COLUMN_ID, COLUMN_ID);
|
sDictProjectionMap = new HashMap<String, String>();
|
||||||
sDictProjectionMap.put(COLUMN_WORD, COLUMN_WORD);
|
sDictProjectionMap.put(COLUMN_ID, COLUMN_ID);
|
||||||
sDictProjectionMap.put(COLUMN_FREQUENCY, COLUMN_FREQUENCY);
|
sDictProjectionMap.put(COLUMN_WORD, COLUMN_WORD);
|
||||||
sDictProjectionMap.put(COLUMN_LOCALE, COLUMN_LOCALE);
|
sDictProjectionMap.put(COLUMN_FREQUENCY, COLUMN_FREQUENCY);
|
||||||
|
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