am e9085da8: Merge "Simplify UnigramProperty."

* commit 'e9085da8cb6efe8228c5432194458242d7163842':
  Simplify UnigramProperty.
main
Keisuke Kuroyanagi 2014-01-30 20:43:24 -08:00 committed by Android Git Automerger
commit 0264945149
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,
jbooleanArray outFlags, jintArray outProbability, jintArray outHistoricalInfo,
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};
env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags);
env->SetIntArrayRegion(outProbability, 0 /* start */, 1 /* len */, &mProbability);

View File

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

View File

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