Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29777e3a authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Implement updateCounter() by using existing entry adding methods.

Bug: 14425059
Change-Id: I0b6cb80e1fb8f738e9c7d9e80fbc0c479546b879
parent ce5fd94b
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -374,7 +374,7 @@ static bool latinime_BinaryDictionary_addUnigramEntry(JNIEnv *env, jclass clazz,
    // Use 1 for count to indicate the word has inputted.
    const UnigramProperty unigramProperty(isBeginningOfSentence, isNotAWord,
            isBlacklisted, probability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */),
            &shortcuts);
            std::move(shortcuts));
    return dictionary->addUnigramEntry(CodePointArrayView(codePoints, codePointCount),
            &unigramProperty);
}
@@ -434,10 +434,16 @@ static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, j
    if (!dictionary) {
        return false;
    }
    jsize wordLength = env->GetArrayLength(word);
    int wordCodePoints[wordLength];
    env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
    return false;
    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
            prevWordCodePointArrays, isBeginningOfSentenceArray,
            env->GetArrayLength(prevWordCodePointArrays));
    jsize codePointCount = env->GetArrayLength(word);
    int wordCodePoints[codePointCount];
    env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
    const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
    return dictionary->updateCounter(&prevWordsInfo,
            CodePointArrayView(wordCodePoints, codePointCount), isValidWord == JNI_TRUE,
            historicalInfo);
}

// Returns how many language model params are processed.
@@ -509,7 +515,7 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j
        // Use 1 for count to indicate the word has inputted.
        const UnigramProperty unigramProperty(false /* isBeginningOfSentence */, isNotAWord,
                isBlacklisted, unigramProbability,
                HistoricalInfo(timestamp, 0 /* level */, 1 /* count */), &shortcuts);
                HistoricalInfo(timestamp, 0 /* level */, 1 /* count */), std::move(shortcuts));
        dictionary->addUnigramEntry(CodePointArrayView(word1CodePoints, word1Length),
                &unigramProperty);
        if (word0) {
+8 −0
Original line number Diff line number Diff line
@@ -155,6 +155,14 @@ bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
    return mDictionaryStructureWithBufferPolicy->removeNgramEntry(prevWordsInfo, codePoints);
}

bool Dictionary::updateCounter(const PrevWordsInfo *const prevWordsInfo,
        const CodePointArrayView codePoints, const bool isValidWord,
        const HistoricalInfo historicalInfo) {
    TimeKeeper::setCurrentTime();
    return mDictionaryStructureWithBufferPolicy->updateCounter(prevWordsInfo, codePoints,
            isValidWord, historicalInfo);
}

bool Dictionary::flush(const char *const filePath) {
    TimeKeeper::setCurrentTime();
    return mDictionaryStructureWithBufferPolicy->flush(filePath);
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "defines.h"
#include "jni.h"
#include "suggest/core/dictionary/ngram_listener.h"
#include "suggest/core/dictionary/property/historical_info.h"
#include "suggest/core/dictionary/property/word_property.h"
#include "suggest/core/policy/dictionary_header_structure_policy.h"
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
@@ -90,6 +91,10 @@ class Dictionary {
    bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
            const CodePointArrayView codePoints);

    bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
            const CodePointArrayView codePoints, const bool isValidWord,
            const HistoricalInfo historicalInfo);

    bool flush(const char *const filePath);

    bool flushWithGC(const char *const filePath);
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace latinime {
class NgramProperty {
 public:
    NgramProperty(const std::vector<int> &&targetCodePoints, const int probability,
            const HistoricalInfo &historicalInfo)
            const HistoricalInfo historicalInfo)
            : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability),
              mHistoricalInfo(historicalInfo) {}

+10 −3
Original line number Diff line number Diff line
@@ -54,11 +54,18 @@ class UnigramProperty {
              mProbability(NOT_A_PROBABILITY), mHistoricalInfo(), mShortcuts() {}

    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
            const bool isBlacklisted, const int probability, const HistoricalInfo &historicalInfo,
            const std::vector<ShortcutProperty> *const shortcuts)
            const bool isBlacklisted, const int probability, const HistoricalInfo historicalInfo,
            const std::vector<ShortcutProperty> &&shortcuts)
            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
              mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), mProbability(probability),
              mHistoricalInfo(historicalInfo), mShortcuts(*shortcuts) {}
              mHistoricalInfo(historicalInfo), mShortcuts(std::move(shortcuts)) {}

    // Without shortcuts.
    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
            const bool isBlacklisted, const int probability, const HistoricalInfo historicalInfo)
            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
              mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), mProbability(probability),
              mHistoricalInfo(historicalInfo), mShortcuts() {}

    bool representsBeginningOfSentence() const {
        return mRepresentsBeginningOfSentence;
Loading