Loading native/jni/src/suggest/core/dicnode/dic_node.h +12 −18 Original line number Diff line number Diff line Loading @@ -112,10 +112,10 @@ class DicNode { mIsUsed = true; mIsCachedForNextSuggestion = false; mDicNodeProperties.init( NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); mDicNodeState.init(prevWordNodePos); PROF_NODE_RESET(mProfiler); } Loading @@ -125,10 +125,10 @@ class DicNode { mIsUsed = true; mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; mDicNodeProperties.init( NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); // TODO: Move to dicNodeState? mDicNodeState.mDicNodeStateOutput.init(); // reset for next word mDicNodeState.mDicNodeStateInput.init( Loading Loading @@ -157,18 +157,16 @@ class DicNode { PROF_NODE_COPY(&parentNode->mProfiler, mProfiler); } void initAsChild(DicNode *dicNode, const int pos, const int childrenPos, const int attributesPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, void initAsChild(DicNode *dicNode, const int pos, const int childrenPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { mIsUsed = true; uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1); mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; const uint16_t newLeavingDepth = static_cast<uint16_t>( dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount); mDicNodeProperties.init(pos, childrenPos, attributesPos, mergedNodeCodePoints[0], probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, newDepth, newLeavingDepth); mDicNodeProperties.init(pos, childrenPos, mergedNodeCodePoints[0], probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, newDepth, newLeavingDepth); mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount, mergedNodeCodePoints); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); Loading Loading @@ -467,10 +465,6 @@ class DicNode { return mDicNodeProperties.isBlacklistedOrNotAWord(); } int getAttributesPos() const { return mDicNodeProperties.getAttributesPos(); } inline uint16_t getNodeCodePointCount() const { return mDicNodeProperties.getDepth(); } Loading native/jni/src/suggest/core/dicnode/dic_node_properties.h +4 −14 Original line number Diff line number Diff line Loading @@ -31,20 +31,17 @@ namespace latinime { class DicNodeProperties { public: AK_FORCE_INLINE DicNodeProperties() : mPos(0), mChildrenPos(0), mAttributesPos(0), mProbability(0), mNodeCodePoint(0), mIsTerminal(false), mHasChildren(false), mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {} : mPos(0), mChildrenPos(0), mProbability(0), mNodeCodePoint(0), mIsTerminal(false), mHasChildren(false), mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {} virtual ~DicNodeProperties() {} // Should be called only once per DicNode is initialized. void init(const int pos, const int childrenPos, const int attributesPos, const int nodeCodePoint, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t depth, const uint16_t leavingDepth) { mPos = pos; mChildrenPos = childrenPos; mAttributesPos = attributesPos; mNodeCodePoint = nodeCodePoint; mProbability = probability; mIsTerminal = isTerminal; Loading @@ -58,7 +55,6 @@ class DicNodeProperties { void init(const DicNodeProperties *const nodeProp) { mPos = nodeProp->mPos; mChildrenPos = nodeProp->mChildrenPos; mAttributesPos = nodeProp->mAttributesPos; mNodeCodePoint = nodeProp->mNodeCodePoint; mProbability = nodeProp->mProbability; mIsTerminal = nodeProp->mIsTerminal; Loading @@ -72,7 +68,6 @@ class DicNodeProperties { void init(const DicNodeProperties *const nodeProp, const int codePoint) { mPos = nodeProp->mPos; mChildrenPos = nodeProp->mChildrenPos; mAttributesPos = nodeProp->mAttributesPos; mNodeCodePoint = codePoint; // Overwrite the node char of a passing child mProbability = nodeProp->mProbability; mIsTerminal = nodeProp->mIsTerminal; Loading @@ -90,10 +85,6 @@ class DicNodeProperties { return mChildrenPos; } int getAttributesPos() const { return mAttributesPos; } int getProbability() const { return mProbability; } Loading Loading @@ -129,7 +120,6 @@ class DicNodeProperties { // for this class int mPos; int mChildrenPos; int mAttributesPos; int mProbability; int mNodeCodePoint; bool mIsTerminal; Loading native/jni/src/suggest/core/dicnode/dic_node_utils.cpp +2 −6 Original line number Diff line number Diff line Loading @@ -77,7 +77,6 @@ namespace latinime { const bool hasMultipleChars = (0 != (BinaryFormat::FLAG_HAS_MULTIPLE_CHARS & flags)); const bool isTerminal = (0 != (BinaryFormat::FLAG_IS_TERMINAL & flags)); const bool hasChildren = BinaryFormat::hasChildrenInFlags(flags); const bool hasShortcuts = (0 != (BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS & flags)); const bool isBlacklistedOrNotAWord = BinaryFormat::hasBlacklistedOrNotAWordFlag(flags); int codePoint = BinaryFormat::getCodePointAndForwardPointer( Loading @@ -104,17 +103,14 @@ namespace latinime { pos = BinaryFormat::skipProbability(flags, pos); int childrenPos = hasChildren ? BinaryFormat::readChildrenPosition( binaryDictionaryInfo->getDictRoot(), flags, pos) : NOT_A_DICT_POS; const int attributesPos = hasShortcuts ? BinaryFormat::skipChildrenPosition(flags, pos) : NOT_A_DICT_POS; const int siblingPos = BinaryFormat::skipChildrenPosAndAttributes( binaryDictionaryInfo->getDictRoot(), flags, pos); if (childrenFilter->isFilteredOut(mergedNodeCodePoints[0])) { return siblingPos; } childDicNodes->pushLeavingChild(dicNode, nextPos, childrenPos, attributesPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); childDicNodes->pushLeavingChild(dicNode, nextPos, childrenPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); return siblingPos; } Loading native/jni/src/suggest/core/dicnode/dic_node_vector.h +5 −5 Original line number Diff line number Diff line Loading @@ -63,13 +63,13 @@ class DicNodeVector { } void pushLeavingChild(DicNode *dicNode, const int pos, const int childrenPos, const int attributesPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { ASSERT(!mLock); mDicNodes.push_back(mEmptyNode); mDicNodes.back().initAsChild(dicNode, pos, childrenPos, attributesPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mDicNodes.back().initAsChild(dicNode, pos, childrenPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); } Loading native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -109,13 +109,13 @@ int BigramDictionary::getPredictions(const int *prevWord, int prevWordLength, in int pos = getBigramListPositionForWord(prevWord, prevWordLength, false /* forceLowerCaseSearch */); // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams if (0 == pos) { if (NOT_A_DICT_POS == pos) { // If no bigrams for this exact word, search again in lower case. pos = getBigramListPositionForWord(prevWord, prevWordLength, true /* forceLowerCaseSearch */); } // If still no bigrams, we really don't have them! if (0 == pos) return 0; if (NOT_A_DICT_POS == pos) return 0; int bigramCount = 0; int unigramProbability = 0; Loading Loading @@ -154,8 +154,8 @@ int BigramDictionary::getBigramListPositionForWord(const int *prevWord, const in int pos = mBinaryDictionaryInfo->getStructurePolicy()->getTerminalNodePositionOfWord( mBinaryDictionaryInfo, prevWord, prevWordLength, forceLowerCaseSearch); if (NOT_A_VALID_WORD_POS == pos) return 0; return BinaryFormat::getBigramListPositionForWordPosition( mBinaryDictionaryInfo->getDictRoot(), pos); return mBinaryDictionaryInfo->getStructurePolicy()->getBigramsPositionOfNode( mBinaryDictionaryInfo, pos); } bool BigramDictionary::checkFirstCharacter(int *word, int *inputCodePoints) const { Loading @@ -178,7 +178,7 @@ bool BigramDictionary::isValidBigram(const int *word0, int length0, const int *w int length1) const { int pos = getBigramListPositionForWord(word0, length0, false /* forceLowerCaseSearch */); // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams if (0 == pos) return false; if (NOT_A_DICT_POS == pos) return false; int nextWordPos = mBinaryDictionaryInfo->getStructurePolicy()->getTerminalNodePositionOfWord( mBinaryDictionaryInfo, word1, length1, false /* forceLowerCaseSearch */); if (NOT_A_VALID_WORD_POS == nextWordPos) return false; Loading Loading
native/jni/src/suggest/core/dicnode/dic_node.h +12 −18 Original line number Diff line number Diff line Loading @@ -112,10 +112,10 @@ class DicNode { mIsUsed = true; mIsCachedForNextSuggestion = false; mDicNodeProperties.init( NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); mDicNodeState.init(prevWordNodePos); PROF_NODE_RESET(mProfiler); } Loading @@ -125,10 +125,10 @@ class DicNode { mIsUsed = true; mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; mDicNodeProperties.init( NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); NOT_A_VALID_WORD_POS /* pos */, rootGroupPos, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */, false /* isTerminal */, true /* hasChildren */, false /* isBlacklistedOrNotAWord */, 0 /* depth */, 0 /* terminalDepth */); // TODO: Move to dicNodeState? mDicNodeState.mDicNodeStateOutput.init(); // reset for next word mDicNodeState.mDicNodeStateInput.init( Loading Loading @@ -157,18 +157,16 @@ class DicNode { PROF_NODE_COPY(&parentNode->mProfiler, mProfiler); } void initAsChild(DicNode *dicNode, const int pos, const int childrenPos, const int attributesPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, void initAsChild(DicNode *dicNode, const int pos, const int childrenPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { mIsUsed = true; uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1); mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; const uint16_t newLeavingDepth = static_cast<uint16_t>( dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount); mDicNodeProperties.init(pos, childrenPos, attributesPos, mergedNodeCodePoints[0], probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, newDepth, newLeavingDepth); mDicNodeProperties.init(pos, childrenPos, mergedNodeCodePoints[0], probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, newDepth, newLeavingDepth); mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount, mergedNodeCodePoints); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); Loading Loading @@ -467,10 +465,6 @@ class DicNode { return mDicNodeProperties.isBlacklistedOrNotAWord(); } int getAttributesPos() const { return mDicNodeProperties.getAttributesPos(); } inline uint16_t getNodeCodePointCount() const { return mDicNodeProperties.getDepth(); } Loading
native/jni/src/suggest/core/dicnode/dic_node_properties.h +4 −14 Original line number Diff line number Diff line Loading @@ -31,20 +31,17 @@ namespace latinime { class DicNodeProperties { public: AK_FORCE_INLINE DicNodeProperties() : mPos(0), mChildrenPos(0), mAttributesPos(0), mProbability(0), mNodeCodePoint(0), mIsTerminal(false), mHasChildren(false), mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {} : mPos(0), mChildrenPos(0), mProbability(0), mNodeCodePoint(0), mIsTerminal(false), mHasChildren(false), mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {} virtual ~DicNodeProperties() {} // Should be called only once per DicNode is initialized. void init(const int pos, const int childrenPos, const int attributesPos, const int nodeCodePoint, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t depth, const uint16_t leavingDepth) { mPos = pos; mChildrenPos = childrenPos; mAttributesPos = attributesPos; mNodeCodePoint = nodeCodePoint; mProbability = probability; mIsTerminal = isTerminal; Loading @@ -58,7 +55,6 @@ class DicNodeProperties { void init(const DicNodeProperties *const nodeProp) { mPos = nodeProp->mPos; mChildrenPos = nodeProp->mChildrenPos; mAttributesPos = nodeProp->mAttributesPos; mNodeCodePoint = nodeProp->mNodeCodePoint; mProbability = nodeProp->mProbability; mIsTerminal = nodeProp->mIsTerminal; Loading @@ -72,7 +68,6 @@ class DicNodeProperties { void init(const DicNodeProperties *const nodeProp, const int codePoint) { mPos = nodeProp->mPos; mChildrenPos = nodeProp->mChildrenPos; mAttributesPos = nodeProp->mAttributesPos; mNodeCodePoint = codePoint; // Overwrite the node char of a passing child mProbability = nodeProp->mProbability; mIsTerminal = nodeProp->mIsTerminal; Loading @@ -90,10 +85,6 @@ class DicNodeProperties { return mChildrenPos; } int getAttributesPos() const { return mAttributesPos; } int getProbability() const { return mProbability; } Loading Loading @@ -129,7 +120,6 @@ class DicNodeProperties { // for this class int mPos; int mChildrenPos; int mAttributesPos; int mProbability; int mNodeCodePoint; bool mIsTerminal; Loading
native/jni/src/suggest/core/dicnode/dic_node_utils.cpp +2 −6 Original line number Diff line number Diff line Loading @@ -77,7 +77,6 @@ namespace latinime { const bool hasMultipleChars = (0 != (BinaryFormat::FLAG_HAS_MULTIPLE_CHARS & flags)); const bool isTerminal = (0 != (BinaryFormat::FLAG_IS_TERMINAL & flags)); const bool hasChildren = BinaryFormat::hasChildrenInFlags(flags); const bool hasShortcuts = (0 != (BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS & flags)); const bool isBlacklistedOrNotAWord = BinaryFormat::hasBlacklistedOrNotAWordFlag(flags); int codePoint = BinaryFormat::getCodePointAndForwardPointer( Loading @@ -104,17 +103,14 @@ namespace latinime { pos = BinaryFormat::skipProbability(flags, pos); int childrenPos = hasChildren ? BinaryFormat::readChildrenPosition( binaryDictionaryInfo->getDictRoot(), flags, pos) : NOT_A_DICT_POS; const int attributesPos = hasShortcuts ? BinaryFormat::skipChildrenPosition(flags, pos) : NOT_A_DICT_POS; const int siblingPos = BinaryFormat::skipChildrenPosAndAttributes( binaryDictionaryInfo->getDictRoot(), flags, pos); if (childrenFilter->isFilteredOut(mergedNodeCodePoints[0])) { return siblingPos; } childDicNodes->pushLeavingChild(dicNode, nextPos, childrenPos, attributesPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); childDicNodes->pushLeavingChild(dicNode, nextPos, childrenPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); return siblingPos; } Loading
native/jni/src/suggest/core/dicnode/dic_node_vector.h +5 −5 Original line number Diff line number Diff line Loading @@ -63,13 +63,13 @@ class DicNodeVector { } void pushLeavingChild(DicNode *dicNode, const int pos, const int childrenPos, const int attributesPos, const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { const int probability, const bool isTerminal, const bool hasChildren, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { ASSERT(!mLock); mDicNodes.push_back(mEmptyNode); mDicNodes.back().initAsChild(dicNode, pos, childrenPos, attributesPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mDicNodes.back().initAsChild(dicNode, pos, childrenPos, probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, mergedNodeCodePoints); } Loading
native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -109,13 +109,13 @@ int BigramDictionary::getPredictions(const int *prevWord, int prevWordLength, in int pos = getBigramListPositionForWord(prevWord, prevWordLength, false /* forceLowerCaseSearch */); // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams if (0 == pos) { if (NOT_A_DICT_POS == pos) { // If no bigrams for this exact word, search again in lower case. pos = getBigramListPositionForWord(prevWord, prevWordLength, true /* forceLowerCaseSearch */); } // If still no bigrams, we really don't have them! if (0 == pos) return 0; if (NOT_A_DICT_POS == pos) return 0; int bigramCount = 0; int unigramProbability = 0; Loading Loading @@ -154,8 +154,8 @@ int BigramDictionary::getBigramListPositionForWord(const int *prevWord, const in int pos = mBinaryDictionaryInfo->getStructurePolicy()->getTerminalNodePositionOfWord( mBinaryDictionaryInfo, prevWord, prevWordLength, forceLowerCaseSearch); if (NOT_A_VALID_WORD_POS == pos) return 0; return BinaryFormat::getBigramListPositionForWordPosition( mBinaryDictionaryInfo->getDictRoot(), pos); return mBinaryDictionaryInfo->getStructurePolicy()->getBigramsPositionOfNode( mBinaryDictionaryInfo, pos); } bool BigramDictionary::checkFirstCharacter(int *word, int *inputCodePoints) const { Loading @@ -178,7 +178,7 @@ bool BigramDictionary::isValidBigram(const int *word0, int length0, const int *w int length1) const { int pos = getBigramListPositionForWord(word0, length0, false /* forceLowerCaseSearch */); // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams if (0 == pos) return false; if (NOT_A_DICT_POS == pos) return false; int nextWordPos = mBinaryDictionaryInfo->getStructurePolicy()->getTerminalNodePositionOfWord( mBinaryDictionaryInfo, word1, length1, false /* forceLowerCaseSearch */); if (NOT_A_VALID_WORD_POS == nextWordPos) return false; Loading