Merge "Add jni method for removeUnigramEntry()."

This commit is contained in:
Keisuke Kuroyanagi 2014-06-12 07:05:58 +00:00 committed by Android (Google) Code Review
commit da0ea7603b
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, private static native boolean addUnigramWordNative(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);
private static native boolean removeUnigramWordNative(long dict, int[] word);
private static native boolean addBigramWordsNative(long dict, int[] word0, private static native boolean addBigramWordsNative(long dict, int[] word0,
boolean isBeginningOfSentence, int[] word1, int probability, int timestamp); boolean isBeginningOfSentence, int[] word1, int probability, int timestamp);
private static native boolean removeBigramWordsNative(long dict, int[] word0, private static native boolean removeBigramWordsNative(long dict, int[] word0,
@ -436,6 +437,19 @@ public final class BinaryDictionary extends Dictionary {
return true; 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. // Add an n-gram entry to the binary dictionary with timestamp in native code.
public boolean addNgramEntry(final PrevWordsInfo prevWordsInfo, final String word, public boolean addNgramEntry(final PrevWordsInfo prevWordsInfo, final String word,
final int probability, final int timestamp) { 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); 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, static bool latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz, jlong dict,
jintArray word0, jboolean isBeginningOfSentence, jintArray word1, jint probability, jintArray word0, jboolean isBeginningOfSentence, jintArray word1, jint probability,
jint timestamp) { jint timestamp) {
@ -669,6 +681,11 @@ static const JNINativeMethod sMethods[] = {
const_cast<char *>("(J[II[IIZZZI)Z"), const_cast<char *>("(J[II[IIZZZI)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_addUnigramWord) 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 *>("addBigramWordsNative"),
const_cast<char *>("(J[IZ[III)Z"), const_cast<char *>("(J[IZ[III)Z"),