Add jni method for getMaxFrequencyOfExactMatches().

Bug: 13142176
Bug: 15428247
Change-Id: I2ae25090b67ad0c6df97dec7712e2f7e0bb08c40
This commit is contained in:
Keisuke Kuroyanagi 2014-06-05 18:16:11 +09:00
parent 9d4d61f9c1
commit d6b89e17a6
2 changed files with 24 additions and 1 deletions

View File

@ -189,6 +189,7 @@ public final class BinaryDictionary extends Dictionary {
private static native void closeNative(long dict);
private static native int getFormatVersionNative(long dict);
private static native int getProbabilityNative(long dict, int[] word);
private static native int getMaxProbabilityOfExactMatchesNative(long dict, int[] word);
private static native int getBigramProbabilityNative(long dict, int[] word0,
boolean isBeginningOfSentence, int[] word1);
private static native void getWordPropertyNative(long dict, int[] word,
@ -350,11 +351,17 @@ public final class BinaryDictionary extends Dictionary {
@Override
public int getFrequency(final String word) {
if (word == null) return NOT_A_PROBABILITY;
if (TextUtils.isEmpty(word)) return NOT_A_PROBABILITY;
int[] codePoints = StringUtils.toCodePointArray(word);
return getProbabilityNative(mNativeDict, codePoints);
}
public int getMaxFrequencyOfExactMatches(final String word) {
if (TextUtils.isEmpty(word)) return NOT_A_PROBABILITY;
int[] codePoints = StringUtils.toCodePointArray(word);
return getMaxProbabilityOfExactMatchesNative(mNativeDict, codePoints);
}
@UsedForTesting
public boolean isValidNgram(final PrevWordsInfo prevWordsInfo, final String word) {
return getNgramProbability(prevWordsInfo, word) != NOT_A_PROBABILITY;

View File

@ -273,6 +273,17 @@ static jint latinime_BinaryDictionary_getProbability(JNIEnv *env, jclass clazz,
return dictionary->getProbability(codePoints, wordLength);
}
static jint latinime_BinaryDictionary_getMaxProbabilityOfExactMatches(
JNIEnv *env, jclass clazz, jlong dict, jintArray word) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return NOT_A_PROBABILITY;
const jsize wordLength = env->GetArrayLength(word);
int codePoints[wordLength];
env->GetIntArrayRegion(word, 0, wordLength, codePoints);
// TODO: Implement.
return NOT_A_PROBABILITY;
}
static jint latinime_BinaryDictionary_getBigramProbability(JNIEnv *env, jclass clazz,
jlong dict, jintArray word0, jboolean isBeginningOfSentence, jintArray word1) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
@ -633,6 +644,11 @@ static const JNINativeMethod sMethods[] = {
const_cast<char *>("(J[I)I"),
reinterpret_cast<void *>(latinime_BinaryDictionary_getProbability)
},
{
const_cast<char *>("getMaxProbabilityOfExactMatchesNative"),
const_cast<char *>("(J[I)I"),
reinterpret_cast<void *>(latinime_BinaryDictionary_getMaxProbabilityOfExactMatches)
},
{
const_cast<char *>("getBigramProbabilityNative"),
const_cast<char *>("(J[IZ[I)I"),