Correction algorithm to check for missing single characters.
Searches for alternative words by trying wild-card characters at different character positions.main
parent
5a323e65d0
commit
c3df2d6fd2
|
@ -87,7 +87,7 @@ static jint latinime_BinaryDictionary_open
|
||||||
static int latinime_BinaryDictionary_getSuggestions(
|
static int latinime_BinaryDictionary_getSuggestions(
|
||||||
JNIEnv *env, jobject object, jint dict, jintArray inputArray, jint arraySize,
|
JNIEnv *env, jobject object, jint dict, jintArray inputArray, jint arraySize,
|
||||||
jcharArray outputArray, jintArray frequencyArray, jint maxWordLength, jint maxWords,
|
jcharArray outputArray, jintArray frequencyArray, jint maxWordLength, jint maxWords,
|
||||||
jint maxAlternatives)
|
jint maxAlternatives, jint skipPos)
|
||||||
{
|
{
|
||||||
Dictionary *dictionary = (Dictionary*) dict;
|
Dictionary *dictionary = (Dictionary*) dict;
|
||||||
if (dictionary == NULL)
|
if (dictionary == NULL)
|
||||||
|
@ -98,7 +98,7 @@ static int latinime_BinaryDictionary_getSuggestions(
|
||||||
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
|
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
|
||||||
|
|
||||||
int count = dictionary->getSuggestions(inputCodes, arraySize, (unsigned short*) outputChars, frequencies,
|
int count = dictionary->getSuggestions(inputCodes, arraySize, (unsigned short*) outputChars, frequencies,
|
||||||
maxWordLength, maxWords, maxAlternatives);
|
maxWordLength, maxWords, maxAlternatives, skipPos);
|
||||||
|
|
||||||
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
|
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
|
||||||
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
|
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
|
||||||
|
@ -134,7 +134,7 @@ 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},
|
(void*)latinime_BinaryDictionary_open},
|
||||||
{"closeNative", "(I)V", (void*)latinime_BinaryDictionary_close},
|
{"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}
|
{"isValidWordNative", "(I[CI)Z", (void*)latinime_BinaryDictionary_isValidWord}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,8 @@ Dictionary::~Dictionary()
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
|
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;
|
mFrequencies = frequencies;
|
||||||
mOutputChars = outWords;
|
mOutputChars = outWords;
|
||||||
mInputCodes = codes;
|
mInputCodes = codes;
|
||||||
|
@ -62,6 +59,7 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
|
||||||
mMaxWordLength = maxWordLength;
|
mMaxWordLength = maxWordLength;
|
||||||
mMaxWords = maxWords;
|
mMaxWords = maxWords;
|
||||||
mWords = 0;
|
mWords = 0;
|
||||||
|
mSkipPos = skipPos;
|
||||||
|
|
||||||
getWordsRec(0, 0, mInputLength * 3, false, 1, 0);
|
getWordsRec(0, 0, mInputLength * 3, false, 1, 0);
|
||||||
|
|
||||||
|
@ -209,9 +207,9 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
|
||||||
getWordsRec(childrenAddress, depth + 1, maxDepth,
|
getWordsRec(childrenAddress, depth + 1, maxDepth,
|
||||||
completion, snr, inputIndex);
|
completion, snr, inputIndex);
|
||||||
}
|
}
|
||||||
} else if (c == QUOTE && currentChars[0] != QUOTE) {
|
} else if (c == QUOTE && currentChars[0] != QUOTE || mSkipPos == depth) {
|
||||||
// Skip the ' and continue deeper
|
// Skip the ' or other letter and continue deeper
|
||||||
mWord[depth] = QUOTE;
|
mWord[depth] = c;
|
||||||
if (childrenAddress != 0) {
|
if (childrenAddress != 0) {
|
||||||
getWordsRec(childrenAddress, depth + 1, maxDepth, false, snr, inputIndex);
|
getWordsRec(childrenAddress, depth + 1, maxDepth, false, snr, inputIndex);
|
||||||
}
|
}
|
||||||
|
@ -239,6 +237,7 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
|
if (mSkipPos >= 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Dictionary {
|
||||||
public:
|
public:
|
||||||
Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
|
Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
|
||||||
int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
|
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);
|
bool isValidWord(unsigned short *word, int length);
|
||||||
void setAsset(void *asset) { mAsset = asset; }
|
void setAsset(void *asset) { mAsset = asset; }
|
||||||
void *getAsset() { return mAsset; }
|
void *getAsset() { return mAsset; }
|
||||||
|
@ -66,6 +66,7 @@ private:
|
||||||
int mInputLength;
|
int mInputLength;
|
||||||
int mMaxAlternatives;
|
int mMaxAlternatives;
|
||||||
unsigned short mWord[128];
|
unsigned short mWord[128];
|
||||||
|
int mSkipPos;
|
||||||
|
|
||||||
int mFullWordMultiplier;
|
int mFullWordMultiplier;
|
||||||
int mTypedLetterMultiplier;
|
int mTypedLetterMultiplier;
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class BinaryDictionary extends Dictionary {
|
||||||
private static final int MAX_WORDS = 16;
|
private static final int MAX_WORDS = 16;
|
||||||
|
|
||||||
private static final int TYPED_LETTER_MULTIPLIER = 2;
|
private static final int TYPED_LETTER_MULTIPLIER = 2;
|
||||||
|
private static final boolean ENABLE_MISSED_CHARACTERS = true;
|
||||||
|
|
||||||
private int mNativeDict;
|
private int mNativeDict;
|
||||||
private int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_ALTERNATIVES];
|
private int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_ALTERNATIVES];
|
||||||
|
@ -64,7 +65,7 @@ public class BinaryDictionary extends Dictionary {
|
||||||
private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
|
private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
|
||||||
private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
|
private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
|
||||||
char[] outputChars, int[] frequencies,
|
char[] outputChars, int[] frequencies,
|
||||||
int maxWordLength, int maxWords, int maxAlternatives);
|
int maxWordLength, int maxWords, int maxAlternatives, int skipPos);
|
||||||
private native void setParamsNative(int typedLetterMultiplier,
|
private native void setParamsNative(int typedLetterMultiplier,
|
||||||
int fullWordMultiplier);
|
int fullWordMultiplier);
|
||||||
|
|
||||||
|
@ -88,9 +89,24 @@ public class BinaryDictionary extends Dictionary {
|
||||||
Math.min(alternatives.length, MAX_ALTERNATIVES));
|
Math.min(alternatives.length, MAX_ALTERNATIVES));
|
||||||
}
|
}
|
||||||
Arrays.fill(mOutputChars, (char) 0);
|
Arrays.fill(mOutputChars, (char) 0);
|
||||||
|
Arrays.fill(mFrequencies, 0);
|
||||||
|
|
||||||
int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize, mOutputChars, mFrequencies,
|
int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize,
|
||||||
MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
|
mOutputChars, mFrequencies,
|
||||||
|
MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES, -1);
|
||||||
|
|
||||||
|
// If there aren't sufficient suggestions, search for words by allowing wild cards at
|
||||||
|
// the different character positions. This feature is not ready for prime-time as we need
|
||||||
|
// to figure out the best ranking for such words compared to proximity corrections and
|
||||||
|
// completions.
|
||||||
|
if (ENABLE_MISSED_CHARACTERS && count < 5) {
|
||||||
|
for (int skip = 0; skip < codesSize; skip++) {
|
||||||
|
count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize,
|
||||||
|
mOutputChars, mFrequencies,
|
||||||
|
MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES, skip);
|
||||||
|
if (count > 0) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < count; j++) {
|
for (int j = 0; j < count; j++) {
|
||||||
if (mFrequencies[j] < 1) break;
|
if (mFrequencies[j] < 1) break;
|
||||||
|
|
Loading…
Reference in New Issue