Correction algorithm to check for missing single characters.
Searches for alternative words by trying wild-card characters at different
character positions.
diff --git a/dictionary/src/dictionary.cpp b/dictionary/src/dictionary.cpp
index b37f4c9..6fe7f4a 100644
--- a/dictionary/src/dictionary.cpp
+++ b/dictionary/src/dictionary.cpp
@@ -49,11 +49,8 @@
}
int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
- int maxWordLength, int maxWords, int maxAlternatives)
+ int maxWordLength, int maxWords, int maxAlternatives, int skipPos)
{
- memset(frequencies, 0, maxWords * sizeof(*frequencies));
- memset(outWords, 0, maxWords * maxWordLength * sizeof(*outWords));
-
mFrequencies = frequencies;
mOutputChars = outWords;
mInputCodes = codes;
@@ -62,6 +59,7 @@
mMaxWordLength = maxWordLength;
mMaxWords = maxWords;
mWords = 0;
+ mSkipPos = skipPos;
getWordsRec(0, 0, mInputLength * 3, false, 1, 0);
@@ -209,9 +207,9 @@
getWordsRec(childrenAddress, depth + 1, maxDepth,
completion, snr, inputIndex);
}
- } else if (c == QUOTE && currentChars[0] != QUOTE) {
- // Skip the ' and continue deeper
- mWord[depth] = QUOTE;
+ } else if (c == QUOTE && currentChars[0] != QUOTE || mSkipPos == depth) {
+ // Skip the ' or other letter and continue deeper
+ mWord[depth] = c;
if (childrenAddress != 0) {
getWordsRec(childrenAddress, depth + 1, maxDepth, false, snr, inputIndex);
}
@@ -239,6 +237,7 @@
}
}
j++;
+ if (mSkipPos >= 0) break;
}
}
}
diff --git a/dictionary/src/dictionary.h b/dictionary/src/dictionary.h
index b13e977..70dfa73 100644
--- a/dictionary/src/dictionary.h
+++ b/dictionary/src/dictionary.h
@@ -32,7 +32,7 @@
public:
Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
- int maxWordLength, int maxWords, int maxAlternatives);
+ int maxWordLength, int maxWords, int maxAlternatives, int skipPos);
bool isValidWord(unsigned short *word, int length);
void setAsset(void *asset) { mAsset = asset; }
void *getAsset() { return mAsset; }
@@ -66,6 +66,7 @@
int mInputLength;
int mMaxAlternatives;
unsigned short mWord[128];
+ int mSkipPos;
int mFullWordMultiplier;
int mTypedLetterMultiplier;