aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-05-21 18:30:34 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-05-21 18:30:34 +0900
commit9f8c9a0161924f515c5ff9617db2317cdc1d01e2 (patch)
tree7498a3ae3d1f13bc1076131b6e44a27ca61e4104 /native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
parentc18b1c42f31ed81e072373dbbff25279cf4da94e (diff)
downloadlatinime-9f8c9a0161924f515c5ff9617db2317cdc1d01e2.tar.gz
latinime-9f8c9a0161924f515c5ff9617db2317cdc1d01e2.tar.xz
latinime-9f8c9a0161924f515c5ff9617db2317cdc1d01e2.zip
Use PrevWordsInfo to add/remove n(bi)-gram in native code.
Bug: 14119293 Bug: 14425059 Change-Id: I4b9a46bfd670b35195418eaee51456d44fb91b6d
Diffstat (limited to 'native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp')
-rw-r--r--native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index 28aaf2d1a..6223f86f4 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -343,7 +343,7 @@ static void latinime_BinaryDictionary_addUnigramWord(JNIEnv *env, jclass clazz,
// Use 1 for count to indicate the word has inputted.
const UnigramProperty unigramProperty(isNotAWord, isBlacklisted,
probability, timestamp, 0 /* level */, 1 /* count */, &shortcuts);
- dictionary->addUnigramWord(codePoints, codePointCount, &unigramProperty);
+ dictionary->addUnigramEntry(codePoints, codePointCount, &unigramProperty);
}
static void latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz, jlong dict,
@@ -363,7 +363,9 @@ static void latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz,
// Use 1 for count to indicate the bigram has inputted.
const BigramProperty bigramProperty(&bigramTargetCodePoints, probability,
timestamp, 0 /* level */, 1 /* count */);
- dictionary->addBigramWords(word0CodePoints, word0Length, &bigramProperty);
+ const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length,
+ false /* isBeginningOfSentence */);
+ dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty);
}
static void latinime_BinaryDictionary_removeBigramWords(JNIEnv *env, jclass clazz, jlong dict,
@@ -378,8 +380,9 @@ static void latinime_BinaryDictionary_removeBigramWords(JNIEnv *env, jclass claz
jsize word1Length = env->GetArrayLength(word1);
int word1CodePoints[word1Length];
env->GetIntArrayRegion(word1, 0, word1Length, word1CodePoints);
- dictionary->removeBigramWords(word0CodePoints, word0Length, word1CodePoints,
- word1Length);
+ const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length,
+ false /* isBeginningOfSentence */);
+ dictionary->removeNgramEntry(&prevWordsInfo, word1CodePoints, word1Length);
}
// Returns how many language model params are processed.
@@ -449,7 +452,7 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j
// Use 1 for count to indicate the word has inputted.
const UnigramProperty unigramProperty(isNotAWord, isBlacklisted,
unigramProbability, timestamp, 0 /* level */, 1 /* count */, &shortcuts);
- dictionary->addUnigramWord(word1CodePoints, word1Length, &unigramProperty);
+ dictionary->addUnigramEntry(word1CodePoints, word1Length, &unigramProperty);
if (word0) {
jint bigramProbability = env->GetIntField(languageModelParam, bigramProbabilityFieldId);
const std::vector<int> bigramTargetCodePoints(
@@ -457,7 +460,9 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j
// Use 1 for count to indicate the bigram has inputted.
const BigramProperty bigramProperty(&bigramTargetCodePoints, bigramProbability,
timestamp, 0 /* level */, 1 /* count */);
- dictionary->addBigramWords(word0CodePoints, word0Length, &bigramProperty);
+ const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length,
+ false /* isBeginningOfSentence */);
+ dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty);
}
if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) {
return i + 1;
@@ -541,7 +546,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j
return false;
}
}
- if (!dictionaryStructureWithBufferPolicy->addUnigramWord(wordCodePoints, wordLength,
+ if (!dictionaryStructureWithBufferPolicy->addUnigramEntry(wordCodePoints, wordLength,
wordProperty.getUnigramProperty())) {
LogUtils::logToJava(env, "Cannot add unigram to the new dict.");
return false;
@@ -561,8 +566,10 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j
return false;
}
}
+ const PrevWordsInfo prevWordsInfo(wordCodePoints, wordLength,
+ false /* isStartOfSentence */);
for (const BigramProperty &bigramProperty : *wordProperty.getBigramProperties()) {
- if (!dictionaryStructureWithBufferPolicy->addBigramWords(wordCodePoints, wordLength,
+ if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo,
&bigramProperty)) {
LogUtils::logToJava(env, "Cannot add bigram to the new dict.");
return false;