am c29ab24b: Merge "Add BigramProperty and ShortcutProperty in WordProperty."

* commit 'c29ab24b2f7b32bd1e32536a7f39fc2e6ae29749':
  Add BigramProperty and ShortcutProperty in WordProperty.
main
Keisuke Kuroyanagi 2014-01-31 08:21:44 -08:00 committed by Android Git Automerger
commit 95eb29cc89
3 changed files with 50 additions and 19 deletions

View File

@ -33,15 +33,16 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
jmethodID intToIntegerConstructorId = env->GetMethodID(integerClass, "<init>", "(I)V"); jmethodID intToIntegerConstructorId = env->GetMethodID(integerClass, "<init>", "(I)V");
jclass arrayListClass = env->FindClass("java/util/ArrayList"); jclass arrayListClass = env->FindClass("java/util/ArrayList");
jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z");
const int shortcutTargetCount = mShortcutTargets.size(); const int shortcutTargetCount = mShortcuts.size();
for (int i = 0; i < shortcutTargetCount; ++i) { for (int i = 0; i < shortcutTargetCount; ++i) {
jintArray shortcutTargetCodePointArray = env->NewIntArray(mShortcutTargets[i].size()); const std::vector<int> *const targetCodePoints = mShortcuts[i].getTargetCodePoints();
jintArray shortcutTargetCodePointArray = env->NewIntArray(targetCodePoints->size());
env->SetIntArrayRegion(shortcutTargetCodePointArray, 0 /* start */, env->SetIntArrayRegion(shortcutTargetCodePointArray, 0 /* start */,
mShortcutTargets[i].size(), &mShortcutTargets[i][0]); targetCodePoints->size(), &targetCodePoints->at(0));
env->CallVoidMethod(outShortcutTargets, addMethodId, shortcutTargetCodePointArray); env->CallVoidMethod(outShortcutTargets, addMethodId, shortcutTargetCodePointArray);
env->DeleteLocalRef(shortcutTargetCodePointArray); env->DeleteLocalRef(shortcutTargetCodePointArray);
jobject integerProbability = env->NewObject(integerClass, intToIntegerConstructorId, jobject integerProbability = env->NewObject(integerClass, intToIntegerConstructorId,
mShortcutProbabilities[i]); mShortcuts[i].getProbability());
env->CallVoidMethod(outShortcutProbabilities, addMethodId, integerProbability); env->CallVoidMethod(outShortcutProbabilities, addMethodId, integerProbability);
env->DeleteLocalRef(integerProbability); env->DeleteLocalRef(integerProbability);
} }

View File

@ -28,23 +28,54 @@ namespace latinime {
// This class is used for returning information belonging to a word to java side. // This class is used for returning information belonging to a word to java side.
class WordProperty { class WordProperty {
public: public:
// TODO: Add bigram information. class BigramProperty {
public:
BigramProperty(const std::vector<int> *const targetCodePoints,
const int probability, const int timestamp, const int level, const int count)
: mTargetCodePoints(*targetCodePoints), mProbability(probability),
mTimestamp(timestamp), mLevel(level), mCount(count) {}
private:
std::vector<int> mTargetCodePoints;
int mProbability;
int mTimestamp;
int mLevel;
int mCount;
};
class ShortcutProperty {
public:
ShortcutProperty(const std::vector<int> *const targetCodePoints, const int probability)
: mTargetCodePoints(*targetCodePoints), mProbability(probability) {}
const std::vector<int> *getTargetCodePoints() const {
return &mTargetCodePoints;
}
int getProbability() const {
return mProbability;
}
private:
std::vector<int> mTargetCodePoints;
int mProbability;
};
// Invalid word. // Invalid word.
WordProperty() WordProperty()
: mCodePoints(), 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), mBigrams(), mShortcuts() {}
WordProperty(const std::vector<int> *const codePoints, WordProperty(const std::vector<int> *const codePoints,
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<BigramProperty> *const bigrams,
const std::vector<std::vector<int> > *const shortcutTargets, const std::vector<ShortcutProperty> *const shortcuts)
const std::vector<int> *const shortcutProbabilities)
: mCodePoints(*codePoints), mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), : mCodePoints(*codePoints), mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted),
mHasBigrams(hasBigrams), mHasShortcuts(hasShortcuts), mProbability(probability), mHasBigrams(hasBigrams), mHasShortcuts(hasShortcuts), mProbability(probability),
mTimestamp(timestamp), mLevel(level), mCount(count), mTimestamp(timestamp), mLevel(level), mCount(count), mBigrams(*bigrams),
mShortcutTargets(*shortcutTargets), mShortcutProbabilities(*shortcutProbabilities) {} mShortcuts(*shortcuts) {}
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,
@ -63,9 +94,8 @@ class WordProperty {
int mTimestamp; int mTimestamp;
int mLevel; int mLevel;
int mCount; int mCount;
// Shortcut std::vector<BigramProperty> mBigrams;
std::vector<std::vector<int> > mShortcutTargets; std::vector<ShortcutProperty> mShortcuts;
std::vector<int> mShortcutProbabilities;
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_WORD_PROPERTY_H #endif // LATINIME_WORD_PROPERTY_H

View File

@ -332,9 +332,10 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
mBuffers.get()->getProbabilityDictContent()->getProbabilityEntry( mBuffers.get()->getProbabilityDictContent()->getProbabilityEntry(
ptNodeParams.getTerminalId()); ptNodeParams.getTerminalId());
const HistoricalInfo *const historicalInfo = probabilityEntry.getHistoricalInfo(); const HistoricalInfo *const historicalInfo = probabilityEntry.getHistoricalInfo();
// TODO: Fetch bigram information.
std::vector<WordProperty::BigramProperty> bigrams;
// Fetch shortcut information. // Fetch shortcut information.
std::vector<std::vector<int> > shortcutTargets; std::vector<WordProperty::ShortcutProperty> shortcuts;
std::vector<int> shortcutProbabilities;
int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
if (shortcutPos != NOT_A_DICT_POS) { if (shortcutPos != NOT_A_DICT_POS) {
int shortcutTarget[MAX_WORD_LENGTH]; int shortcutTarget[MAX_WORD_LENGTH];
@ -347,15 +348,14 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
shortcutDictContent->getShortcutEntryAndAdvancePosition(MAX_WORD_LENGTH, shortcutTarget, shortcutDictContent->getShortcutEntryAndAdvancePosition(MAX_WORD_LENGTH, shortcutTarget,
&shortcutTargetLength, &shortcutProbability, &hasNext, &shortcutPos); &shortcutTargetLength, &shortcutProbability, &hasNext, &shortcutPos);
std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength); std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength);
shortcutTargets.push_back(target); shortcuts.push_back(WordProperty::ShortcutProperty(&target, shortcutProbability));
shortcutProbabilities.push_back(shortcutProbability);
} }
} }
return WordProperty(&codePointVector, ptNodeParams.isNotAWord(), return WordProperty(&codePointVector, 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(), &bigrams, &shortcuts);
} }
} // namespace latinime } // namespace latinime