am 6624ea96: Merge "Pass prevWordCount to native code for getSuggestion."

* commit '6624ea96f763b083a1eb590411b31b6b2d04d058':
  Pass prevWordCount to native code for getSuggestion.
main
Keisuke Kuroyanagi 2014-09-18 13:11:19 +00:00 committed by Android Git Automerger
commit 2ad56c16e8
3 changed files with 20 additions and 21 deletions

View File

@ -186,9 +186,9 @@ public final class BinaryDictionary extends Dictionary {
long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times, long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times,
int[] pointerIds, int[] inputCodePoints, int inputSize, int[] suggestOptions, int[] pointerIds, int[] inputCodePoints, int inputSize, int[] suggestOptions,
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
int[] outputSuggestionCount, int[] outputCodePoints, int[] outputScores, int prevWordCount, int[] outputSuggestionCount, int[] outputCodePoints,
int[] outputIndices, int[] outputTypes, int[] outputAutoCommitFirstWordConfidence, int[] outputScores, int[] outputIndices, int[] outputTypes,
float[] inOutLanguageWeight); int[] outputAutoCommitFirstWordConfidence, float[] inOutLanguageWeight);
private static native boolean addUnigramEntryNative(long dict, int[] word, int probability, private static native boolean addUnigramEntryNative(long dict, int[] word, int probability,
int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence, int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence,
boolean isNotAWord, boolean isBlacklisted, int timestamp); boolean isNotAWord, boolean isBlacklisted, int timestamp);
@ -295,10 +295,10 @@ public final class BinaryDictionary extends Dictionary {
inputPointers.getYCoordinates(), inputPointers.getTimes(), inputPointers.getYCoordinates(), inputPointers.getTimes(),
inputPointers.getPointerIds(), session.mInputCodePoints, inputSize, inputPointers.getPointerIds(), session.mInputCodePoints, inputSize,
session.mNativeSuggestOptions.getOptions(), session.mPrevWordCodePointArrays, session.mNativeSuggestOptions.getOptions(), session.mPrevWordCodePointArrays,
session.mIsBeginningOfSentenceArray, session.mOutputSuggestionCount, session.mIsBeginningOfSentenceArray, prevWordsInfo.getPrevWordCount(),
session.mOutputCodePoints, session.mOutputScores, session.mSpaceIndices, session.mOutputSuggestionCount, session.mOutputCodePoints, session.mOutputScores,
session.mOutputTypes, session.mOutputAutoCommitFirstWordConfidence, session.mSpaceIndices, session.mOutputTypes,
session.mInputOutputLanguageWeight); session.mOutputAutoCommitFirstWordConfidence, session.mInputOutputLanguageWeight);
if (inOutLanguageWeight != null) { if (inOutLanguageWeight != null) {
inOutLanguageWeight[0] = session.mInputOutputLanguageWeight[0]; inOutLanguageWeight[0] = session.mInputOutputLanguageWeight[0];
} }

View File

@ -180,8 +180,8 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray, jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray,
jintArray inputCodePointsArray, jint inputSize, jintArray suggestOptions, jintArray inputCodePointsArray, jint inputSize, jintArray suggestOptions,
jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray, jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray,
jintArray outSuggestionCount, jintArray outCodePointsArray, jintArray outScoresArray, jint prevWordCount, jintArray outSuggestionCount, jintArray outCodePointsArray,
jintArray outSpaceIndicesArray, jintArray outTypesArray, jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outTypesArray,
jintArray outAutoCommitFirstWordConfidenceArray, jfloatArray inOutLanguageWeight) { jintArray outAutoCommitFirstWordConfidenceArray, jfloatArray inOutLanguageWeight) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict); Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
// Assign 0 to outSuggestionCount here in case of returning earlier in this method. // 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); env->GetFloatArrayRegion(inOutLanguageWeight, 0, 1 /* len */, &languageWeight);
SuggestionResults suggestionResults(MAX_RESULTS); SuggestionResults suggestionResults(MAX_RESULTS);
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env, const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
prevWordCodePointArrays, isBeginningOfSentenceArray); prevWordCodePointArrays, isBeginningOfSentenceArray, prevWordCount);
if (givenSuggestOptions.isGesture() || inputSize > 0) { if (givenSuggestOptions.isGesture() || inputSize > 0) {
// TODO: Use SuggestionResults to return suggestions. // TODO: Use SuggestionResults to return suggestions.
dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates, dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
@ -285,7 +285,8 @@ static jint latinime_BinaryDictionary_getNgramProbability(JNIEnv *env, jclass cl
int wordCodePoints[wordLength]; int wordCodePoints[wordLength];
env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env, const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
prevWordCodePointArrays, isBeginningOfSentenceArray); prevWordCodePointArrays, isBeginningOfSentenceArray,
env->GetArrayLength(prevWordCodePointArrays));
return dictionary->getNgramProbability(&prevWordsInfo, return dictionary->getNgramProbability(&prevWordsInfo,
CodePointArrayView(wordCodePoints, wordLength)); CodePointArrayView(wordCodePoints, wordLength));
} }
@ -393,7 +394,8 @@ static bool latinime_BinaryDictionary_addNgramEntry(JNIEnv *env, jclass clazz, j
return false; return false;
} }
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env, const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
prevWordCodePointArrays, isBeginningOfSentenceArray); prevWordCodePointArrays, isBeginningOfSentenceArray,
env->GetArrayLength(prevWordCodePointArrays));
jsize wordLength = env->GetArrayLength(word); jsize wordLength = env->GetArrayLength(word);
int wordCodePoints[wordLength]; int wordCodePoints[wordLength];
env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
@ -413,7 +415,8 @@ static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz
return false; return false;
} }
const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env, const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
prevWordCodePointArrays, isBeginningOfSentenceArray); prevWordCodePointArrays, isBeginningOfSentenceArray,
env->GetArrayLength(prevWordCodePointArrays));
jsize codePointCount = env->GetArrayLength(word); jsize codePointCount = env->GetArrayLength(word);
int wordCodePoints[codePointCount]; int wordCodePoints[codePointCount];
env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints); env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
@ -667,7 +670,7 @@ static const JNINativeMethod sMethods[] = {
}, },
{ {
const_cast<char *>("getSuggestionsNative"), 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) reinterpret_cast<void *>(latinime_BinaryDictionary_getSuggestions)
}, },
{ {

View File

@ -97,17 +97,13 @@ class JniDataUtils {
} }
static PrevWordsInfo constructPrevWordsInfo(JNIEnv *env, jobjectArray prevWordCodePointArrays, 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 prevWordCodePoints[MAX_PREV_WORD_COUNT_FOR_N_GRAM][MAX_WORD_LENGTH];
int prevWordCodePointCount[MAX_PREV_WORD_COUNT_FOR_N_GRAM]; int prevWordCodePointCount[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
bool isBeginningOfSentence[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 < prevWordCount; ++i) {
for (size_t i = 0; i < NELEMS(prevWordCodePoints); ++i) {
prevWordCodePointCount[i] = 0; prevWordCodePointCount[i] = 0;
isBeginningOfSentence[i] = false; isBeginningOfSentence[i] = false;
if (prevWordsCount <= static_cast<int>(i)) {
continue;
}
jintArray prevWord = (jintArray)env->GetObjectArrayElement(prevWordCodePointArrays, i); jintArray prevWord = (jintArray)env->GetObjectArrayElement(prevWordCodePointArrays, i);
if (!prevWord) { if (!prevWord) {
continue; continue;
@ -124,7 +120,7 @@ class JniDataUtils {
isBeginningOfSentence[i] = isBeginningOfSentenceBoolean == JNI_TRUE; isBeginningOfSentence[i] = isBeginningOfSentenceBoolean == JNI_TRUE;
} }
return PrevWordsInfo(prevWordCodePoints, prevWordCodePointCount, isBeginningOfSentence, return PrevWordsInfo(prevWordCodePoints, prevWordCodePointCount, isBeginningOfSentence,
MAX_PREV_WORD_COUNT_FOR_N_GRAM); prevWordCount);
} }
static void putBooleanToArray(JNIEnv *env, jbooleanArray array, const int index, static void putBooleanToArray(JNIEnv *env, jbooleanArray array, const int index,