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

Commit 841aa0b6 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Move HistoricalInfo to property and use it in *Property."

parents d368975c 287e155e
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -373,7 +373,8 @@ 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, timestamp, 0 /* level */, 1 /* count */, &shortcuts);
            isBlacklisted, probability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */),
            &shortcuts);
    return dictionary->addUnigramEntry(CodePointArrayView(codePoints, codePointCount),
            &unigramProperty);
}
@@ -405,7 +406,7 @@ static bool latinime_BinaryDictionary_addNgramEntry(JNIEnv *env, jclass clazz, j
    env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
    // Use 1 for count to indicate the ngram has inputted.
    const NgramProperty ngramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(),
            probability, timestamp, 0 /* level */, 1 /* count */);
            probability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */));
    return dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty);
}

@@ -494,8 +495,8 @@ 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, timestamp, 0 /* level */, 1 /* count */,
                &shortcuts);
                isBlacklisted, unigramProbability,
                HistoricalInfo(timestamp, 0 /* level */, 1 /* count */), &shortcuts);
        dictionary->addUnigramEntry(CodePointArrayView(word1CodePoints, word1Length),
                &unigramProperty);
        if (word0) {
@@ -503,7 +504,7 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j
            // Use 1 for count to indicate the bigram has inputted.
            const NgramProperty ngramProperty(
                    CodePointArrayView(word1CodePoints, word1Length).toVector(),
                    bigramProbability, timestamp, 0 /* level */, 1 /* count */);
                    bigramProbability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */));
            const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length,
                    false /* isBeginningOfSentence */);
            dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty);
+6 −6
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class HistoricalInfo {
        return mTimestamp != NOT_A_TIMESTAMP;
    }

    int getTimeStamp() const {
    int getTimestamp() const {
        return mTimestamp;
    }

@@ -47,12 +47,12 @@ class HistoricalInfo {
    }

 private:
    // Copy constructor is public to use this class as a type of return value.
    DISALLOW_ASSIGNMENT_OPERATOR(HistoricalInfo);
    // Default copy constructor and assign operator are used for using in std::vector.

    const int mTimestamp;
    const int mLevel;
    const int mCount;
    // TODO: Make members const.
    int mTimestamp;
    int mLevel;
    int mCount;
};
} // namespace latinime
#endif /* LATINIME_HISTORICAL_INFO_H */
+6 −15
Original line number Diff line number Diff line
@@ -20,15 +20,16 @@
#include <vector>

#include "defines.h"
#include "suggest/core/dictionary/property/historical_info.h"

namespace latinime {

class NgramProperty {
 public:
    NgramProperty(const std::vector<int> &&targetCodePoints, const int probability,
            const int timestamp, const int level, const int count)
            const HistoricalInfo &historicalInfo)
            : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability),
              mTimestamp(timestamp), mLevel(level), mCount(count) {}
              mHistoricalInfo(historicalInfo) {}

    const std::vector<int> *getTargetCodePoints() const {
        return &mTargetCodePoints;
@@ -38,16 +39,8 @@ class NgramProperty {
        return mProbability;
    }

    int getTimestamp() const {
        return mTimestamp;
    }

    int getLevel() const {
        return mLevel;
    }

    int getCount() const {
        return mCount;
    const HistoricalInfo getHistoricalInfo() const {
        return mHistoricalInfo;
    }

 private:
@@ -57,9 +50,7 @@ class NgramProperty {
    // TODO: Make members const.
    std::vector<int> mTargetCodePoints;
    int mProbability;
    int mTimestamp;
    int mLevel;
    int mCount;
    HistoricalInfo mHistoricalInfo;
};
} // namespace latinime
#endif // LATINIME_NGRAM_PROPERTY_H
+8 −19
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <vector>

#include "defines.h"
#include "suggest/core/dictionary/property/historical_info.h"

namespace latinime {

@@ -50,15 +51,14 @@ class UnigramProperty {

    UnigramProperty()
            : mRepresentsBeginningOfSentence(false), mIsNotAWord(false), mIsBlacklisted(false),
              mProbability(NOT_A_PROBABILITY), mTimestamp(NOT_A_TIMESTAMP), mLevel(0), mCount(0),
              mShortcuts() {}
              mProbability(NOT_A_PROBABILITY), mHistoricalInfo(), mShortcuts() {}

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

    bool representsBeginningOfSentence() const {
        return mRepresentsBeginningOfSentence;
@@ -85,16 +85,8 @@ class UnigramProperty {
        return mProbability;
    }

    int getTimestamp() const {
        return mTimestamp;
    }

    int getLevel() const {
        return mLevel;
    }

    int getCount() const {
        return mCount;
    const HistoricalInfo getHistoricalInfo() const {
        return mHistoricalInfo;
    }

    const std::vector<ShortcutProperty> &getShortcuts() const {
@@ -110,10 +102,7 @@ class UnigramProperty {
    bool mIsNotAWord;
    bool mIsBlacklisted;
    int mProbability;
    // Historical information
    int mTimestamp;
    int mLevel;
    int mCount;
    HistoricalInfo mHistoricalInfo;
    std::vector<ShortcutProperty> mShortcuts;
};
} // namespace latinime
+7 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "suggest/core/dictionary/property/word_property.h"

#include "utils/jni_data_utils.h"
#include "suggest/core/dictionary/property/historical_info.h"

namespace latinime {

@@ -31,8 +32,9 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
            !mNgrams.empty(), mUnigramProperty.hasShortcuts(),
            mUnigramProperty.representsBeginningOfSentence()};
    env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags);
    int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(),
            mUnigramProperty.getLevel(), mUnigramProperty.getCount()};
    const HistoricalInfo &historicalInfo = mUnigramProperty.getHistoricalInfo();
    int probabilityInfo[] = {mUnigramProperty.getProbability(), historicalInfo.getTimestamp(),
            historicalInfo.getLevel(), historicalInfo.getCount()};
    env->SetIntArrayRegion(outProbabilityInfo, 0 /* start */, NELEMS(probabilityInfo),
            probabilityInfo);

@@ -51,10 +53,10 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
                false /* needsNullTermination */);
        env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray);
        env->DeleteLocalRef(bigramWord1CodePointArray);

        const HistoricalInfo &ngramHistoricalInfo = ngramProperty.getHistoricalInfo();
        int bigramProbabilityInfo[] = {ngramProperty.getProbability(),
                ngramProperty.getTimestamp(), ngramProperty.getLevel(),
                ngramProperty.getCount()};
                ngramHistoricalInfo.getTimestamp(), ngramHistoricalInfo.getLevel(),
                ngramHistoricalInfo.getCount()};
        jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo));
        env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */,
                NELEMS(bigramProbabilityInfo), bigramProbabilityInfo);
Loading