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/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/dictionary/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index a1f410d..c9e158c 100644
--- a/dictionary/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/dictionary/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -42,7 +42,7 @@
//
// helper function to throw an exception
//
-static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data)
+static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data)
{
if (jclass cls = env->FindClass(ex)) {
char msg[1000];
@@ -66,7 +66,7 @@
Asset *dictAsset = am->openNonAsset(resourcePath, Asset::ACCESS_BUFFER);
if (dictAsset == NULL) {
- LOGE("DICT: Couldn't get asset %s\n", resourcePath);
+ LOGE("DICT: Couldn't get asset %s\n", resourcePath);
env->ReleaseStringUTFChars(resourceString, resourcePath);
return 0;
}
@@ -79,15 +79,15 @@
}
Dictionary *dictionary = new Dictionary(dict, typedLetterMultiplier, fullWordMultiplier);
dictionary->setAsset(dictAsset);
-
+
env->ReleaseStringUTFChars(resourceString, resourcePath);
- return (jint) dictionary;
+ return (jint) dictionary;
}
static int latinime_BinaryDictionary_getSuggestions(
- JNIEnv *env, jobject object, jint dict, jintArray inputArray, jint arraySize,
- jcharArray outputArray, jintArray frequencyArray, jint maxWordLength, jint maxWords,
- jint maxAlternatives)
+ JNIEnv *env, jobject object, jint dict, jintArray inputArray, jint arraySize,
+ jcharArray outputArray, jintArray frequencyArray, jint maxWordLength, jint maxWords,
+ jint maxAlternatives, jint skipPos)
{
Dictionary *dictionary = (Dictionary*) dict;
if (dictionary == NULL)
@@ -96,9 +96,9 @@
int *frequencies = env->GetIntArrayElements(frequencyArray, NULL);
int *inputCodes = env->GetIntArrayElements(inputArray, NULL);
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
-
+
int count = dictionary->getSuggestions(inputCodes, arraySize, (unsigned short*) outputChars, frequencies,
- maxWordLength, maxWords, maxAlternatives);
+ maxWordLength, maxWords, maxAlternatives, skipPos);
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
@@ -112,16 +112,16 @@
{
Dictionary *dictionary = (Dictionary*) dict;
if (dictionary == NULL) return (jboolean) false;
-
+
jchar *word = env->GetCharArrayElements(wordArray, NULL);
jboolean result = dictionary->isValidWord((unsigned short*) word, wordLength);
env->ReleaseCharArrayElements(wordArray, word, JNI_ABORT);
-
+
return result;
}
static void latinime_BinaryDictionary_close
- (JNIEnv *env, jobject object, jint dict)
+ (JNIEnv *env, jobject object, jint dict)
{
Dictionary *dictionary = (Dictionary*) dict;
((Asset*) dictionary->getAsset())->close();
@@ -131,10 +131,10 @@
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
- {"openNative", "(Landroid/content/res/AssetManager;Ljava/lang/String;II)I",
+ {"openNative", "(Landroid/content/res/AssetManager;Ljava/lang/String;II)I",
(void*)latinime_BinaryDictionary_open},
{"closeNative", "(I)V", (void*)latinime_BinaryDictionary_close},
- {"getSuggestionsNative", "(I[II[C[IIII)I", (void*)latinime_BinaryDictionary_getSuggestions},
+ {"getSuggestionsNative", "(I[II[C[IIIII)I", (void*)latinime_BinaryDictionary_getSuggestions},
{"isValidWordNative", "(I[CI)Z", (void*)latinime_BinaryDictionary_isValidWord}
};
@@ -153,7 +153,7 @@
fprintf(stderr, "RegisterNatives failed for '%s'\n", className);
return JNI_FALSE;
}
-
+
return JNI_TRUE;
}
@@ -161,21 +161,21 @@
{
const char* const kClassPathName = "com/android/inputmethod/latin/BinaryDictionary";
jclass clazz;
-
+
clazz = env->FindClass("java/io/FileDescriptor");
if (clazz == NULL) {
LOGE("Can't find %s", "java/io/FileDescriptor");
return -1;
}
sDescriptorField = env->GetFieldID(clazz, "descriptor", "I");
-
+
clazz = env->FindClass("android/content/res/AssetManager");
if (clazz == NULL) {
LOGE("Can't find %s", "java/io/FileDescriptor");
return -1;
}
sAssetManagerNativeField = env->GetFieldID(clazz, "mObject", "I");
-
+
return registerNativeMethods(env,
kClassPathName, gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
}
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;