Add jni method to update entries for a word efficiently.

Bug: 14425059
Change-Id: Ic628939ea68cdee17573409883a8403c73b78905
This commit is contained in:
Keisuke Kuroyanagi 2014-10-01 17:40:20 +09:00
parent 287e155e44
commit ce5fd94b97
2 changed files with 21 additions and 0 deletions

View file

@ -199,6 +199,9 @@ public final class BinaryDictionary extends Dictionary {
int[] word, int probability, int timestamp);
private static native boolean removeNgramEntryNative(long dict,
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word);
private static native boolean updateCounterNative(long dict,
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
int[] word, boolean isValidWord, int count, int timestamp);
private static native int addMultipleDictionaryEntriesNative(long dict,
LanguageModelParam[] languageModelParams, int startIndex);
private static native String getPropertyNative(long dict, String query);

View file

@ -427,6 +427,19 @@ static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz
CodePointArrayView(wordCodePoints, codePointCount));
}
static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, jlong dict,
jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray,
jintArray word, jboolean isValidWord, jint count, jint timestamp) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) {
return false;
}
jsize wordLength = env->GetArrayLength(word);
int wordCodePoints[wordLength];
env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
return false;
}
// Returns how many language model params are processed.
static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, jclass clazz,
jlong dict, jobjectArray languageModelParams, jint startIndex) {
@ -724,6 +737,11 @@ static const JNINativeMethod sMethods[] = {
const_cast<char *>("(J[[I[Z[I)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_removeNgramEntry)
},
{
const_cast<char *>("updateCounterNative"),
const_cast<char *>("(J[[I[Z[IZII)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_updateCounter)
},
{
const_cast<char *>("addMultipleDictionaryEntriesNative"),
const_cast<char *>(