diff options
author | 2014-04-24 14:48:01 -0700 | |
---|---|---|
committer | 2014-04-24 14:48:01 -0700 | |
commit | 67c0ed8f8c14f79e61cbd16f841b1b1f3a7466d7 (patch) | |
tree | 2d73d42b4a7ec0187b1955d6868a7d64cdb932a9 /java/src/com/android/inputmethod/latin/personalization | |
parent | 978958a41f8e3365643d6b45a9fc36d02c01df44 (diff) | |
download | latinime-67c0ed8f8c14f79e61cbd16f841b1b1f3a7466d7.tar.gz latinime-67c0ed8f8c14f79e61cbd16f841b1b1f3a7466d7.tar.xz latinime-67c0ed8f8c14f79e61cbd16f841b1b1f3a7466d7.zip |
Handle user history dictionary as an ExpandableBinaryDictionary.
Bug: 13755213
Change-Id: I1ea8a6df007af7153852f2d32bf5e8ec669c432b
Diffstat (limited to 'java/src/com/android/inputmethod/latin/personalization')
2 files changed, 30 insertions, 36 deletions
diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java index 46862c1c0..35b4ccd40 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java @@ -65,12 +65,8 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB dumpAllWordsForDebug(); } // Flush pending writes. - flush(); - super.close(); - } - - public void flush() { asyncFlushBinaryDictionary(); + super.close(); } @Override @@ -103,33 +99,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB addMultipleDictionaryEntriesDynamically(languageModelParams, callback); } - /** - * Pair will be added to the decaying dictionary. - * - * The first word may be null. That means we don't know the context, in other words, - * it's only a unigram. The first word may also be an empty string : this means start - * context, as in beginning of a sentence for example. - * The second word may not be null (a NullPointerException would be thrown). - */ - public void addToDictionary(final String word0, final String word1, final boolean isValid, - final int timestamp) { - if (word1.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH || - (word0 != null && word0.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH)) { - return; - } - final int frequency = isValid ? - FREQUENCY_FOR_WORDS_IN_DICTS : FREQUENCY_FOR_WORDS_NOT_IN_DICTS; - addWordDynamically(word1, frequency, null /* shortcutTarget */, 0 /* shortcutFreq */, - false /* isNotAWord */, false /* isBlacklisted */, timestamp); - // Do not insert a word as a bigram of itself - if (word1.equals(word0)) { - return; - } - if (null != word0) { - addBigramDynamically(word0, word1, frequency, timestamp); - } - } - @Override protected void loadInitialContentsLocked() { // No initial contents. diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index 504e9b2f3..8a29c354d 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -18,7 +18,9 @@ package com.android.inputmethod.latin.personalization; import android.content.Context; +import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; +import com.android.inputmethod.latin.ExpandableBinaryDictionary; import java.io.File; import java.util.Locale; @@ -40,13 +42,36 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas dictFile); } - public void cancelAddingUserHistory(final String word0, final String word1) { - removeBigramDynamically(word0, word1); - } - @Override public boolean isValidWord(final String word) { // Strings out of this dictionary should not be considered existing words. return false; } + + /** + * Pair will be added to the user history dictionary. + * + * The first word may be null. That means we don't know the context, in other words, + * it's only a unigram. The first word may also be an empty string : this means start + * context, as in beginning of a sentence for example. + * The second word may not be null (a NullPointerException would be thrown). + */ + public static void addToDictionary(final ExpandableBinaryDictionary userHistoryDictionary, + final String word0, final String word1, final boolean isValid, final int timestamp) { + if (word1.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH || + (word0 != null && word0.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH)) { + return; + } + final int frequency = isValid ? + FREQUENCY_FOR_WORDS_IN_DICTS : FREQUENCY_FOR_WORDS_NOT_IN_DICTS; + userHistoryDictionary.addWordDynamically(word1, frequency, null /* shortcutTarget */, + 0 /* shortcutFreq */, false /* isNotAWord */, false /* isBlacklisted */, timestamp); + // Do not insert a word as a bigram of itself + if (word1.equals(word0)) { + return; + } + if (null != word0) { + userHistoryDictionary.addBigramDynamically(word0, word1, frequency, timestamp); + } + } } |