Merge "Pass the previous word down to native code in getSuggestions"
This commit is contained in:
commit
bde232dcaa
3 changed files with 30 additions and 6 deletions
|
@ -85,8 +85,8 @@ public class BinaryDictionary extends Dictionary {
|
|||
private native void closeNative(long dict);
|
||||
private native boolean isValidWordNative(long dict, char[] word, int wordLength);
|
||||
private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates,
|
||||
int[] yCoordinates, int[] inputCodes, int codesSize, boolean useFullEditDistance,
|
||||
char[] outputChars, int[] scores);
|
||||
int[] yCoordinates, int[] inputCodes, int codesSize, int[] prevWordForBigrams,
|
||||
boolean useFullEditDistance, char[] outputChars, int[] scores);
|
||||
private native int getBigramsNative(long dict, char[] prevWord, int prevWordLength,
|
||||
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
|
||||
int maxWordLength, int maxBigrams);
|
||||
|
@ -177,11 +177,14 @@ public class BinaryDictionary extends Dictionary {
|
|||
Arrays.fill(outputChars, (char) 0);
|
||||
Arrays.fill(scores, 0);
|
||||
|
||||
final int[] prevWordCodePointArray = null == prevWordForBigrams
|
||||
? null : StringUtils.toCodePointArray(prevWordForBigrams.toString());
|
||||
|
||||
// TODO: pass the previous word to native code
|
||||
return getSuggestionsNative(
|
||||
mNativeDict, proximityInfo.getNativeProximityInfo(),
|
||||
codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
|
||||
mUseFullEditDistance, outputChars, scores);
|
||||
prevWordCodePointArray, mUseFullEditDistance, outputChars, scores);
|
||||
}
|
||||
|
||||
public static double calcNormalizedScore(String before, String after, int score) {
|
||||
|
|
|
@ -166,4 +166,19 @@ public class StringUtils {
|
|||
// - It also does not work with unicode surrogate code points.
|
||||
return s.toUpperCase(locale).charAt(0) + s.substring(1);
|
||||
}
|
||||
|
||||
public static int[] toCodePointArray(final String string) {
|
||||
final char[] characters = string.toCharArray();
|
||||
final int length = characters.length;
|
||||
final int[] codePoints = new int[Character.codePointCount(characters, 0, length)];
|
||||
int codePoint = Character.codePointAt(characters, 0);
|
||||
int dsti = 0;
|
||||
for (int srci = Character.charCount(codePoint);
|
||||
srci < length; srci += Character.charCount(codePoint), ++dsti) {
|
||||
codePoints[dsti] = codePoint;
|
||||
codePoint = Character.codePointAt(characters, srci);
|
||||
}
|
||||
codePoints[dsti] = codePoint;
|
||||
return codePoints;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,8 +127,8 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
|||
|
||||
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jlong dict,
|
||||
jlong proximityInfo, jintArray xCoordinatesArray, jintArray yCoordinatesArray,
|
||||
jintArray inputArray, jint arraySize, jboolean useFullEditDistance,
|
||||
jcharArray outputArray, jintArray frequencyArray) {
|
||||
jintArray inputArray, jint arraySize, jintArray prevWordForBigrams,
|
||||
jboolean useFullEditDistance, jcharArray outputArray, jintArray frequencyArray) {
|
||||
Dictionary *dictionary = (Dictionary*)dict;
|
||||
if (!dictionary) return 0;
|
||||
ProximityInfo *pInfo = (ProximityInfo*)proximityInfo;
|
||||
|
@ -137,6 +137,11 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
|
|||
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
|
||||
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
|
||||
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
||||
// Deactivated to prevent unused variable errors.
|
||||
// TODO: use the following variables.
|
||||
// jint *prevWordChars = prevWordForBigrams
|
||||
// ? env->GetIntArrayElements(prevWordForBigrams, 0) : NULL;
|
||||
// jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0;
|
||||
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
|
||||
arraySize, useFullEditDistance, (unsigned short*) outputChars, frequencies);
|
||||
env->ReleaseCharArrayElements(outputArray, outputChars, 0);
|
||||
|
@ -229,7 +234,8 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) {
|
|||
static JNINativeMethod sMethods[] = {
|
||||
{"openNative", "(Ljava/lang/String;JJIIII)J", (void*)latinime_BinaryDictionary_open},
|
||||
{"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close},
|
||||
{"getSuggestionsNative", "(JJ[I[I[IIZ[C[I)I", (void*)latinime_BinaryDictionary_getSuggestions},
|
||||
{"getSuggestionsNative", "(JJ[I[I[II[IZ[C[I)I",
|
||||
(void*)latinime_BinaryDictionary_getSuggestions},
|
||||
{"isValidWordNative", "(J[CI)Z", (void*)latinime_BinaryDictionary_isValidWord},
|
||||
{"getBigramsNative", "(J[CI[II[C[III)I", (void*)latinime_BinaryDictionary_getBigrams},
|
||||
{"calcNormalizedScoreNative", "([CI[CII)D",
|
||||
|
|
Loading…
Reference in a new issue