Add jni method for removeUnigramEntry().

Bug: 15552347
Change-Id: Iadcdc73d3335d561a27b9314d3fcdab0b0c96e49
This commit is contained in:
Keisuke Kuroyanagi 2014-06-12 12:21:44 +09:00
parent f12985245c
commit b4d77eca55
2 changed files with 31 additions and 0 deletions

View File

@ -207,6 +207,7 @@ public final class BinaryDictionary extends Dictionary {
private static native boolean addUnigramWordNative(long dict, int[] word, int probability,
int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence,
boolean isNotAWord, boolean isBlacklisted, int timestamp);
private static native boolean removeUnigramWordNative(long dict, int[] word);
private static native boolean addBigramWordsNative(long dict, int[] word0,
boolean isBeginningOfSentence, int[] word1, int probability, int timestamp);
private static native boolean removeBigramWordsNative(long dict, int[] word0,
@ -443,6 +444,19 @@ public final class BinaryDictionary extends Dictionary {
return true;
}
// Remove a unigram entry from the binary dictionary in native code.
public boolean removeUnigramEntry(final String word) {
if (TextUtils.isEmpty(word)) {
return false;
}
final int[] codePoints = StringUtils.toCodePointArray(word);
if (!removeUnigramWordNative(mNativeDict, codePoints)) {
return false;
}
mHasUpdated = true;
return true;
}
// Add an n-gram entry to the binary dictionary with timestamp in native code.
public boolean addNgramEntry(final PrevWordsInfo prevWordsInfo, final String word,
final int probability, final int timestamp) {

View File

@ -357,6 +357,18 @@ static bool latinime_BinaryDictionary_addUnigramWord(JNIEnv *env, jclass clazz,
return dictionary->addUnigramEntry(codePoints, codePointCount, &unigramProperty);
}
static bool latinime_BinaryDictionary_removeUnigramWord(JNIEnv *env, jclass clazz, jlong dict,
jintArray word) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) {
return false;
}
jsize codePointCount = env->GetArrayLength(word);
int codePoints[codePointCount];
env->GetIntArrayRegion(word, 0, codePointCount, codePoints);
return dictionary->removeUnigramEntry(codePoints, codePointCount);
}
static bool latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz, jlong dict,
jintArray word0, jboolean isBeginningOfSentence, jintArray word1, jint probability,
jint timestamp) {
@ -669,6 +681,11 @@ static const JNINativeMethod sMethods[] = {
const_cast<char *>("(J[II[IIZZZI)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_addUnigramWord)
},
{
const_cast<char *>("removeUnigramWordNative"),
const_cast<char *>("(J[I)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_removeUnigramWord)
},
{
const_cast<char *>("addBigramWordsNative"),
const_cast<char *>("(J[IZ[III)Z"),