Simplify UnigramProperty.
Bug: 12810574 Change-Id: I606f559b5dd340b7525280ecead2c2c7ec920a78main
parent
0c186c31d2
commit
5f7f6a1615
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue