am 41302021
: Merge "Rename updateCounter to updateEntriesForWordWithNgramContext."
* commit '41302021d61d3c876fe3952089ff211bab0abb4e': Rename updateCounter to updateEntriesForWordWithNgramContext.
This commit is contained in:
commit
f49a1ec120
11 changed files with 35 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
namespace latinime {
|
||||
|
||||
// Rename to NgramContext.
|
||||
class PrevWordsInfo {
|
||||
public:
|
||||
// No prev word information.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -363,11 +363,12 @@ 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.
|
||||
|
@ -375,7 +376,7 @@ bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsI
|
|||
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 */)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue