mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Remove hasBigrams/hasShortcut flags from ver4 PtNode."
This commit is contained in:
commit
a807663aae
@ -65,7 +65,7 @@ bool DynamicPtGcEventListeners
|
||||
|
||||
bool DynamicPtGcEventListeners::TraversePolicyToUpdateBigramProbability
|
||||
::onVisitingPtNode(const PtNodeParams *const ptNodeParams) {
|
||||
if (!ptNodeParams->isDeleted() && ptNodeParams->hasBigrams()) {
|
||||
if (!ptNodeParams->isDeleted()) {
|
||||
int bigramEntryCount = 0;
|
||||
if (!mPtNodeWriter->updateAllBigramEntriesAndDeleteUselessEntries(ptNodeParams,
|
||||
&bigramEntryCount)) {
|
||||
|
@ -270,8 +270,8 @@ const PtNodeParams DynamicPtUpdatingHelper::getUpdatedPtNodeParams(
|
||||
const bool isNotAWord, const bool isBlacklisted, const bool isTerminal, const int parentPos,
|
||||
const int codePointCount, const int *const codePoints, const int probability) const {
|
||||
const PatriciaTrieReadingUtils::NodeFlags flags = PatriciaTrieReadingUtils::createAndGetFlags(
|
||||
isBlacklisted, isNotAWord, isTerminal, originalPtNodeParams->hasShortcutTargets(),
|
||||
originalPtNodeParams->hasBigrams(), codePointCount > 1 /* hasMultipleChars */,
|
||||
isBlacklisted, isNotAWord, isTerminal, false /* hasShortcutTargets */,
|
||||
false /* hasBigrams */, codePointCount > 1 /* hasMultipleChars */,
|
||||
CHILDREN_POSITION_FIELD_SIZE);
|
||||
return PtNodeParams(originalPtNodeParams, flags, parentPos, codePointCount, codePoints,
|
||||
probability);
|
||||
|
@ -231,14 +231,6 @@ bool Ver4PatriciaTrieNodeWriter::addNewBigramEntry(
|
||||
sourcePtNodeParams->getTerminalId(), targetPtNodeParam->getTerminalId());
|
||||
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;
|
||||
}
|
||||
|
||||
@ -303,28 +295,9 @@ bool Ver4PatriciaTrieNodeWriter::addShortcutTarget(const PtNodeParams *const ptN
|
||||
AKLOGE("Cannot add new shortuct entry. terminalId: %d", ptNodeParams->getTerminalId());
|
||||
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;
|
||||
}
|
||||
|
||||
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(
|
||||
const PtNodeParams *const ptNodeParams, int *const outTerminalId,
|
||||
int *const ptNodeWritingPos) {
|
||||
@ -377,8 +350,7 @@ bool Ver4PatriciaTrieNodeWriter::writePtNodeAndGetTerminalIdAndAdvancePosition(
|
||||
return false;
|
||||
}
|
||||
return updatePtNodeFlags(nodePos, ptNodeParams->isBlacklisted(), ptNodeParams->isNotAWord(),
|
||||
isTerminal, ptNodeParams->hasShortcutTargets(), ptNodeParams->hasBigrams(),
|
||||
ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
|
||||
isTerminal, ptNodeParams->getCodePointCount() > 1 /* hasMultipleChars */);
|
||||
}
|
||||
|
||||
const ProbabilityEntry Ver4PatriciaTrieNodeWriter::createUpdatedEntryFrom(
|
||||
@ -402,11 +374,11 @@ const ProbabilityEntry Ver4PatriciaTrieNodeWriter::createUpdatedEntryFrom(
|
||||
|
||||
bool Ver4PatriciaTrieNodeWriter::updatePtNodeFlags(const int ptNodePos,
|
||||
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.
|
||||
PatriciaTrieReadingUtils::NodeFlags nodeFlags =
|
||||
PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord, isTerminal,
|
||||
hasShortcutTargets, hasBigrams, hasMultipleChars,
|
||||
false /* hasShortcutTargets */, false /* hasBigrams */, hasMultipleChars,
|
||||
CHILDREN_POSITION_FIELD_SIZE);
|
||||
if (!DynamicPtWritingUtils::writeFlags(mTrieBuffer, nodeFlags, ptNodePos)) {
|
||||
AKLOGE("Cannot write PtNode flags. flags: %x, pos: %d", nodeFlags, ptNodePos);
|
||||
|
@ -93,8 +93,6 @@ class Ver4PatriciaTrieNodeWriter : public PtNodeWriter {
|
||||
const int *const targetCodePoints, const int targetCodePointCount,
|
||||
const int shortcutProbability);
|
||||
|
||||
bool updatePtNodeHasBigramsAndShortcutTargetsFlags(const PtNodeParams *const ptNodeParams);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Ver4PatriciaTrieNodeWriter);
|
||||
|
||||
@ -110,8 +108,7 @@ class Ver4PatriciaTrieNodeWriter : public PtNodeWriter {
|
||||
const UnigramProperty *const unigramProperty) const;
|
||||
|
||||
bool updatePtNodeFlags(const int ptNodePos, const bool isBlacklisted, const bool isNotAWord,
|
||||
const bool isTerminal, const bool hasShortcutTargets, const bool hasBigrams,
|
||||
const bool hasMultipleChars);
|
||||
const bool isTerminal, const bool hasMultipleChars);
|
||||
|
||||
static const int CHILDREN_POSITION_FIELD_SIZE;
|
||||
|
||||
|
@ -286,8 +286,9 @@ bool Ver4PatriciaTrieWritingHelper::TraversePolicyToUpdateAllPtNodeFlagsAndTermi
|
||||
}
|
||||
if (!mPtNodeWriter->updateTerminalId(ptNodeParams, it->second)) {
|
||||
AKLOGE("Cannot update terminal id. %d -> %d", it->first, it->second);
|
||||
return false;
|
||||
}
|
||||
return mPtNodeWriter->updatePtNodeHasBigramsAndShortcutTargetsFlags(ptNodeParams);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace latinime
|
||||
|
Loading…
Reference in New Issue
Block a user