mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Pass prevWordCount to native code for getSuggestion.
Bug: 14425059 Change-Id: Id2b49a448982c997e5c0a22445b115e675156c3e
This commit is contained in:
parent
cdabc71c6d
commit
8806248386
@ -186,9 +186,9 @@ public final class BinaryDictionary extends Dictionary {
|
||||
long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times,
|
||||
int[] pointerIds, int[] inputCodePoints, int inputSize, int[] suggestOptions,
|
||||
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
|
||||
int[] outputSuggestionCount, int[] outputCodePoints, int[] outputScores,
|
||||
int[] outputIndices, int[] outputTypes, int[] outputAutoCommitFirstWordConfidence,
|
||||
float[] inOutLanguageWeight);
|
||||
int prevWordCount, int[] outputSuggestionCount, int[] outputCodePoints,
|
||||
int[] outputScores, int[] outputIndices, int[] outputTypes,
|
||||
int[] outputAutoCommitFirstWordConfidence, float[] inOutLanguageWeight);
|
||||
private static native boolean addUnigramEntryNative(long dict, int[] word, int probability,
|
||||
int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence,
|
||||
boolean isNotAWord, boolean isBlacklisted, int timestamp);
|
||||
@ -295,10 +295,10 @@ public final class BinaryDictionary extends Dictionary {
|
||||
inputPointers.getYCoordinates(), inputPointers.getTimes(),
|
||||
inputPointers.getPointerIds(), session.mInputCodePoints, inputSize,
|
||||
session.mNativeSuggestOptions.getOptions(), session.mPrevWordCodePointArrays,
|
||||
session.mIsBeginningOfSentenceArray, session.mOutputSuggestionCount,
|
||||
session.mOutputCodePoints, session.mOutputScores, session.mSpaceIndices,
|
||||
session.mOutputTypes, session.mOutputAutoCommitFirstWordConfidence,
|
||||
session.mInputOutputLanguageWeight);
|
||||
session.mIsBeginningOfSentenceArray, prevWordsInfo.getPrevWordCount(),
|
||||
session.mOutputSuggestionCount, session.mOutputCodePoints, session.mOutputScores,
|
||||
session.mSpaceIndices, session.mOutputTypes,
|
||||
session.mOutputAutoCommitFirstWordConfidence, session.mInputOutputLanguageWeight);
|
||||
if (inOutLanguageWeight != null) {
|
||||
inOutLanguageWeight[0] = session.mInputOutputLanguageWeight[0];
|
||||
}
|
||||
|
@ -180,8 +180,8 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
|
||||
jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray,
|
||||
jintArray inputCodePointsArray, jint inputSize, jintArray suggestOptions,
|
||||
jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray,
|
||||
jintArray outSuggestionCount, jintArray outCodePointsArray, jintArray outScoresArray,
|
||||
jintArray outSpaceIndicesArray, jintArray outTypesArray,
|
||||
jint prevWordCount, jintArray outSuggestionCount, jintArray outCodePointsArray,
|
||||
jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outTypesArray,
|
||||
jintArray outAutoCommitFirstWordConfidenceArray, jfloatArray inOutLanguageWeight) {
|
||||
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||
// Assign 0 to outSuggestionCount here in case of returning earlier in this method.
|
||||
@ -241,7 +241,7 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
|
||||
env->GetFloatArrayRegion(inOutLanguageWeight, 0, 1 /* len */, &languageWeight);
|
||||
SuggestionResults suggestionResults(MAX_RESULTS);
|
||||
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray);
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray, prevWordCount);
|
||||
if (givenSuggestOptions.isGesture() || inputSize > 0) {
|
||||
// TODO: Use SuggestionResults to return suggestions.
|
||||
dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
||||
@ -285,7 +285,8 @@ static jint latinime_BinaryDictionary_getNgramProbability(JNIEnv *env, jclass cl
|
||||
int wordCodePoints[wordLength];
|
||||
env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
|
||||
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray);
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray,
|
||||
env->GetArrayLength(prevWordCodePointArrays));
|
||||
return dictionary->getNgramProbability(&prevWordsInfo,
|
||||
CodePointArrayView(wordCodePoints, wordLength));
|
||||
}
|
||||
@ -393,7 +394,8 @@ static bool latinime_BinaryDictionary_addNgramEntry(JNIEnv *env, jclass clazz, j
|
||||
return false;
|
||||
}
|
||||
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray);
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray,
|
||||
env->GetArrayLength(prevWordCodePointArrays));
|
||||
jsize wordLength = env->GetArrayLength(word);
|
||||
int wordCodePoints[wordLength];
|
||||
env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
|
||||
@ -413,7 +415,8 @@ static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz
|
||||
return false;
|
||||
}
|
||||
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray);
|
||||
prevWordCodePointArrays, isBeginningOfSentenceArray,
|
||||
env->GetArrayLength(prevWordCodePointArrays));
|
||||
jsize codePointCount = env->GetArrayLength(word);
|
||||
int wordCodePoints[codePointCount];
|
||||
env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
|
||||
@ -667,7 +670,7 @@ static const JNINativeMethod sMethods[] = {
|
||||
},
|
||||
{
|
||||
const_cast<char *>("getSuggestionsNative"),
|
||||
const_cast<char *>("(JJJ[I[I[I[I[II[I[[I[Z[I[I[I[I[I[I[F)V"),
|
||||
const_cast<char *>("(JJJ[I[I[I[I[II[I[[I[ZI[I[I[I[I[I[I[F)V"),
|
||||
reinterpret_cast<void *>(latinime_BinaryDictionary_getSuggestions)
|
||||
},
|
||||
{
|
||||
|
@ -97,17 +97,13 @@ class JniDataUtils {
|
||||
}
|
||||
|
||||
static PrevWordsInfo constructPrevWordsInfo(JNIEnv *env, jobjectArray prevWordCodePointArrays,
|
||||
jbooleanArray isBeginningOfSentenceArray) {
|
||||
jbooleanArray isBeginningOfSentenceArray, const size_t prevWordCount) {
|
||||
int prevWordCodePoints[MAX_PREV_WORD_COUNT_FOR_N_GRAM][MAX_WORD_LENGTH];
|
||||
int prevWordCodePointCount[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
|
||||
bool isBeginningOfSentence[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
|
||||
jsize prevWordsCount = env->GetArrayLength(prevWordCodePointArrays);
|
||||
for (size_t i = 0; i < NELEMS(prevWordCodePoints); ++i) {
|
||||
for (size_t i = 0; i < prevWordCount; ++i) {
|
||||
prevWordCodePointCount[i] = 0;
|
||||
isBeginningOfSentence[i] = false;
|
||||
if (prevWordsCount <= static_cast<int>(i)) {
|
||||
continue;
|
||||
}
|
||||
jintArray prevWord = (jintArray)env->GetObjectArrayElement(prevWordCodePointArrays, i);
|
||||
if (!prevWord) {
|
||||
continue;
|
||||
@ -124,7 +120,7 @@ class JniDataUtils {
|
||||
isBeginningOfSentence[i] = isBeginningOfSentenceBoolean == JNI_TRUE;
|
||||
}
|
||||
return PrevWordsInfo(prevWordCodePoints, prevWordCodePointCount, isBeginningOfSentence,
|
||||
MAX_PREV_WORD_COUNT_FOR_N_GRAM);
|
||||
prevWordCount);
|
||||
}
|
||||
|
||||
static void putBooleanToArray(JNIEnv *env, jbooleanArray array, const int index,
|
||||
|
Loading…
Reference in New Issue
Block a user