Merge "Rename updateCounter to updateEntriesForWordWithNgramContext."
commit
41302021d6
|
@ -202,8 +202,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
int[] word, int probability, int timestamp);
|
int[] word, int probability, int timestamp);
|
||||||
private static native boolean removeNgramEntryNative(long dict,
|
private static native boolean removeNgramEntryNative(long dict,
|
||||||
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word);
|
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word);
|
||||||
// TODO: Rename to updateEntriesForWordWithNgramContextNative.
|
private static native boolean updateEntriesForWordWithNgramContextNative(long dict,
|
||||||
private static native boolean updateCounterNative(long dict,
|
|
||||||
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
|
int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
|
||||||
int[] word, boolean isValidWord, int count, int timestamp);
|
int[] word, boolean isValidWord, int count, int timestamp);
|
||||||
private static native int addMultipleDictionaryEntriesNative(long dict,
|
private static native int addMultipleDictionaryEntriesNative(long dict,
|
||||||
|
@ -512,7 +511,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
final boolean[] isBeginningOfSentenceArray = new boolean[ngramContext.getPrevWordCount()];
|
final boolean[] isBeginningOfSentenceArray = new boolean[ngramContext.getPrevWordCount()];
|
||||||
ngramContext.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
|
ngramContext.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
|
||||||
final int[] wordCodePoints = StringUtils.toCodePointArray(word);
|
final int[] wordCodePoints = StringUtils.toCodePointArray(word);
|
||||||
if (!updateCounterNative(mNativeDict, prevWordCodePointArrays,
|
if (!updateEntriesForWordWithNgramContextNative(mNativeDict, prevWordCodePointArrays,
|
||||||
isBeginningOfSentenceArray, wordCodePoints, isValidWord, count, timestamp)) {
|
isBeginningOfSentenceArray, wordCodePoints, isValidWord, count, timestamp)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,9 +431,10 @@ static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz
|
||||||
CodePointArrayView(wordCodePoints, codePointCount));
|
CodePointArrayView(wordCodePoints, codePointCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, jlong dict,
|
static bool latinime_BinaryDictionary_updateEntriesForWordWithNgramContext(JNIEnv *env,
|
||||||
jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray,
|
jclass clazz, jlong dict, jobjectArray prevWordCodePointArrays,
|
||||||
jintArray word, jboolean isValidWord, jint count, jint timestamp) {
|
jbooleanArray isBeginningOfSentenceArray, jintArray word, jboolean isValidWord, jint count,
|
||||||
|
jint timestamp) {
|
||||||
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||||
if (!dictionary) {
|
if (!dictionary) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -445,7 +446,7 @@ static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, j
|
||||||
int wordCodePoints[codePointCount];
|
int wordCodePoints[codePointCount];
|
||||||
env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
|
env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
|
||||||
const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
|
const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
|
||||||
return dictionary->updateCounter(&prevWordsInfo,
|
return dictionary->updateEntriesForWordWithNgramContext(&prevWordsInfo,
|
||||||
CodePointArrayView(wordCodePoints, codePointCount), isValidWord == JNI_TRUE,
|
CodePointArrayView(wordCodePoints, codePointCount), isValidWord == JNI_TRUE,
|
||||||
historicalInfo);
|
historicalInfo);
|
||||||
}
|
}
|
||||||
|
@ -749,9 +750,9 @@ static const JNINativeMethod sMethods[] = {
|
||||||
reinterpret_cast<void *>(latinime_BinaryDictionary_removeNgramEntry)
|
reinterpret_cast<void *>(latinime_BinaryDictionary_removeNgramEntry)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
const_cast<char *>("updateCounterNative"),
|
const_cast<char *>("updateEntriesForWordWithNgramContextNative"),
|
||||||
const_cast<char *>("(J[[I[Z[IZII)Z"),
|
const_cast<char *>("(J[[I[Z[IZII)Z"),
|
||||||
reinterpret_cast<void *>(latinime_BinaryDictionary_updateCounter)
|
reinterpret_cast<void *>(latinime_BinaryDictionary_updateEntriesForWordWithNgramContext)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
const_cast<char *>("addMultipleDictionaryEntriesNative"),
|
const_cast<char *>("addMultipleDictionaryEntriesNative"),
|
||||||
|
|
|
@ -152,12 +152,12 @@ bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
||||||
return mDictionaryStructureWithBufferPolicy->removeNgramEntry(prevWordsInfo, codePoints);
|
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 CodePointArrayView codePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo) {
|
const HistoricalInfo historicalInfo) {
|
||||||
TimeKeeper::setCurrentTime();
|
TimeKeeper::setCurrentTime();
|
||||||
return mDictionaryStructureWithBufferPolicy->updateCounter(prevWordsInfo, codePoints,
|
return mDictionaryStructureWithBufferPolicy->updateEntriesForWordWithNgramContext(prevWordsInfo,
|
||||||
isValidWord, historicalInfo);
|
codePoints, isValidWord, historicalInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::flush(const char *const filePath) {
|
bool Dictionary::flush(const char *const filePath) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Dictionary {
|
||||||
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView codePoints);
|
const CodePointArrayView codePoints);
|
||||||
|
|
||||||
bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView codePoints, const bool isValidWord,
|
const CodePointArrayView codePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo);
|
const HistoricalInfo historicalInfo);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class DictionaryStructureWithBufferPolicy {
|
||||||
const CodePointArrayView wordCodePoints) = 0;
|
const CodePointArrayView wordCodePoints) = 0;
|
||||||
|
|
||||||
// Returns whether the update was success or not.
|
// 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 CodePointArrayView wordCodePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo) = 0;
|
const HistoricalInfo historicalInfo) = 0;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
// Rename to NgramContext.
|
||||||
class PrevWordsInfo {
|
class PrevWordsInfo {
|
||||||
public:
|
public:
|
||||||
// No prev word information.
|
// No prev word information.
|
||||||
|
|
|
@ -440,18 +440,19 @@ bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext(
|
||||||
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints,
|
||||||
const HistoricalInfo historicalInfo) {
|
const bool isValidWord, const HistoricalInfo historicalInfo) {
|
||||||
if (!mBuffers->isUpdatable()) {
|
if (!mBuffers->isUpdatable()) {
|
||||||
AKLOGI("Warning: updateCounter() is called for non-updatable dictionary.");
|
AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable "
|
||||||
|
"dictionary.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY;
|
const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY;
|
||||||
const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */,
|
const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */,
|
||||||
false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo);
|
false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo);
|
||||||
if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
|
if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
|
||||||
AKLOGE("Cannot update unigarm entry in updateCounter().");
|
AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
|
const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
|
||||||
|
@ -459,7 +460,7 @@ bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsI
|
||||||
const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram,
|
const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram,
|
||||||
historicalInfo);
|
historicalInfo);
|
||||||
if (!addNgramEntry(prevWordsInfo, &ngramProperty)) {
|
if (!addNgramEntry(prevWordsInfo, &ngramProperty)) {
|
||||||
AKLOGE("Cannot update unigarm entry in updateCounter().");
|
AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -118,7 +118,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView wordCodePoints);
|
const CodePointArrayView wordCodePoints);
|
||||||
|
|
||||||
bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo);
|
const HistoricalInfo historicalInfo);
|
||||||
|
|
||||||
|
|
|
@ -107,11 +107,12 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo) {
|
const HistoricalInfo historicalInfo) {
|
||||||
// This method should not be called for non-updatable dictionary.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -363,11 +363,12 @@ bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext(
|
||||||
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView wordCodePoints,
|
||||||
const HistoricalInfo historicalInfo) {
|
const bool isValidWord, const HistoricalInfo historicalInfo) {
|
||||||
if (!mBuffers->isUpdatable()) {
|
if (!mBuffers->isUpdatable()) {
|
||||||
AKLOGI("Warning: updateCounter() is called for non-updatable dictionary.");
|
AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable "
|
||||||
|
"dictionary.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: Have count up method in language model dict content.
|
// 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 */,
|
const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */,
|
||||||
false /* isNotAWord */, false /* isBlacklisted */, probability, historicalInfo);
|
false /* isNotAWord */, false /* isBlacklisted */, probability, historicalInfo);
|
||||||
if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
|
if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
|
||||||
AKLOGE("Cannot update unigarm entry in updateCounter().");
|
AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
|
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) {
|
for (size_t i = 1; i <= prevWordsInfo->getPrevWordCount(); ++i) {
|
||||||
const PrevWordsInfo trimmedPrevWordsInfo(prevWordsInfo->getTrimmedPrevWordsInfo(i));
|
const PrevWordsInfo trimmedPrevWordsInfo(prevWordsInfo->getTrimmedPrevWordsInfo(i));
|
||||||
if (!addNgramEntry(&trimmedPrevWordsInfo, &ngramProperty)) {
|
if (!addNgramEntry(&trimmedPrevWordsInfo, &ngramProperty)) {
|
||||||
AKLOGE("Cannot update ngram entry in updateCounter().");
|
AKLOGE("Cannot update ngram entry in updateEntriesForWordWithNgramContext().");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView wordCodePoints);
|
const CodePointArrayView wordCodePoints);
|
||||||
|
|
||||||
bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
|
bool updateEntriesForWordWithNgramContext(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
const CodePointArrayView wordCodePoints, const bool isValidWord,
|
||||||
const HistoricalInfo historicalInfo);
|
const HistoricalInfo historicalInfo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue