aboutsummaryrefslogtreecommitdiffstats
path: root/dictionary/src/dictionary.cpp
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2010-02-05 14:07:04 -0800
committerAmith Yamasani <yamasani@google.com>2010-02-08 15:22:37 -0800
commit1b62ff1a3d61cd44ab88acdfcbdf0fc70a7e1b10 (patch)
tree17739a10acf4f7f9e70b82ba4d0a2f1c17c914b4 /dictionary/src/dictionary.cpp
parent8fa317a61a2152347c59dda7eb1b8e2979f6cc1d (diff)
downloadlatinime-1b62ff1a3d61cd44ab88acdfcbdf0fc70a7e1b10.tar.gz
latinime-1b62ff1a3d61cd44ab88acdfcbdf0fc70a7e1b10.tar.xz
latinime-1b62ff1a3d61cd44ab88acdfcbdf0fc70a7e1b10.zip
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.
Diffstat (limited to 'dictionary/src/dictionary.cpp')
-rw-r--r--dictionary/src/dictionary.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/dictionary/src/dictionary.cpp b/dictionary/src/dictionary.cpp
index 306aff527..6e6f44182 100644
--- a/dictionary/src/dictionary.cpp
+++ b/dictionary/src/dictionary.cpp
@@ -49,7 +49,8 @@ Dictionary::~Dictionary()
}
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 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
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 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
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 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
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,