Merge "Rename updateCounter to updateEntriesForWordWithNgramContext."

main
Keisuke Kuroyanagi 2014-10-09 08:51:17 +00:00 committed by Android (Google) Code Review
commit 41302021d6
11 changed files with 35 additions and 31 deletions

View File

@ -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;
}

View File

@ -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<Dictionary *>(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<void *>(latinime_BinaryDictionary_removeNgramEntry)
},
{
const_cast<char *>("updateCounterNative"),
const_cast<char *>("updateEntriesForWordWithNgramContextNative"),
const_cast<char *>("(J[[I[Z[IZII)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_updateCounter)
reinterpret_cast<void *>(latinime_BinaryDictionary_updateEntriesForWordWithNgramContext)
},
{
const_cast<char *>("addMultipleDictionaryEntriesNative"),

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -26,6 +26,7 @@
namespace latinime {
// Rename to NgramContext.
class PrevWordsInfo {
public:
// No prev word information.

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);