aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-05-20 13:37:04 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-05-20 13:37:04 +0900
commitff50b39176370ab80a33bfdcf9979603c08a88b3 (patch)
tree39aeb698d9011ce97e4632acb6434984ded4864c /java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
parentd7bef2bee16b6e529d55b505764a79821fe3c825 (diff)
downloadlatinime-ff50b39176370ab80a33bfdcf9979603c08a88b3.tar.gz
latinime-ff50b39176370ab80a33bfdcf9979603c08a88b3.tar.xz
latinime-ff50b39176370ab80a33bfdcf9979603c08a88b3.zip
Use PrevWordsInfo for get/add/remove n-gram(bigram) entry.
Bug: 14119293 Bug: 14425059 Change-Id: I12e9ba977c153b514c6591ab52940712fd0874e3
Diffstat (limited to 'java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java28
1 files changed, 16 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
index 818cd9a5f..f89caf921 100644
--- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
@@ -22,6 +22,7 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
+import com.android.inputmethod.latin.PrevWordsInfo;
import java.io.File;
import java.util.Locale;
@@ -52,29 +53,32 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
}
/**
- * Pair will be added to the user history dictionary.
+ * Add a word 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).
+ * @param userHistoryDictionary the user history dictionary
+ * @param prevWordsInfo the information of previous words
+ * @param word the word the user inputted
+ * @param isValid whether the word is valid or not
+ * @param timestamp the timestamp when the word has been inputted
*/
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)) {
+ final PrevWordsInfo prevWordsInfo, final String word, final boolean isValid,
+ final int timestamp) {
+ final String prevWord = prevWordsInfo.mPrevWord;
+ if (word.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH ||
+ (prevWord != null && prevWord.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 */,
+ userHistoryDictionary.addUnigramEntry(word, frequency, null /* shortcutTarget */,
0 /* shortcutFreq */, false /* isNotAWord */, false /* isBlacklisted */, timestamp);
// Do not insert a word as a bigram of itself
- if (word1.equals(word0)) {
+ if (word.equals(prevWord)) {
return;
}
- if (null != word0) {
- userHistoryDictionary.addBigramDynamically(word0, word1, frequency, timestamp);
+ if (null != prevWord) {
+ userHistoryDictionary.addNgramEntry(prevWordsInfo, word, frequency, timestamp);
}
}
}