mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Make dictionary structure policy return shortcut iterator.
Bug: 14425059 Change-Id: I0da22c41f818673430c285103af340397aaba9fb
This commit is contained in:
parent
972003428b
commit
847a026cd8
@ -31,6 +31,11 @@ class BinaryDictionaryShortcutIterator {
|
||||
mPos(shortcutStructurePolicy->getStartPos(shortcutPos)),
|
||||
mHasNextShortcutTarget(shortcutPos != NOT_A_DICT_POS) {}
|
||||
|
||||
BinaryDictionaryShortcutIterator(const BinaryDictionaryShortcutIterator &&shortcutIterator)
|
||||
: mShortcutStructurePolicy(shortcutIterator.mShortcutStructurePolicy),
|
||||
mPos(shortcutIterator.mPos),
|
||||
mHasNextShortcutTarget(shortcutIterator.mHasNextShortcutTarget) {}
|
||||
|
||||
AK_FORCE_INLINE bool hasNextShortcutTarget() const {
|
||||
return mHasNextShortcutTarget;
|
||||
}
|
||||
@ -45,7 +50,8 @@ class BinaryDictionaryShortcutIterator {
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryShortcutIterator);
|
||||
DISALLOW_DEFAULT_CONSTRUCTOR(BinaryDictionaryShortcutIterator);
|
||||
DISALLOW_ASSIGNMENT_OPERATOR(BinaryDictionaryShortcutIterator);
|
||||
|
||||
const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
|
||||
int mPos;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"
|
||||
#include "suggest/core/dictionary/property/word_property.h"
|
||||
#include "utils/int_array_view.h"
|
||||
|
||||
@ -28,7 +29,6 @@ namespace latinime {
|
||||
class DicNode;
|
||||
class DicNodeVector;
|
||||
class DictionaryHeaderStructurePolicy;
|
||||
class DictionaryShortcutsStructurePolicy;
|
||||
class NgramListener;
|
||||
class PrevWordsInfo;
|
||||
class UnigramProperty;
|
||||
@ -63,12 +63,10 @@ class DictionaryStructureWithBufferPolicy {
|
||||
virtual void iterateNgramEntries(const int *const prevWordIds,
|
||||
NgramListener *const listener) const = 0;
|
||||
|
||||
virtual int getShortcutPositionOfPtNode(const int ptNodePos) const = 0;
|
||||
virtual BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const = 0;
|
||||
|
||||
virtual const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const = 0;
|
||||
|
||||
virtual const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const = 0;
|
||||
|
||||
// Returns whether the update was success or not.
|
||||
virtual bool addUnigramEntry(const CodePointArrayView wordCodePoints,
|
||||
const UnigramProperty *const unigramProperty) = 0;
|
||||
|
@ -139,10 +139,9 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
|
||||
// Shortcut is not supported for multiple words suggestions.
|
||||
// TODO: Check shortcuts during traversal for multiple words suggestions.
|
||||
if (!terminalDicNode->hasMultipleWords()) {
|
||||
BinaryDictionaryShortcutIterator shortcutIt(
|
||||
traverseSession->getDictionaryStructurePolicy()->getShortcutsStructurePolicy(),
|
||||
traverseSession->getDictionaryStructurePolicy()
|
||||
->getShortcutPositionOfPtNode(terminalDicNode->getPtNodePos()));
|
||||
BinaryDictionaryShortcutIterator shortcutIt =
|
||||
traverseSession->getDictionaryStructurePolicy()->getShortcutIterator(
|
||||
terminalDicNode->getPtNodePos());
|
||||
const bool sameAsTyped = scoringPolicy->sameAsTyped(traverseSession, terminalDicNode);
|
||||
outputShortcuts(&shortcutIt, finalScore, sameAsTyped, outSuggestionResults);
|
||||
}
|
||||
|
@ -174,6 +174,12 @@ void Ver4PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
|
||||
}
|
||||
}
|
||||
|
||||
BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator(
|
||||
const int ptNodePos) const {
|
||||
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
|
||||
return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos);
|
||||
}
|
||||
|
||||
int Ver4PatriciaTriePolicy::getShortcutPositionOfPtNode(const int ptNodePos) const {
|
||||
if (ptNodePos == NOT_A_DICT_POS) {
|
||||
return NOT_A_DICT_POS;
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h"
|
||||
#include "suggest/core/dictionary/binary_dictionary_shortcut_iterator.h"
|
||||
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
|
||||
#include "suggest/policyimpl/dictionary/header/header_policy.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_updating_helper.h"
|
||||
@ -96,16 +97,12 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
|
||||
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
|
||||
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const;
|
||||
|
||||
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
|
||||
return mHeaderPolicy;
|
||||
}
|
||||
|
||||
const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const {
|
||||
return &mShortcutPolicy;
|
||||
}
|
||||
|
||||
bool addUnigramEntry(const CodePointArrayView wordCodePoints,
|
||||
const UnigramProperty *const unigramProperty);
|
||||
|
||||
@ -163,6 +160,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
mutable bool mIsCorrupted;
|
||||
|
||||
int getBigramsPositionOfPtNode(const int ptNodePos) const;
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
int getWordIdFromTerminalPtNodePos(const int ptNodePos) const;
|
||||
int getTerminalPtNodePosFromWordId(const int wordId) const;
|
||||
};
|
||||
|
@ -341,6 +341,12 @@ void PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
|
||||
}
|
||||
}
|
||||
|
||||
BinaryDictionaryShortcutIterator PatriciaTriePolicy::getShortcutIterator(
|
||||
const int ptNodePos) const {
|
||||
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
|
||||
return BinaryDictionaryShortcutIterator(&mShortcutListPolicy, shortcutPos);
|
||||
}
|
||||
|
||||
int PatriciaTriePolicy::getShortcutPositionOfPtNode(const int ptNodePos) const {
|
||||
if (ptNodePos == NOT_A_DICT_POS) {
|
||||
return NOT_A_DICT_POS;
|
||||
@ -365,7 +371,7 @@ int PatriciaTriePolicy::createAndGetLeavingChildNode(const DicNode *const dicNod
|
||||
int shortcutPos = NOT_A_DICT_POS;
|
||||
int bigramPos = NOT_A_DICT_POS;
|
||||
int siblingPos = NOT_A_DICT_POS;
|
||||
PatriciaTrieReadingUtils::readPtNodeInfo(mDictRoot, ptNodePos, getShortcutsStructurePolicy(),
|
||||
PatriciaTrieReadingUtils::readPtNodeInfo(mDictRoot, ptNodePos, &mShortcutListPolicy,
|
||||
&mBigramListPolicy, &flags, &mergedNodeCodePointCount, mergedNodeCodePoints,
|
||||
&probability, &childrenPos, &shortcutPos, &bigramPos, &siblingPos);
|
||||
// Skip PtNodes don't start with Unicode code point because they represent non-word information.
|
||||
|
@ -72,16 +72,12 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
|
||||
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
|
||||
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const;
|
||||
|
||||
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
|
||||
return &mHeaderPolicy;
|
||||
}
|
||||
|
||||
const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const {
|
||||
return &mShortcutListPolicy;
|
||||
}
|
||||
|
||||
bool addUnigramEntry(const CodePointArrayView wordCodePoints,
|
||||
const UnigramProperty *const unigramProperty) {
|
||||
// This method should not be called for non-updatable dictionary.
|
||||
@ -158,6 +154,7 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
std::vector<int> mTerminalPtNodePositionsForIteratingWords;
|
||||
mutable bool mIsCorrupted;
|
||||
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
int getBigramsPositionOfPtNode(const int ptNodePos) const;
|
||||
int createAndGetLeavingChildNode(const DicNode *const dicNode, const int ptNodePos,
|
||||
DicNodeVector *const childDicNodes) const;
|
||||
|
@ -156,6 +156,12 @@ int Ver4PatriciaTriePolicy::getProbabilityOfWord(const int *const prevWordIds,
|
||||
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
||||
}
|
||||
|
||||
BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator(
|
||||
const int ptNodePos) const {
|
||||
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
|
||||
return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos);
|
||||
}
|
||||
|
||||
void Ver4PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
|
||||
NgramListener *const listener) const {
|
||||
if (!prevWordIds) {
|
||||
|
@ -74,16 +74,12 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
|
||||
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
|
||||
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const;
|
||||
|
||||
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
|
||||
return mHeaderPolicy;
|
||||
}
|
||||
|
||||
const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const {
|
||||
return &mShortcutPolicy;
|
||||
}
|
||||
|
||||
bool addUnigramEntry(const CodePointArrayView wordCodePoints,
|
||||
const UnigramProperty *const unigramProperty);
|
||||
|
||||
@ -138,6 +134,8 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||
int mBigramCount;
|
||||
std::vector<int> mTerminalPtNodePositionsForIteratingWords;
|
||||
mutable bool mIsCorrupted;
|
||||
|
||||
int getShortcutPositionOfPtNode(const int ptNodePos) const;
|
||||
};
|
||||
} // namespace latinime
|
||||
#endif // LATINIME_VER4_PATRICIA_TRIE_POLICY_H
|
||||
|
Loading…
Reference in New Issue
Block a user