Loading native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +9 −8 Original line number Original line Diff line number Diff line Loading @@ -403,10 +403,10 @@ static bool latinime_BinaryDictionary_addNgramEntry(JNIEnv *env, jclass clazz, j jsize wordLength = env->GetArrayLength(word); jsize wordLength = env->GetArrayLength(word); int wordCodePoints[wordLength]; int wordCodePoints[wordLength]; env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); // Use 1 for count to indicate the bigram has inputted. // Use 1 for count to indicate the ngram has inputted. const BigramProperty bigramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(), const NgramProperty ngramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(), probability, timestamp, 0 /* level */, 1 /* count */); probability, timestamp, 0 /* level */, 1 /* count */); return dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty); return dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty); } } static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz, jlong dict, static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz, jlong dict, Loading Loading @@ -501,12 +501,12 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j if (word0) { if (word0) { jint bigramProbability = env->GetIntField(languageModelParam, bigramProbabilityFieldId); jint bigramProbability = env->GetIntField(languageModelParam, bigramProbabilityFieldId); // Use 1 for count to indicate the bigram has inputted. // Use 1 for count to indicate the bigram has inputted. const BigramProperty bigramProperty( const NgramProperty ngramProperty( CodePointArrayView(word1CodePoints, word1Length).toVector(), CodePointArrayView(word1CodePoints, word1Length).toVector(), bigramProbability, timestamp, 0 /* level */, 1 /* count */); bigramProbability, timestamp, 0 /* level */, 1 /* count */); const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length, const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length, false /* isBeginningOfSentence */); false /* isBeginningOfSentence */); dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty); dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty); } } if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) { if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) { return i + 1; return i + 1; Loading Loading @@ -603,6 +603,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j } while (token != 0); } while (token != 0); // Add bigrams. // Add bigrams. // TODO: Support ngrams. do { do { token = dictionary->getNextWordAndNextToken(token, wordCodePoints, &wordCodePointCount); token = dictionary->getNextWordAndNextToken(token, wordCodePoints, &wordCodePointCount); const WordProperty wordProperty = dictionary->getWordProperty( const WordProperty wordProperty = dictionary->getWordProperty( Loading @@ -617,10 +618,10 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j } } const PrevWordsInfo prevWordsInfo(wordCodePoints, wordCodePointCount, const PrevWordsInfo prevWordsInfo(wordCodePoints, wordCodePointCount, wordProperty.getUnigramProperty()->representsBeginningOfSentence()); wordProperty.getUnigramProperty()->representsBeginningOfSentence()); for (const BigramProperty &bigramProperty : *wordProperty.getBigramProperties()) { for (const NgramProperty &ngramProperty : *wordProperty.getNgramProperties()) { if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo, if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo, &bigramProperty)) { &ngramProperty)) { LogUtils::logToJava(env, "Cannot add bigram to the new dict."); LogUtils::logToJava(env, "Cannot add ngram to the new dict."); return false; return false; } } } } Loading native/jni/src/suggest/core/dictionary/dictionary.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -144,9 +144,9 @@ bool Dictionary::removeUnigramEntry(const CodePointArrayView codePoints) { } } bool Dictionary::addNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool Dictionary::addNgramEntry(const PrevWordsInfo *const prevWordsInfo, const BigramProperty *const bigramProperty) { const NgramProperty *const ngramProperty) { TimeKeeper::setCurrentTime(); TimeKeeper::setCurrentTime(); return mDictionaryStructureWithBufferPolicy->addNgramEntry(prevWordsInfo, bigramProperty); return mDictionaryStructureWithBufferPolicy->addNgramEntry(prevWordsInfo, ngramProperty); } } bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, Loading native/jni/src/suggest/core/dictionary/dictionary.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -85,7 +85,7 @@ class Dictionary { bool removeUnigramEntry(const CodePointArrayView codePoints); bool removeUnigramEntry(const CodePointArrayView codePoints); bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo, const BigramProperty *const bigramProperty); const NgramProperty *const ngramProperty); bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView codePoints); const CodePointArrayView codePoints); Loading native/jni/src/suggest/core/dictionary/property/bigram_property.h→native/jni/src/suggest/core/dictionary/property/ngram_property.h +6 −7 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,8 @@ * limitations under the License. * limitations under the License. */ */ #ifndef LATINIME_BIGRAM_PROPERTY_H #ifndef LATINIME_NGRAM_PROPERTY_H #define LATINIME_BIGRAM_PROPERTY_H #define LATINIME_NGRAM_PROPERTY_H #include <vector> #include <vector> Loading @@ -23,10 +23,9 @@ namespace latinime { namespace latinime { // TODO: Change to NgramProperty. class NgramProperty { class BigramProperty { public: public: BigramProperty(const std::vector<int> &&targetCodePoints, const int probability, NgramProperty(const std::vector<int> &&targetCodePoints, const int probability, const int timestamp, const int level, const int count) const int timestamp, const int level, const int count) : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability), : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability), mTimestamp(timestamp), mLevel(level), mCount(count) {} mTimestamp(timestamp), mLevel(level), mCount(count) {} Loading @@ -53,7 +52,7 @@ class BigramProperty { private: private: // Default copy constructor and assign operator are used for using in std::vector. // Default copy constructor and assign operator are used for using in std::vector. DISALLOW_DEFAULT_CONSTRUCTOR(BigramProperty); DISALLOW_DEFAULT_CONSTRUCTOR(NgramProperty); // TODO: Make members const. // TODO: Make members const. std::vector<int> mTargetCodePoints; std::vector<int> mTargetCodePoints; Loading @@ -63,4 +62,4 @@ class BigramProperty { int mCount; int mCount; }; }; } // namespace latinime } // namespace latinime #endif // LATINIME_WORD_PROPERTY_H #endif // LATINIME_NGRAM_PROPERTY_H native/jni/src/suggest/core/dictionary/property/word_property.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,7 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, MAX_WORD_LENGTH /* maxLength */, mCodePoints.data(), mCodePoints.size(), MAX_WORD_LENGTH /* maxLength */, mCodePoints.data(), mCodePoints.size(), false /* needsNullTermination */); false /* needsNullTermination */); jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(), jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(), !mBigrams.empty(), mUnigramProperty.hasShortcuts(), !mNgrams.empty(), mUnigramProperty.hasShortcuts(), mUnigramProperty.representsBeginningOfSentence()}; mUnigramProperty.representsBeginningOfSentence()}; env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(), int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(), Loading @@ -42,8 +42,9 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); // Output bigrams. // Output bigrams. for (const auto &bigramProperty : mBigrams) { // TODO: Support n-gram const std::vector<int> *const word1CodePoints = bigramProperty.getTargetCodePoints(); for (const auto &ngramProperty : mNgrams) { const std::vector<int> *const word1CodePoints = ngramProperty.getTargetCodePoints(); jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size()); jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size()); JniDataUtils::outputCodePoints(env, bigramWord1CodePointArray, 0 /* start */, JniDataUtils::outputCodePoints(env, bigramWord1CodePointArray, 0 /* start */, word1CodePoints->size(), word1CodePoints->data(), word1CodePoints->size(), word1CodePoints->size(), word1CodePoints->data(), word1CodePoints->size(), Loading @@ -51,9 +52,9 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray); env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray); env->DeleteLocalRef(bigramWord1CodePointArray); env->DeleteLocalRef(bigramWord1CodePointArray); int bigramProbabilityInfo[] = {bigramProperty.getProbability(), int bigramProbabilityInfo[] = {ngramProperty.getProbability(), bigramProperty.getTimestamp(), bigramProperty.getLevel(), ngramProperty.getTimestamp(), ngramProperty.getLevel(), bigramProperty.getCount()}; ngramProperty.getCount()}; jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo)); jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo)); env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */, env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */, NELEMS(bigramProbabilityInfo), bigramProbabilityInfo); NELEMS(bigramProbabilityInfo), bigramProbabilityInfo); Loading Loading
native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +9 −8 Original line number Original line Diff line number Diff line Loading @@ -403,10 +403,10 @@ static bool latinime_BinaryDictionary_addNgramEntry(JNIEnv *env, jclass clazz, j jsize wordLength = env->GetArrayLength(word); jsize wordLength = env->GetArrayLength(word); int wordCodePoints[wordLength]; int wordCodePoints[wordLength]; env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints); // Use 1 for count to indicate the bigram has inputted. // Use 1 for count to indicate the ngram has inputted. const BigramProperty bigramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(), const NgramProperty ngramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(), probability, timestamp, 0 /* level */, 1 /* count */); probability, timestamp, 0 /* level */, 1 /* count */); return dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty); return dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty); } } static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz, jlong dict, static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz, jlong dict, Loading Loading @@ -501,12 +501,12 @@ static int latinime_BinaryDictionary_addMultipleDictionaryEntries(JNIEnv *env, j if (word0) { if (word0) { jint bigramProbability = env->GetIntField(languageModelParam, bigramProbabilityFieldId); jint bigramProbability = env->GetIntField(languageModelParam, bigramProbabilityFieldId); // Use 1 for count to indicate the bigram has inputted. // Use 1 for count to indicate the bigram has inputted. const BigramProperty bigramProperty( const NgramProperty ngramProperty( CodePointArrayView(word1CodePoints, word1Length).toVector(), CodePointArrayView(word1CodePoints, word1Length).toVector(), bigramProbability, timestamp, 0 /* level */, 1 /* count */); bigramProbability, timestamp, 0 /* level */, 1 /* count */); const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length, const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length, false /* isBeginningOfSentence */); false /* isBeginningOfSentence */); dictionary->addNgramEntry(&prevWordsInfo, &bigramProperty); dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty); } } if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) { if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) { return i + 1; return i + 1; Loading Loading @@ -603,6 +603,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j } while (token != 0); } while (token != 0); // Add bigrams. // Add bigrams. // TODO: Support ngrams. do { do { token = dictionary->getNextWordAndNextToken(token, wordCodePoints, &wordCodePointCount); token = dictionary->getNextWordAndNextToken(token, wordCodePoints, &wordCodePointCount); const WordProperty wordProperty = dictionary->getWordProperty( const WordProperty wordProperty = dictionary->getWordProperty( Loading @@ -617,10 +618,10 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j } } const PrevWordsInfo prevWordsInfo(wordCodePoints, wordCodePointCount, const PrevWordsInfo prevWordsInfo(wordCodePoints, wordCodePointCount, wordProperty.getUnigramProperty()->representsBeginningOfSentence()); wordProperty.getUnigramProperty()->representsBeginningOfSentence()); for (const BigramProperty &bigramProperty : *wordProperty.getBigramProperties()) { for (const NgramProperty &ngramProperty : *wordProperty.getNgramProperties()) { if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo, if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo, &bigramProperty)) { &ngramProperty)) { LogUtils::logToJava(env, "Cannot add bigram to the new dict."); LogUtils::logToJava(env, "Cannot add ngram to the new dict."); return false; return false; } } } } Loading
native/jni/src/suggest/core/dictionary/dictionary.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -144,9 +144,9 @@ bool Dictionary::removeUnigramEntry(const CodePointArrayView codePoints) { } } bool Dictionary::addNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool Dictionary::addNgramEntry(const PrevWordsInfo *const prevWordsInfo, const BigramProperty *const bigramProperty) { const NgramProperty *const ngramProperty) { TimeKeeper::setCurrentTime(); TimeKeeper::setCurrentTime(); return mDictionaryStructureWithBufferPolicy->addNgramEntry(prevWordsInfo, bigramProperty); return mDictionaryStructureWithBufferPolicy->addNgramEntry(prevWordsInfo, ngramProperty); } } bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, Loading
native/jni/src/suggest/core/dictionary/dictionary.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -85,7 +85,7 @@ class Dictionary { bool removeUnigramEntry(const CodePointArrayView codePoints); bool removeUnigramEntry(const CodePointArrayView codePoints); bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo, const BigramProperty *const bigramProperty); const NgramProperty *const ngramProperty); bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo, const CodePointArrayView codePoints); const CodePointArrayView codePoints); Loading
native/jni/src/suggest/core/dictionary/property/bigram_property.h→native/jni/src/suggest/core/dictionary/property/ngram_property.h +6 −7 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,8 @@ * limitations under the License. * limitations under the License. */ */ #ifndef LATINIME_BIGRAM_PROPERTY_H #ifndef LATINIME_NGRAM_PROPERTY_H #define LATINIME_BIGRAM_PROPERTY_H #define LATINIME_NGRAM_PROPERTY_H #include <vector> #include <vector> Loading @@ -23,10 +23,9 @@ namespace latinime { namespace latinime { // TODO: Change to NgramProperty. class NgramProperty { class BigramProperty { public: public: BigramProperty(const std::vector<int> &&targetCodePoints, const int probability, NgramProperty(const std::vector<int> &&targetCodePoints, const int probability, const int timestamp, const int level, const int count) const int timestamp, const int level, const int count) : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability), : mTargetCodePoints(std::move(targetCodePoints)), mProbability(probability), mTimestamp(timestamp), mLevel(level), mCount(count) {} mTimestamp(timestamp), mLevel(level), mCount(count) {} Loading @@ -53,7 +52,7 @@ class BigramProperty { private: private: // Default copy constructor and assign operator are used for using in std::vector. // Default copy constructor and assign operator are used for using in std::vector. DISALLOW_DEFAULT_CONSTRUCTOR(BigramProperty); DISALLOW_DEFAULT_CONSTRUCTOR(NgramProperty); // TODO: Make members const. // TODO: Make members const. std::vector<int> mTargetCodePoints; std::vector<int> mTargetCodePoints; Loading @@ -63,4 +62,4 @@ class BigramProperty { int mCount; int mCount; }; }; } // namespace latinime } // namespace latinime #endif // LATINIME_WORD_PROPERTY_H #endif // LATINIME_NGRAM_PROPERTY_H
native/jni/src/suggest/core/dictionary/property/word_property.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,7 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, MAX_WORD_LENGTH /* maxLength */, mCodePoints.data(), mCodePoints.size(), MAX_WORD_LENGTH /* maxLength */, mCodePoints.data(), mCodePoints.size(), false /* needsNullTermination */); false /* needsNullTermination */); jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(), jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(), !mBigrams.empty(), mUnigramProperty.hasShortcuts(), !mNgrams.empty(), mUnigramProperty.hasShortcuts(), mUnigramProperty.representsBeginningOfSentence()}; mUnigramProperty.representsBeginningOfSentence()}; env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(), int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(), Loading @@ -42,8 +42,9 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); // Output bigrams. // Output bigrams. for (const auto &bigramProperty : mBigrams) { // TODO: Support n-gram const std::vector<int> *const word1CodePoints = bigramProperty.getTargetCodePoints(); for (const auto &ngramProperty : mNgrams) { const std::vector<int> *const word1CodePoints = ngramProperty.getTargetCodePoints(); jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size()); jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size()); JniDataUtils::outputCodePoints(env, bigramWord1CodePointArray, 0 /* start */, JniDataUtils::outputCodePoints(env, bigramWord1CodePointArray, 0 /* start */, word1CodePoints->size(), word1CodePoints->data(), word1CodePoints->size(), word1CodePoints->size(), word1CodePoints->data(), word1CodePoints->size(), Loading @@ -51,9 +52,9 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray); env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray); env->DeleteLocalRef(bigramWord1CodePointArray); env->DeleteLocalRef(bigramWord1CodePointArray); int bigramProbabilityInfo[] = {bigramProperty.getProbability(), int bigramProbabilityInfo[] = {ngramProperty.getProbability(), bigramProperty.getTimestamp(), bigramProperty.getLevel(), ngramProperty.getTimestamp(), ngramProperty.getLevel(), bigramProperty.getCount()}; ngramProperty.getCount()}; jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo)); jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo)); env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */, env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */, NELEMS(bigramProbabilityInfo), bigramProbabilityInfo); NELEMS(bigramProbabilityInfo), bigramProbabilityInfo); Loading