Increase target size of preferred letters while typing.
This increases the chance of hitting the correct letter when typing a word
that exists in the dictionary, rather than only correct it after the fact.
It is most effective after 2 or 3 letters of a word have been typed and gets
more accurate with more typed letters in the word.
If 2 adjacent letters have similar probabilities of occuring, then there is no
hit correction applied.
diff --git a/dictionary/src/dictionary.cpp b/dictionary/src/dictionary.cpp
index 306aff5..6e6f441 100644
--- a/dictionary/src/dictionary.cpp
+++ b/dictionary/src/dictionary.cpp
@@ -49,7 +49,8 @@
}
int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
- int maxWordLength, int maxWords, int maxAlternatives, int skipPos)
+ int maxWordLength, int maxWords, int maxAlternatives, int skipPos,
+ int *nextLetters, int nextLettersSize)
{
int suggWords;
mFrequencies = frequencies;
@@ -61,6 +62,8 @@
mMaxWords = maxWords;
mSkipPos = skipPos;
mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2;
+ mNextLettersFrequencies = nextLetters;
+ mNextLettersSize = nextLettersSize;
getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0);
@@ -68,9 +71,27 @@
suggWords = 0;
while (suggWords < mMaxWords && mFrequencies[suggWords] > 0) suggWords++;
if (DEBUG_DICT) LOGI("Returning %d words", suggWords);
+
+ if (DEBUG_DICT) {
+ LOGI("Next letters: ");
+ for (int k = 0; k < nextLettersSize; k++) {
+ if (mNextLettersFrequencies[k] > 0) {
+ LOGI("%c = %d,", k, mNextLettersFrequencies[k]);
+ }
+ }
+ LOGI("\n");
+ }
return suggWords;
}
+void
+Dictionary::registerNextLetter(unsigned short c)
+{
+ if (c < mNextLettersSize) {
+ mNextLettersFrequencies[c]++;
+ }
+}
+
unsigned short
Dictionary::getChar(int *pos)
{
@@ -210,6 +231,9 @@
mWord[depth] = c;
if (terminal) {
addWord(mWord, depth + 1, freq * snr);
+ if (depth >= mInputLength && mSkipPos < 0) {
+ registerNextLetter(mWord[mInputLength]);
+ }
}
if (childrenAddress != 0) {
getWordsRec(childrenAddress, depth + 1, maxDepth,