Skip to content
Snippets Groups Projects
Commit b23f0348 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Use reference instead of pointer for WordProperty()."

parents d158c430 bbf0d414
No related branches found
No related tags found
No related merge requests found
...@@ -586,7 +586,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j ...@@ -586,7 +586,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j
} }
if (!dictionaryStructureWithBufferPolicy->addUnigramEntry( if (!dictionaryStructureWithBufferPolicy->addUnigramEntry(
CodePointArrayView(wordCodePoints, wordCodePointCount), CodePointArrayView(wordCodePoints, wordCodePointCount),
wordProperty.getUnigramProperty())) { &wordProperty.getUnigramProperty())) {
LogUtils::logToJava(env, "Cannot add unigram to the new dict."); LogUtils::logToJava(env, "Cannot add unigram to the new dict.");
return false; return false;
} }
...@@ -605,7 +605,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j ...@@ -605,7 +605,7 @@ static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, j
return false; return false;
} }
} }
for (const NgramProperty &ngramProperty : *wordProperty.getNgramProperties()) { for (const NgramProperty &ngramProperty : wordProperty.getNgramProperties()) {
if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&ngramProperty)) { if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&ngramProperty)) {
LogUtils::logToJava(env, "Cannot add ngram to the new dict."); LogUtils::logToJava(env, "Cannot add ngram to the new dict.");
return false; return false;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "jni.h" #include "jni.h"
#include "suggest/core/dictionary/property/ngram_property.h" #include "suggest/core/dictionary/property/ngram_property.h"
#include "suggest/core/dictionary/property/unigram_property.h" #include "suggest/core/dictionary/property/unigram_property.h"
#include "utils/int_array_view.h"
namespace latinime { namespace latinime {
...@@ -33,10 +34,10 @@ class WordProperty { ...@@ -33,10 +34,10 @@ class WordProperty {
WordProperty() WordProperty()
: mCodePoints(), mUnigramProperty(), mNgrams() {} : mCodePoints(), mUnigramProperty(), mNgrams() {}
WordProperty(const std::vector<int> &&codePoints, const UnigramProperty *const unigramProperty, WordProperty(const std::vector<int> &&codePoints, const UnigramProperty &unigramProperty,
const std::vector<NgramProperty> *const ngrams) const std::vector<NgramProperty> &ngrams)
: mCodePoints(std::move(codePoints)), mUnigramProperty(*unigramProperty), : mCodePoints(std::move(codePoints)), mUnigramProperty(unigramProperty),
mNgrams(*ngrams) {} mNgrams(ngrams) {}
void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags, void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags,
jintArray outProbabilityInfo, jobject outNgramPrevWordsArray, jintArray outProbabilityInfo, jobject outNgramPrevWordsArray,
...@@ -44,12 +45,16 @@ class WordProperty { ...@@ -44,12 +45,16 @@ class WordProperty {
jobject outNgramProbabilities, jobject outShortcutTargets, jobject outNgramProbabilities, jobject outShortcutTargets,
jobject outShortcutProbabilities) const; jobject outShortcutProbabilities) const;
const UnigramProperty *getUnigramProperty() const { const CodePointArrayView getCodePoints() const {
return &mUnigramProperty; return CodePointArrayView(mCodePoints);
} }
const std::vector<NgramProperty> *getNgramProperties() const { const UnigramProperty &getUnigramProperty() const {
return &mNgrams; return mUnigramProperty;
}
const std::vector<NgramProperty> &getNgramProperties() const {
return mNgrams;
} }
private: private:
......
...@@ -614,7 +614,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty( ...@@ -614,7 +614,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(
const UnigramProperty unigramProperty(ptNodeParams.representsBeginningOfSentence(), const UnigramProperty unigramProperty(ptNodeParams.representsBeginningOfSentence(),
ptNodeParams.isNotAWord(), ptNodeParams.isPossiblyOffensive(), ptNodeParams.isNotAWord(), ptNodeParams.isPossiblyOffensive(),
ptNodeParams.getProbability(), *historicalInfo, std::move(shortcuts)); ptNodeParams.getProbability(), *historicalInfo, std::move(shortcuts));
return WordProperty(wordCodePoints.toVector(), &unigramProperty, &ngrams); return WordProperty(wordCodePoints.toVector(), unigramProperty, ngrams);
} }
int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints, int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints,
......
...@@ -478,7 +478,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty( ...@@ -478,7 +478,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty(
const UnigramProperty unigramProperty(ptNodeParams.representsBeginningOfSentence(), const UnigramProperty unigramProperty(ptNodeParams.representsBeginningOfSentence(),
ptNodeParams.isNotAWord(), ptNodeParams.isPossiblyOffensive(), ptNodeParams.isNotAWord(), ptNodeParams.isPossiblyOffensive(),
ptNodeParams.getProbability(), HistoricalInfo(), std::move(shortcuts)); ptNodeParams.getProbability(), HistoricalInfo(), std::move(shortcuts));
return WordProperty(wordCodePoints.toVector(), &unigramProperty, &ngrams); return WordProperty(wordCodePoints.toVector(), unigramProperty, ngrams);
} }
int PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints, int PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints,
......
...@@ -560,7 +560,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty( ...@@ -560,7 +560,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(
wordAttributes.isNotAWord(), wordAttributes.isBlacklisted(), wordAttributes.isNotAWord(), wordAttributes.isBlacklisted(),
wordAttributes.isPossiblyOffensive(), wordAttributes.getProbability(), wordAttributes.isPossiblyOffensive(), wordAttributes.getProbability(),
*historicalInfo, std::move(shortcuts)); *historicalInfo, std::move(shortcuts));
return WordProperty(wordCodePoints.toVector(), &unigramProperty, &ngrams); return WordProperty(wordCodePoints.toVector(), unigramProperty, ngrams);
} }
int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints, int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment