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

* commit 'b23f03488f165565e46f8d1b742ee6629f9c0f52':
  Use reference instead of pointer for WordProperty().
main
Keisuke Kuroyanagi 2014-11-10 21:57:07 +00:00 committed by Android Git Automerger
commit 75825abc72
5 changed files with 18 additions and 13 deletions

View File

@ -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
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;

View File

@ -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 {
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 {
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:

View File

@ -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,

View File

@ -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,

View File

@ -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,