From ab4437f4681db3fb8327f752df8f08bd0d8cf967 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 9 Oct 2014 17:34:29 +0900 Subject: [PATCH] Rename updateCounter to updateEntriesForWordWithNgramContext. Bug: 14425059 Change-Id: Id9b0dd7e32c711ed4292981517c3febd5fe9e897 --- .../inputmethod/latin/BinaryDictionary.java | 5 ++--- ...android_inputmethod_latin_BinaryDictionary.cpp | 13 +++++++------ .../src/suggest/core/dictionary/dictionary.cpp | 6 +++--- .../jni/src/suggest/core/dictionary/dictionary.h | 2 +- .../dictionary_structure_with_buffer_policy.h | 2 +- .../src/suggest/core/session/prev_words_info.h | 1 + .../backward/v402/ver4_patricia_trie_policy.cpp | 13 +++++++------ .../backward/v402/ver4_patricia_trie_policy.h | 2 +- .../structure/v2/patricia_trie_policy.h | 5 +++-- .../structure/v4/ver4_patricia_trie_policy.cpp | 15 ++++++++------- .../structure/v4/ver4_patricia_trie_policy.h | 2 +- 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index afd423c90..931f98a65 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -202,8 +202,7 @@ public final class BinaryDictionary extends Dictionary { int[] word, int probability, int timestamp); private static native boolean removeNgramEntryNative(long dict, int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word); - // TODO: Rename to updateEntriesForWordWithNgramContextNative. - private static native boolean updateCounterNative(long dict, + private static native boolean updateEntriesForWordWithNgramContextNative(long dict, int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word, boolean isValidWord, int count, int timestamp); private static native int addMultipleDictionaryEntriesNative(long dict, @@ -512,7 +511,7 @@ public final class BinaryDictionary extends Dictionary { final boolean[] isBeginningOfSentenceArray = new boolean[ngramContext.getPrevWordCount()]; ngramContext.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray); final int[] wordCodePoints = StringUtils.toCodePointArray(word); - if (!updateCounterNative(mNativeDict, prevWordCodePointArrays, + if (!updateEntriesForWordWithNgramContextNative(mNativeDict, prevWordCodePointArrays, isBeginningOfSentenceArray, wordCodePoints, isValidWord, count, timestamp)) { return false; } diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index b54aca6a8..cb76c330a 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -431,9 +431,10 @@ static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz CodePointArrayView(wordCodePoints, codePointCount)); } -static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, jlong dict, - jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray, - jintArray word, jboolean isValidWord, jint count, jint timestamp) { +static bool latinime_BinaryDictionary_updateEntriesForWordWithNgramContext(JNIEnv *env, + jclass clazz, jlong dict, jobjectArray prevWordCodePointArrays, + jbooleanArray isBeginningOfSentenceArray, jintArray word, jboolean isValidWord, jint count, + jint timestamp) { Dictionary *dictionary = reinterpret_cast(dict); if (!dictionary) { return false; @@ -445,7 +446,7 @@ static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, j int wordCodePoints[codePointCount]; env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints); const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count); - return dictionary->updateCounter(&prevWordsInfo, + return dictionary->updateEntriesForWordWithNgramContext(&prevWordsInfo, CodePointArrayView(wordCodePoints, codePointCount), isValidWord == JNI_TRUE, historicalInfo); } @@ -749,9 +750,9 @@ static const JNINativeMethod sMethods[] = { reinterpret_cast(latinime_BinaryDictionary_removeNgramEntry) }, { - const_cast("updateCounterNative"), + const_cast("updateEntriesForWordWithNgramContextNative"), const_cast("(J[[I[Z[IZII)Z"), - reinterpret_cast(latinime_BinaryDictionary_updateCounter) + reinterpret_cast(latinime_BinaryDictionary_updateEntriesForWordWithNgramContext) }, { const_cast("addMultipleDictionaryEntriesNative"), diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index 7a69d3ceb..bbd29c268 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -152,12 +152,12 @@ bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, return mDictionaryStructureWithBufferPolicy->removeNgramEntry(prevWordsInfo, codePoints); } -bool Dictionary::updateCounter(const PrevWordsInfo *const prevWordsInfo, +bool Dictionary::updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView codePoints, const bool isValidWord, const HistoricalInfo historicalInfo) { TimeKeeper::setCurrentTime(); - return mDictionaryStructureWithBufferPolicy->updateCounter(prevWordsInfo, codePoints, - isValidWord, historicalInfo); + return mDictionaryStructureWithBufferPolicy->updateEntriesForWordWithNgramContext(prevWordsInfo, + codePoints, isValidWord, historicalInfo); } bool Dictionary::flush(const char *const filePath) { diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index a58dbfbd7..1401e7674 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -91,7 +91,7 @@ class Dictionary { bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView codePoints); - bool updateCounter(const PrevWordsInfo *const prevWordsInfo, + bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView codePoints, const bool isValidWord, const HistoricalInfo historicalInfo); diff --git a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h index 6624b7921..02df348c6 100644 --- a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h +++ b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h @@ -89,7 +89,7 @@ class DictionaryStructureWithBufferPolicy { const CodePointArrayView wordCodePoints) = 0; // Returns whether the update was success or not. - virtual bool updateCounter(const PrevWordsInfo *const prevWordsInfo, + virtual bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, const bool isValidWord, const HistoricalInfo historicalInfo) = 0; diff --git a/native/jni/src/suggest/core/session/prev_words_info.h b/native/jni/src/suggest/core/session/prev_words_info.h index 553d5ad07..48ca0e2f3 100644 --- a/native/jni/src/suggest/core/session/prev_words_info.h +++ b/native/jni/src/suggest/core/session/prev_words_info.h @@ -26,6 +26,7 @@ namespace latinime { +// Rename to NgramContext. class PrevWordsInfo { public: // No prev word information. diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp index 36eafa1e9..8e78ea56a 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp @@ -440,18 +440,19 @@ bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWor } -bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo, - const CodePointArrayView wordCodePoints, const bool isValidWord, - const HistoricalInfo historicalInfo) { +bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext( + const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, + const bool isValidWord, const HistoricalInfo historicalInfo) { if (!mBuffers->isUpdatable()) { - AKLOGI("Warning: updateCounter() is called for non-updatable dictionary."); + AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable " + "dictionary."); return false; } const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY; const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */, false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo); if (!addUnigramEntry(wordCodePoints, &unigramProperty)) { - AKLOGE("Cannot update unigarm entry in updateCounter()."); + AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext()."); return false; } const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */) @@ -459,7 +460,7 @@ bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsI const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram, historicalInfo); if (!addNgramEntry(prevWordsInfo, &ngramProperty)) { - AKLOGE("Cannot update unigarm entry in updateCounter()."); + AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext()."); return false; } return true; diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h index b82563e61..e4d7ff1f7 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h @@ -118,7 +118,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy { bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints); - bool updateCounter(const PrevWordsInfo *const prevWordsInfo, + bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, const bool isValidWord, const HistoricalInfo historicalInfo); diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h index 32a95bb6c..16aa592cc 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h @@ -107,11 +107,12 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy { return false; } - bool updateCounter(const PrevWordsInfo *const prevWordsInfo, + bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, const bool isValidWord, const HistoricalInfo historicalInfo) { // This method should not be called for non-updatable dictionary. - AKLOGI("Warning: updateCounter() is called for non-updatable dictionary."); + AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable " + "dictionary."); return false; } diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp index 036197c41..76377a280 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp @@ -363,19 +363,20 @@ bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWor } } -bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo, - const CodePointArrayView wordCodePoints, const bool isValidWord, - const HistoricalInfo historicalInfo) { +bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext( + const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, + const bool isValidWord, const HistoricalInfo historicalInfo) { if (!mBuffers->isUpdatable()) { - AKLOGI("Warning: updateCounter() is called for non-updatable dictionary."); + AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable " + "dictionary."); return false; } // TODO: Have count up method in language model dict content. const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY; const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */, - false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo); + false /* isNotAWord */, false /* isBlacklisted */, probability, historicalInfo); if (!addUnigramEntry(wordCodePoints, &unigramProperty)) { - AKLOGE("Cannot update unigarm entry in updateCounter()."); + AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext()."); return false; } const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */) @@ -385,7 +386,7 @@ bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsI for (size_t i = 1; i <= prevWordsInfo->getPrevWordCount(); ++i) { const PrevWordsInfo trimmedPrevWordsInfo(prevWordsInfo->getTrimmedPrevWordsInfo(i)); if (!addNgramEntry(&trimmedPrevWordsInfo, &ngramProperty)) { - AKLOGE("Cannot update ngram entry in updateCounter()."); + AKLOGE("Cannot update ngram entry in updateEntriesForWordWithNgramContext()."); return false; } } diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h index 662bb8d4b..696ec1f9d 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h @@ -98,7 +98,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy { bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints); - bool updateCounter(const PrevWordsInfo *const prevWordsInfo, + bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints, const bool isValidWord, const HistoricalInfo historicalInfo);