Loading java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java +10 −1 Original line number Diff line number Diff line Loading @@ -41,8 +41,17 @@ abstract public class AbstractDictionaryWriter extends Dictionary { abstract public void clear(); /** * Add a unigram with an optional shortcut to the dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param isNotAWord true if this is not a word, i.e. shortcut only. */ abstract public void addUnigramWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord); final int frequency, final int shortcutFreq, final boolean isNotAWord); // TODO: Remove lastModifiedTime after making binary dictionary support forgetting curve. abstract public void addBigramWords(final String word0, final String word1, Loading java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +2 −2 Original line number Diff line number Diff line Loading @@ -127,7 +127,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { if (DEBUG) { Log.d(TAG, "loadAccountVocabulary: " + word); } super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, 0 /* shortcutFreq */, false /* isNotAWord */); } } Loading Loading @@ -213,7 +213,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { Log.d(TAG, "addName " + name + ", " + word + ", " + prevWord); } super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, false /* isNotAWord */); 0 /* shortcutFreq */, false /* isNotAWord */); if (!TextUtils.isEmpty(prevWord)) { if (mUseFirstLastBigrams) { super.addBigram(prevWord, word, FREQUENCY_FOR_CONTACTS_BIGRAM, Loading java/src/com/android/inputmethod/latin/DictionaryWriter.java +2 −2 Original line number Diff line number Diff line Loading @@ -62,13 +62,13 @@ public class DictionaryWriter extends AbstractDictionaryWriter { // considering performance regression. @Override public void addUnigramWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { final int shortcutFreq, final boolean isNotAWord) { if (shortcutTarget == null) { mFusionDictionary.add(word, frequency, null, isNotAWord); } else { // TODO: Do this in the subclass, with this class taking an arraylist. final ArrayList<WeightedString> shortcutTargets = CollectionUtils.newArrayList(); shortcutTargets.add(new WeightedString(shortcutTarget, frequency)); shortcutTargets.add(new WeightedString(shortcutTarget, shortcutFreq)); mFusionDictionary.add(word, frequency, shortcutTargets, isNotAWord); } } Loading java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +11 −4 Original line number Diff line number Diff line Loading @@ -261,10 +261,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { /** * Adds a word unigram to the dictionary. Used for loading a dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param isNotAWord true if this is not a word, i.e. shortcut only. */ protected void addWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord); final int frequency, final int shortcutFreq, final boolean isNotAWord) { mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, shortcutFreq, isNotAWord); } /** Loading Loading @@ -313,7 +319,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { * Dynamically adds a word unigram to the dictionary. May overwrite an existing entry. */ protected void addWordDynamically(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { final int frequency, final int shortcutFreq, final boolean isNotAWord) { if (!mIsUpdatable) { Log.w(TAG, "addWordDynamically is called for non-updatable dictionary: " + mFilename); return; Loading @@ -326,7 +332,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mBinaryDictionary.addUnigramWord(word, frequency); } else { // TODO: Remove. mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord); mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, shortcutFreq, isNotAWord); } } }); Loading java/src/com/android/inputmethod/latin/ExpandableDictionary.java +26 −4 Original line number Diff line number Diff line Loading @@ -156,15 +156,36 @@ public class ExpandableDictionary extends Dictionary { return Constants.DICTIONARY_MAX_WORD_LENGTH; } public void addWord(final String word, final String shortcutTarget, final int frequency) { /** * Add a word with an optional shortcut to the dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. */ public void addWord(final String word, final String shortcutTarget, final int frequency, final int shortcutFreq) { if (word.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH) { return; } addWordRec(mRoots, word, 0, shortcutTarget, frequency, null); addWordRec(mRoots, word, 0, shortcutTarget, frequency, shortcutFreq, null); } /** * Add a word, recursively searching for its correct place in the trie tree. * @param children The node to recursively search for addition. Initially, the root of the tree. * @param word The word to add. * @param depth The current depth in the tree. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param parentNode The parent node, for up linking. Initially null, as the root has no parent. */ private void addWordRec(final NodeArray children, final String word, final int depth, final String shortcutTarget, final int frequency, final Node parentNode) { final String shortcutTarget, final int frequency, final int shortcutFreq, final Node parentNode) { final int wordLength = word.length(); if (wordLength <= depth) return; final char c = word.charAt(depth); Loading Loading @@ -204,7 +225,8 @@ public class ExpandableDictionary extends Dictionary { if (childNode.mChildren == null) { childNode.mChildren = new NodeArray(); } addWordRec(childNode.mChildren, word, depth + 1, shortcutTarget, frequency, childNode); addWordRec(childNode.mChildren, word, depth + 1, shortcutTarget, frequency, shortcutFreq, childNode); } @Override Loading Loading
java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java +10 −1 Original line number Diff line number Diff line Loading @@ -41,8 +41,17 @@ abstract public class AbstractDictionaryWriter extends Dictionary { abstract public void clear(); /** * Add a unigram with an optional shortcut to the dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param isNotAWord true if this is not a word, i.e. shortcut only. */ abstract public void addUnigramWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord); final int frequency, final int shortcutFreq, final boolean isNotAWord); // TODO: Remove lastModifiedTime after making binary dictionary support forgetting curve. abstract public void addBigramWords(final String word0, final String word1, Loading
java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +2 −2 Original line number Diff line number Diff line Loading @@ -127,7 +127,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { if (DEBUG) { Log.d(TAG, "loadAccountVocabulary: " + word); } super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, 0 /* shortcutFreq */, false /* isNotAWord */); } } Loading Loading @@ -213,7 +213,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { Log.d(TAG, "addName " + name + ", " + word + ", " + prevWord); } super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS, false /* isNotAWord */); 0 /* shortcutFreq */, false /* isNotAWord */); if (!TextUtils.isEmpty(prevWord)) { if (mUseFirstLastBigrams) { super.addBigram(prevWord, word, FREQUENCY_FOR_CONTACTS_BIGRAM, Loading
java/src/com/android/inputmethod/latin/DictionaryWriter.java +2 −2 Original line number Diff line number Diff line Loading @@ -62,13 +62,13 @@ public class DictionaryWriter extends AbstractDictionaryWriter { // considering performance regression. @Override public void addUnigramWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { final int shortcutFreq, final boolean isNotAWord) { if (shortcutTarget == null) { mFusionDictionary.add(word, frequency, null, isNotAWord); } else { // TODO: Do this in the subclass, with this class taking an arraylist. final ArrayList<WeightedString> shortcutTargets = CollectionUtils.newArrayList(); shortcutTargets.add(new WeightedString(shortcutTarget, frequency)); shortcutTargets.add(new WeightedString(shortcutTarget, shortcutFreq)); mFusionDictionary.add(word, frequency, shortcutTargets, isNotAWord); } } Loading
java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +11 −4 Original line number Diff line number Diff line Loading @@ -261,10 +261,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { /** * Adds a word unigram to the dictionary. Used for loading a dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param isNotAWord true if this is not a word, i.e. shortcut only. */ protected void addWord(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord); final int frequency, final int shortcutFreq, final boolean isNotAWord) { mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, shortcutFreq, isNotAWord); } /** Loading Loading @@ -313,7 +319,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { * Dynamically adds a word unigram to the dictionary. May overwrite an existing entry. */ protected void addWordDynamically(final String word, final String shortcutTarget, final int frequency, final boolean isNotAWord) { final int frequency, final int shortcutFreq, final boolean isNotAWord) { if (!mIsUpdatable) { Log.w(TAG, "addWordDynamically is called for non-updatable dictionary: " + mFilename); return; Loading @@ -326,7 +332,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mBinaryDictionary.addUnigramWord(word, frequency); } else { // TODO: Remove. mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord); mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, shortcutFreq, isNotAWord); } } }); Loading
java/src/com/android/inputmethod/latin/ExpandableDictionary.java +26 −4 Original line number Diff line number Diff line Loading @@ -156,15 +156,36 @@ public class ExpandableDictionary extends Dictionary { return Constants.DICTIONARY_MAX_WORD_LENGTH; } public void addWord(final String word, final String shortcutTarget, final int frequency) { /** * Add a word with an optional shortcut to the dictionary. * @param word The word to add. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. */ public void addWord(final String word, final String shortcutTarget, final int frequency, final int shortcutFreq) { if (word.length() >= Constants.DICTIONARY_MAX_WORD_LENGTH) { return; } addWordRec(mRoots, word, 0, shortcutTarget, frequency, null); addWordRec(mRoots, word, 0, shortcutTarget, frequency, shortcutFreq, null); } /** * Add a word, recursively searching for its correct place in the trie tree. * @param children The node to recursively search for addition. Initially, the root of the tree. * @param word The word to add. * @param depth The current depth in the tree. * @param shortcutTarget A shortcut target for this word, or null if none. * @param frequency The frequency for this unigram. * @param shortcutFreq The frequency of the shortcut (0~15, with 15 = whitelist). Ignored * if shortcutTarget is null. * @param parentNode The parent node, for up linking. Initially null, as the root has no parent. */ private void addWordRec(final NodeArray children, final String word, final int depth, final String shortcutTarget, final int frequency, final Node parentNode) { final String shortcutTarget, final int frequency, final int shortcutFreq, final Node parentNode) { final int wordLength = word.length(); if (wordLength <= depth) return; final char c = word.charAt(depth); Loading Loading @@ -204,7 +225,8 @@ public class ExpandableDictionary extends Dictionary { if (childNode.mChildren == null) { childNode.mChildren = new NodeArray(); } addWordRec(childNode.mChildren, word, depth + 1, shortcutTarget, frequency, childNode); addWordRec(childNode.mChildren, word, depth + 1, shortcutTarget, frequency, shortcutFreq, childNode); } @Override Loading