Remove hasBigrams/hasShortcut flags from ver4 PtNode.

Always check bigram/shortcut content instead of having
flags in each PtNode.

Bug: 14425059
Change-Id: I9eb816681bf22fc12e3ab3c92a178a7990b90e93
Keisuke Kuroyanagi 2014-06-23 16:49:49 +09:00
parent d2e566f999
commit 24d49ee577
5 changed files with 9 additions and 39 deletions

View File

@ -65,7 +65,7 @@ bool DynamicPtGcEventListeners
bool DynamicPtGcEventListeners::TraversePolicyToUpdateBigramProbability bool DynamicPtGcEventListeners::TraversePolicyToUpdateBigramProbability
::onVisitingPtNode(const PtNodeParams *const ptNodeParams) { ::onVisitingPtNode(const PtNodeParams *const ptNodeParams) {
if (!ptNodeParams->isDeleted() && ptNodeParams->hasBigrams()) { if (!ptNodeParams->isDeleted()) {
int bigramEntryCount = 0; int bigramEntryCount = 0;
if (!mPtNodeWriter->updateAllBigramEntriesAndDeleteUselessEntries(ptNodeParams, if (!mPtNodeWriter->updateAllBigramEntriesAndDeleteUselessEntries(ptNodeParams,
&bigramEntryCount)) { &bigramEntryCount)) {

View File

@ -270,8 +270,8 @@ const PtNodeParams DynamicPtUpdatingHelper::getUpdatedPtNodeParams(
const bool isNotAWord, const bool isBlacklisted, const bool isTerminal, const int parentPos, const bool isNotAWord, const bool isBlacklisted, const bool isTerminal, const int parentPos,
const int codePointCount, const int *const codePoints, const int probability) const { const int codePointCount, const int *const codePoints, const int probability) const {
const PatriciaTrieReadingUtils::NodeFlags flags = PatriciaTrieReadingUtils::createAndGetFlags( const PatriciaTrieReadingUtils::NodeFlags flags = PatriciaTrieReadingUtils::createAndGetFlags(
isBlacklisted, isNotAWord, isTerminal, originalPtNodeParams->hasShortcutTargets(), isBlacklisted, isNotAWord, isTerminal, false /* hasShortcutTargets */,
originalPtNodeParams->hasBigrams(), codePointCount > 1 /* hasMultipleChars */, false /* hasBigrams */, codePointCount > 1 /* hasMultipleChars */,
CHILDREN_POSITION_FIELD_SIZE); CHILDREN_POSITION_FIELD_SIZE);
return PtNodeParams(originalPtNodeParams, flags, parentPos, codePointCount, codePoints, return PtNodeParams(originalPtNodeParams, flags, parentPos, codePointCount, codePoints,
probability); probability);

View File

@ -231,14 +231,6 @@ bool Ver4PatriciaTrieNodeWriter::addNewBigramEntry(
sourcePtNodeParams->getTerminalId(), targetPtNodeParam->getTerminalId()); sourcePtNodeParams->getTerminalId(), targetPtNodeParam->getTerminalId());
return false; return false;
} }
if (!sourcePtNodeParams->hasBigrams()) {
// Update has bigrams flag.
return updatePtNodeFlags(sourcePtNodeParams->getHeadPos(),
sourcePtNodeParams->isBlacklisted(), sourcePtNodeParams->isNotAWord(),
sourcePtNodeParams->isTerminal(), sourcePtNodeParams->hasShortcutTargets(),
true /* hasBigrams */,
sourcePtNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
}
return true; return true;
} }
@ -303,28 +295,9 @@ bool Ver4PatriciaTrieNodeWriter::addShortcutTarget(const PtNodeParams *const ptN
AKLOGE("Cannot add new shortuct entry. terminalId: %d", ptNodeParams->getTerminalId()); AKLOGE("Cannot add new shortuct entry. terminalId: %d", ptNodeParams->getTerminalId());
return false; return false;
} }
if (!ptNodeParams->hasShortcutTargets()) {
// Update has shortcut targets flag.
return updatePtNodeFlags(ptNodeParams->getHeadPos(),
ptNodeParams->isBlacklisted(), ptNodeParams->isNotAWord(),
ptNodeParams->isTerminal(), true /* hasShortcutTargets */,
ptNodeParams->hasBigrams(),
ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
}
return true; return true;
} }
bool Ver4PatriciaTrieNodeWriter::updatePtNodeHasBigramsAndShortcutTargetsFlags(
const PtNodeParams *const ptNodeParams) {
const bool hasBigrams = mBuffers->getBigramDictContent()->getBigramListHeadPos(
ptNodeParams->getTerminalId()) != NOT_A_DICT_POS;
const bool hasShortcutTargets = mBuffers->getShortcutDictContent()->getShortcutListHeadPos(
ptNodeParams->getTerminalId()) != NOT_A_DICT_POS;
return updatePtNodeFlags(ptNodeParams->getHeadPos(), ptNodeParams->isBlacklisted(),
ptNodeParams->isNotAWord(), ptNodeParams->isTerminal(), hasShortcutTargets,
hasBigrams, ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
}
bool Ver4PatriciaTrieNodeWriter::writePtNodeAndGetTerminalIdAndAdvancePosition( bool Ver4PatriciaTrieNodeWriter::writePtNodeAndGetTerminalIdAndAdvancePosition(
const PtNodeParams *const ptNodeParams, int *const outTerminalId, const PtNodeParams *const ptNodeParams, int *const outTerminalId,
int *const ptNodeWritingPos) { int *const ptNodeWritingPos) {
@ -377,8 +350,7 @@ bool Ver4PatriciaTrieNodeWriter::writePtNodeAndGetTerminalIdAndAdvancePosition(
return false; return false;
} }
return updatePtNodeFlags(nodePos, ptNodeParams->isBlacklisted(), ptNodeParams->isNotAWord(), return updatePtNodeFlags(nodePos, ptNodeParams->isBlacklisted(), ptNodeParams->isNotAWord(),
isTerminal, ptNodeParams->hasShortcutTargets(), ptNodeParams->hasBigrams(), isTerminal, ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
} }
const ProbabilityEntry Ver4PatriciaTrieNodeWriter::createUpdatedEntryFrom( const ProbabilityEntry Ver4PatriciaTrieNodeWriter::createUpdatedEntryFrom(
@ -402,11 +374,11 @@ const ProbabilityEntry Ver4PatriciaTrieNodeWriter::createUpdatedEntryFrom(
bool Ver4PatriciaTrieNodeWriter::updatePtNodeFlags(const int ptNodePos, bool Ver4PatriciaTrieNodeWriter::updatePtNodeFlags(const int ptNodePos,
const bool isBlacklisted, const bool isNotAWord, const bool isTerminal, const bool isBlacklisted, const bool isNotAWord, const bool isTerminal,
const bool hasShortcutTargets, const bool hasBigrams, const bool hasMultipleChars) { const bool hasMultipleChars) {
// Create node flags and write them. // Create node flags and write them.
PatriciaTrieReadingUtils::NodeFlags nodeFlags = PatriciaTrieReadingUtils::NodeFlags nodeFlags =
PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord, isTerminal, PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord, isTerminal,
hasShortcutTargets, hasBigrams, hasMultipleChars, false /* hasShortcutTargets */, false /* hasBigrams */, hasMultipleChars,
CHILDREN_POSITION_FIELD_SIZE); CHILDREN_POSITION_FIELD_SIZE);
if (!DynamicPtWritingUtils::writeFlags(mTrieBuffer, nodeFlags, ptNodePos)) { if (!DynamicPtWritingUtils::writeFlags(mTrieBuffer, nodeFlags, ptNodePos)) {
AKLOGE("Cannot write PtNode flags. flags: %x, pos: %d", nodeFlags, ptNodePos); AKLOGE("Cannot write PtNode flags. flags: %x, pos: %d", nodeFlags, ptNodePos);

View File

@ -93,8 +93,6 @@ class Ver4PatriciaTrieNodeWriter : public PtNodeWriter {
const int *const targetCodePoints, const int targetCodePointCount, const int *const targetCodePoints, const int targetCodePointCount,
const int shortcutProbability); const int shortcutProbability);
bool updatePtNodeHasBigramsAndShortcutTargetsFlags(const PtNodeParams *const ptNodeParams);
private: private:
DISALLOW_COPY_AND_ASSIGN(Ver4PatriciaTrieNodeWriter); DISALLOW_COPY_AND_ASSIGN(Ver4PatriciaTrieNodeWriter);
@ -110,8 +108,7 @@ class Ver4PatriciaTrieNodeWriter : public PtNodeWriter {
const UnigramProperty *const unigramProperty) const; const UnigramProperty *const unigramProperty) const;
bool updatePtNodeFlags(const int ptNodePos, const bool isBlacklisted, const bool isNotAWord, bool updatePtNodeFlags(const int ptNodePos, const bool isBlacklisted, const bool isNotAWord,
const bool isTerminal, const bool hasShortcutTargets, const bool hasBigrams, const bool isTerminal, const bool hasMultipleChars);
const bool hasMultipleChars);
static const int CHILDREN_POSITION_FIELD_SIZE; static const int CHILDREN_POSITION_FIELD_SIZE;

View File

@ -286,8 +286,9 @@ bool Ver4PatriciaTrieWritingHelper::TraversePolicyToUpdateAllPtNodeFlagsAndTermi
} }
if (!mPtNodeWriter->updateTerminalId(ptNodeParams, it->second)) { if (!mPtNodeWriter->updateTerminalId(ptNodeParams, it->second)) {
AKLOGE("Cannot update terminal id. %d -> %d", it->first, it->second); AKLOGE("Cannot update terminal id. %d -> %d", it->first, it->second);
return false;
} }
return mPtNodeWriter->updatePtNodeHasBigramsAndShortcutTargetsFlags(ptNodeParams); return true;
} }
} // namespace latinime } // namespace latinime