Merge "Reinforce user-history based bigram use."
This commit is contained in:
commit
a944574967
2 changed files with 15 additions and 18 deletions
|
@ -32,12 +32,14 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
*/
|
*/
|
||||||
protected static final int MAX_WORD_LENGTH = 32;
|
protected static final int MAX_WORD_LENGTH = 32;
|
||||||
|
|
||||||
|
// Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8.
|
||||||
|
protected static final int BIGRAM_MAX_FREQUENCY = 255;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private char[] mWordBuilder = new char[MAX_WORD_LENGTH];
|
private char[] mWordBuilder = new char[MAX_WORD_LENGTH];
|
||||||
private int mDicTypeId;
|
private int mDicTypeId;
|
||||||
private int mMaxDepth;
|
private int mMaxDepth;
|
||||||
private int mInputLength;
|
private int mInputLength;
|
||||||
private StringBuilder sb = new StringBuilder(MAX_WORD_LENGTH);
|
|
||||||
|
|
||||||
private static final char QUOTE = '\'';
|
private static final char QUOTE = '\'';
|
||||||
|
|
||||||
|
@ -98,6 +100,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
|
|
||||||
public int addFrequency(int add) {
|
public int addFrequency(int add) {
|
||||||
mFrequency += add;
|
mFrequency += add;
|
||||||
|
if (mFrequency > BIGRAM_MAX_FREQUENCY) mFrequency = BIGRAM_MAX_FREQUENCY;
|
||||||
return mFrequency;
|
return mFrequency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,6 +465,9 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Local to reverseLookUp, but do not allocate each time.
|
||||||
|
private final char[] mLookedUpString = new char[MAX_WORD_LENGTH];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reverseLookUp retrieves the full word given a list of terminal nodes and adds those words
|
* reverseLookUp retrieves the full word given a list of terminal nodes and adds those words
|
||||||
* through callback.
|
* through callback.
|
||||||
|
@ -474,20 +480,17 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
for (NextWord nextWord : terminalNodes) {
|
for (NextWord nextWord : terminalNodes) {
|
||||||
node = nextWord.mWord;
|
node = nextWord.mWord;
|
||||||
freq = nextWord.getFrequency();
|
freq = nextWord.getFrequency();
|
||||||
// TODO Not the best way to limit suggestion threshold
|
int index = MAX_WORD_LENGTH;
|
||||||
if (freq >= UserBigramDictionary.SUGGEST_THRESHOLD) {
|
|
||||||
sb.setLength(0);
|
|
||||||
do {
|
do {
|
||||||
sb.insert(0, node.mCode);
|
--index;
|
||||||
|
mLookedUpString[index] = node.mCode;
|
||||||
node = node.mParent;
|
node = node.mParent;
|
||||||
} while (node != null);
|
} while (node != null);
|
||||||
|
|
||||||
// TODO better way to feed char array?
|
callback.addWord(mLookedUpString, index, MAX_WORD_LENGTH - index, freq, mDicTypeId,
|
||||||
callback.addWord(sb.toString().toCharArray(), 0, sb.length(), freq, mDicTypeId,
|
|
||||||
DataType.BIGRAM);
|
DataType.BIGRAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for the terminal node of the word
|
* Search for the terminal node of the word
|
||||||
|
|
|
@ -44,12 +44,6 @@ public class UserBigramDictionary extends ExpandableDictionary {
|
||||||
/** Maximum frequency for all pairs */
|
/** Maximum frequency for all pairs */
|
||||||
private static final int FREQUENCY_MAX = 127;
|
private static final int FREQUENCY_MAX = 127;
|
||||||
|
|
||||||
/**
|
|
||||||
* If this pair is typed 6 times, it would be suggested.
|
|
||||||
* Should be smaller than ContactsDictionary.FREQUENCY_FOR_CONTACTS_BIGRAM
|
|
||||||
*/
|
|
||||||
protected static final int SUGGEST_THRESHOLD = 6 * FREQUENCY_FOR_TYPED;
|
|
||||||
|
|
||||||
/** Maximum number of pairs. Pruning will start when databases goes above this number. */
|
/** Maximum number of pairs. Pruning will start when databases goes above this number. */
|
||||||
private static int sMaxUserBigrams = 10000;
|
private static int sMaxUserBigrams = 10000;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue