From b4d77eca55fa48eaf29ab036ac3b098ebac5e691 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 12 Jun 2014 12:21:44 +0900 Subject: [PATCH] Add jni method for removeUnigramEntry(). Bug: 15552347 Change-Id: Iadcdc73d3335d561a27b9314d3fcdab0b0c96e49 --- .../inputmethod/latin/BinaryDictionary.java | 14 ++++++++++++++ ...droid_inputmethod_latin_BinaryDictionary.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 1d087439d..a414b9c9d 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -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) { diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index 476338e37..fb98f3183 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -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(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("(J[II[IIZZZI)Z"), reinterpret_cast(latinime_BinaryDictionary_addUnigramWord) }, + { + const_cast("removeUnigramWordNative"), + const_cast("(J[I)Z"), + reinterpret_cast(latinime_BinaryDictionary_removeUnigramWord) + }, { const_cast("addBigramWordsNative"), const_cast("(J[IZ[III)Z"),