am da0ea760: Merge "Add jni method for removeUnigramEntry()."
* commit 'da0ea7603bdfb71a6134617d19535960aca4f40e': Add jni method for removeUnigramEntry().main
commit
528eab0b41
|
@ -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,
|
||||
|
@ -436,6 +437,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) {
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue