Use word id to get shortcut iterator.

Bug: 14425059
Change-Id: I1b35a139bd29f70b328cbc82648783b99f633d72
This commit is contained in:
Keisuke Kuroyanagi 2014-09-03 18:33:10 +09:00
parent 847a026cd8
commit ac983b13a9
8 changed files with 17 additions and 15 deletions

View file

@ -63,7 +63,7 @@ class DictionaryStructureWithBufferPolicy {
virtual void iterateNgramEntries(const int *const prevWordIds, virtual void iterateNgramEntries(const int *const prevWordIds,
NgramListener *const listener) const = 0; NgramListener *const listener) const = 0;
virtual BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const = 0; virtual BinaryDictionaryShortcutIterator getShortcutIterator(const int wordId) const = 0;
virtual const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const = 0; virtual const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const = 0;

View file

@ -141,7 +141,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
if (!terminalDicNode->hasMultipleWords()) { if (!terminalDicNode->hasMultipleWords()) {
BinaryDictionaryShortcutIterator shortcutIt = BinaryDictionaryShortcutIterator shortcutIt =
traverseSession->getDictionaryStructurePolicy()->getShortcutIterator( traverseSession->getDictionaryStructurePolicy()->getShortcutIterator(
terminalDicNode->getPtNodePos()); terminalDicNode->getWordId());
const bool sameAsTyped = scoringPolicy->sameAsTyped(traverseSession, terminalDicNode); const bool sameAsTyped = scoringPolicy->sameAsTyped(traverseSession, terminalDicNode);
outputShortcuts(&shortcutIt, finalScore, sameAsTyped, outSuggestionResults); outputShortcuts(&shortcutIt, finalScore, sameAsTyped, outSuggestionResults);
} }

View file

@ -175,8 +175,8 @@ void Ver4PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
} }
BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator( BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator(
const int ptNodePos) const { const int wordId) const {
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); const int shortcutPos = getShortcutPositionOfPtNode(getTerminalPtNodePosFromWordId(wordId));
return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos); return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos);
} }

View file

@ -97,7 +97,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const; void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const; BinaryDictionaryShortcutIterator getShortcutIterator(const int wordId) const;
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const { const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
return mHeaderPolicy; return mHeaderPolicy;

View file

@ -342,8 +342,8 @@ void PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
} }
BinaryDictionaryShortcutIterator PatriciaTriePolicy::getShortcutIterator( BinaryDictionaryShortcutIterator PatriciaTriePolicy::getShortcutIterator(
const int ptNodePos) const { const int wordId) const {
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); const int shortcutPos = getShortcutPositionOfPtNode(getTerminalPtNodePosFromWordId(wordId));
return BinaryDictionaryShortcutIterator(&mShortcutListPolicy, shortcutPos); return BinaryDictionaryShortcutIterator(&mShortcutListPolicy, shortcutPos);
} }

View file

@ -72,7 +72,7 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const; void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const; BinaryDictionaryShortcutIterator getShortcutIterator(const int wordId) const;
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const { const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
return &mHeaderPolicy; return &mHeaderPolicy;

View file

@ -157,8 +157,8 @@ int Ver4PatriciaTriePolicy::getProbabilityOfWord(const int *const prevWordIds,
} }
BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator( BinaryDictionaryShortcutIterator Ver4PatriciaTriePolicy::getShortcutIterator(
const int ptNodePos) const { const int wordId) const {
const int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); const int shortcutPos = getShortcutPositionOfWord(wordId);
return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos); return BinaryDictionaryShortcutIterator(&mShortcutPolicy, shortcutPos);
} }
@ -180,10 +180,12 @@ void Ver4PatriciaTriePolicy::iterateNgramEntries(const int *const prevWordIds,
} }
} }
int Ver4PatriciaTriePolicy::getShortcutPositionOfPtNode(const int ptNodePos) const { int Ver4PatriciaTriePolicy::getShortcutPositionOfWord(const int wordId) const {
if (ptNodePos == NOT_A_DICT_POS) { if (wordId == NOT_A_WORD_ID) {
return NOT_A_DICT_POS; return NOT_A_DICT_POS;
} }
const int ptNodePos =
mBuffers->getTerminalPositionLookupTable()->getTerminalPtNodePosition(wordId);
const PtNodeParams ptNodeParams(mNodeReader.fetchPtNodeParamsInBufferFromPtNodePos(ptNodePos)); const PtNodeParams ptNodeParams(mNodeReader.fetchPtNodeParamsInBufferFromPtNodePos(ptNodePos));
if (ptNodeParams.isDeleted()) { if (ptNodeParams.isDeleted()) {
return NOT_A_DICT_POS; return NOT_A_DICT_POS;
@ -511,7 +513,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(
} }
// Fetch shortcut information. // Fetch shortcut information.
std::vector<UnigramProperty::ShortcutProperty> shortcuts; std::vector<UnigramProperty::ShortcutProperty> shortcuts;
int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); int shortcutPos = getShortcutPositionOfWord(wordId);
if (shortcutPos != NOT_A_DICT_POS) { if (shortcutPos != NOT_A_DICT_POS) {
int shortcutTarget[MAX_WORD_LENGTH]; int shortcutTarget[MAX_WORD_LENGTH];
const ShortcutDictContent *const shortcutDictContent = const ShortcutDictContent *const shortcutDictContent =

View file

@ -74,7 +74,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const; void iterateNgramEntries(const int *const prevWordIds, NgramListener *const listener) const;
BinaryDictionaryShortcutIterator getShortcutIterator(const int ptNodePos) const; BinaryDictionaryShortcutIterator getShortcutIterator(const int wordId) const;
const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const { const DictionaryHeaderStructurePolicy *getHeaderStructurePolicy() const {
return mHeaderPolicy; return mHeaderPolicy;
@ -135,7 +135,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
std::vector<int> mTerminalPtNodePositionsForIteratingWords; std::vector<int> mTerminalPtNodePositionsForIteratingWords;
mutable bool mIsCorrupted; mutable bool mIsCorrupted;
int getShortcutPositionOfPtNode(const int ptNodePos) const; int getShortcutPositionOfWord(const int wordId) const;
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_VER4_PATRICIA_TRIE_POLICY_H #endif // LATINIME_VER4_PATRICIA_TRIE_POLICY_H