Merge "Simplify UnigramProperty."

This commit is contained in:
Keisuke Kuroyanagi 2014-01-31 03:06:33 +00:00 committed by Android (Google) Code Review
commit e9085da8cb
3 changed files with 12 additions and 27 deletions

View file

@ -21,7 +21,7 @@ namespace latinime {
void UnigramProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, void UnigramProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
jbooleanArray outFlags, jintArray outProbability, jintArray outHistoricalInfo, jbooleanArray outFlags, jintArray outProbability, jintArray outHistoricalInfo,
jobject outShortcutTargets, jobject outShortcutProbabilities) const { jobject outShortcutTargets, jobject outShortcutProbabilities) const {
env->SetIntArrayRegion(outCodePoints, 0 /* start */, mCodePointCount, mCodePoints); env->SetIntArrayRegion(outCodePoints, 0 /* start */, mCodePoints.size(), &mCodePoints[0]);
jboolean flags[] = {mIsNotAWord, mIsBlacklisted, mHasBigrams, mHasShortcuts}; jboolean flags[] = {mIsNotAWord, mIsBlacklisted, mHasBigrams, mHasShortcuts};
env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags);
env->SetIntArrayRegion(outProbability, 0 /* start */, 1 /* len */, &mProbability); env->SetIntArrayRegion(outProbability, 0 /* start */, 1 /* len */, &mProbability);

View file

@ -30,36 +30,20 @@ class UnigramProperty {
public: public:
// Invalid unigram. // Invalid unigram.
UnigramProperty() UnigramProperty()
: mCodePoints(), mCodePointCount(0), mIsNotAWord(false), mIsBlacklisted(false), : mCodePoints(), mIsNotAWord(false), mIsBlacklisted(false),
mHasBigrams(false), mHasShortcuts(false), mProbability(NOT_A_PROBABILITY), mHasBigrams(false), mHasShortcuts(false), mProbability(NOT_A_PROBABILITY),
mTimestamp(0), mLevel(0), mCount(0), mShortcutTargets(), mShortcutProbabilities() {} mTimestamp(0), mLevel(0), mCount(0), mShortcutTargets(), mShortcutProbabilities() {}
UnigramProperty(const UnigramProperty &unigramProperty) UnigramProperty(const std::vector<int> *const codePoints,
: mCodePoints(), mCodePointCount(unigramProperty.mCodePointCount),
mIsNotAWord(unigramProperty.mIsNotAWord),
mIsBlacklisted(unigramProperty.mIsBlacklisted),
mHasBigrams(unigramProperty.mHasBigrams),
mHasShortcuts(unigramProperty.mHasShortcuts),
mProbability(unigramProperty.mProbability),
mTimestamp(unigramProperty.mTimestamp), mLevel(unigramProperty.mLevel),
mCount(unigramProperty.mCount), mShortcutTargets(unigramProperty.mShortcutTargets),
mShortcutProbabilities(unigramProperty.mShortcutProbabilities) {
memcpy(mCodePoints, unigramProperty.mCodePoints, sizeof(mCodePoints));
}
UnigramProperty(const int *const codePoints, const int codePointCount,
const bool isNotAWord, const bool isBlacklisted, const bool hasBigrams, const bool isNotAWord, const bool isBlacklisted, const bool hasBigrams,
const bool hasShortcuts, const int probability, const int timestamp, const bool hasShortcuts, const int probability, const int timestamp,
const int level, const int count, const int level, const int count,
const std::vector<std::vector<int> > *const shortcutTargets, const std::vector<std::vector<int> > *const shortcutTargets,
const std::vector<int> *const shortcutProbabilities) const std::vector<int> *const shortcutProbabilities)
: mCodePoints(), mCodePointCount(codePointCount), : mCodePoints(*codePoints), mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted),
mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), mHasBigrams(hasBigrams), mHasBigrams(hasBigrams), mHasShortcuts(hasShortcuts), mProbability(probability),
mHasShortcuts(hasShortcuts), mProbability(probability), mTimestamp(timestamp), mTimestamp(timestamp), mLevel(level), mCount(count),
mLevel(level), mCount(count), mShortcutTargets(*shortcutTargets), mShortcutTargets(*shortcutTargets), mShortcutProbabilities(*shortcutProbabilities) {}
mShortcutProbabilities(*shortcutProbabilities) {
memcpy(mCodePoints, codePoints, sizeof(mCodePoints));
}
void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags, void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags,
jintArray outProbability, jintArray outHistoricalInfo, jobject outShortcutTargets, jintArray outProbability, jintArray outHistoricalInfo, jobject outShortcutTargets,
@ -68,8 +52,7 @@ class UnigramProperty {
private: private:
DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty); DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty);
int mCodePoints[MAX_WORD_LENGTH]; std::vector<int> mCodePoints;
int mCodePointCount;
bool mIsNotAWord; bool mIsNotAWord;
bool mIsBlacklisted; bool mIsBlacklisted;
bool mHasBigrams; bool mHasBigrams;

View file

@ -326,6 +326,8 @@ const UnigramProperty Ver4PatriciaTriePolicy::getUnigramProperty(const int *cons
return UnigramProperty(); return UnigramProperty();
} }
const PtNodeParams ptNodeParams = mNodeReader.fetchNodeInfoInBufferFromPtNodePos(ptNodePos); const PtNodeParams ptNodeParams = mNodeReader.fetchNodeInfoInBufferFromPtNodePos(ptNodePos);
std::vector<int> codePointVector(ptNodeParams.getCodePoints(),
ptNodeParams.getCodePoints() + ptNodeParams.getCodePointCount());
const ProbabilityEntry probabilityEntry = const ProbabilityEntry probabilityEntry =
mBuffers.get()->getProbabilityDictContent()->getProbabilityEntry( mBuffers.get()->getProbabilityDictContent()->getProbabilityEntry(
ptNodeParams.getTerminalId()); ptNodeParams.getTerminalId());
@ -349,8 +351,8 @@ const UnigramProperty Ver4PatriciaTriePolicy::getUnigramProperty(const int *cons
shortcutProbabilities.push_back(shortcutProbability); shortcutProbabilities.push_back(shortcutProbability);
} }
} }
return UnigramProperty(ptNodeParams.getCodePoints(), ptNodeParams.getCodePointCount(), return UnigramProperty(&codePointVector, ptNodeParams.isNotAWord(),
ptNodeParams.isNotAWord(), ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(), ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(),
ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(), ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(),
historicalInfo->getTimeStamp(), historicalInfo->getLevel(), historicalInfo->getTimeStamp(), historicalInfo->getLevel(),
historicalInfo->getCount(), &shortcutTargets, &shortcutProbabilities); historicalInfo->getCount(), &shortcutTargets, &shortcutProbabilities);