Merge "Remove DicNode.getPtNodePos()."

This commit is contained in:
Keisuke Kuroyanagi 2014-09-05 10:15:44 +00:00 committed by Android (Google) Code Review
commit 3f779718cc
6 changed files with 20 additions and 36 deletions

View file

@ -135,15 +135,15 @@ class DicNode {
PROF_NODE_COPY(&parentDicNode->mProfiler, mProfiler); PROF_NODE_COPY(&parentDicNode->mProfiler, mProfiler);
} }
void initAsChild(const DicNode *const dicNode, const int ptNodePos, void initAsChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int childrenPtNodeArrayPos, const int probability, const int wordId, const int probability, const int wordId, const bool hasChildren,
const bool hasChildren, const bool isBlacklistedOrNotAWord, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount,
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { const int *const mergedNodeCodePoints) {
uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1); uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1);
mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion;
const uint16_t newLeavingDepth = static_cast<uint16_t>( const uint16_t newLeavingDepth = static_cast<uint16_t>(
dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount); dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount);
mDicNodeProperties.init(ptNodePos, childrenPtNodeArrayPos, mergedNodeCodePoints[0], mDicNodeProperties.init(childrenPtNodeArrayPos, mergedNodeCodePoints[0],
probability, wordId, hasChildren, isBlacklistedOrNotAWord, newDepth, probability, wordId, hasChildren, isBlacklistedOrNotAWord, newDepth,
newLeavingDepth, dicNode->mDicNodeProperties.getPrevWordIds()); newLeavingDepth, dicNode->mDicNodeProperties.getPrevWordIds());
mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount, mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount,
@ -208,11 +208,6 @@ class DicNode {
return mDicNodeProperties.getWordId(); return mDicNodeProperties.getWordId();
} }
// TODO: Remove
int getPtNodePos() const {
return mDicNodeProperties.getPtNodePos();
}
// TODO: Use view class to return word id array. // TODO: Use view class to return word id array.
const int *getPrevWordIds() const { const int *getPrevWordIds() const {
return mDicNodeProperties.getPrevWordIds(); return mDicNodeProperties.getPrevWordIds();

View file

@ -58,13 +58,13 @@ class DicNodeVector {
mDicNodes.back().initAsPassingChild(dicNode); mDicNodes.back().initAsPassingChild(dicNode);
} }
void pushLeavingChild(const DicNode *const dicNode, const int ptNodePos, void pushLeavingChild(const DicNode *const dicNode, const int childrenPtNodeArrayPos,
const int childrenPtNodeArrayPos, const int probability, const int wordId, const int probability, const int wordId, const bool hasChildren,
const bool hasChildren, const bool isBlacklistedOrNotAWord, const bool isBlacklistedOrNotAWord, const uint16_t mergedNodeCodePointCount,
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { const int *const mergedNodeCodePoints) {
ASSERT(!mLock); ASSERT(!mLock);
mDicNodes.emplace_back(); mDicNodes.emplace_back();
mDicNodes.back().initAsChild(dicNode, ptNodePos, childrenPtNodeArrayPos, probability, mDicNodes.back().initAsChild(dicNode, childrenPtNodeArrayPos, probability,
wordId, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount, wordId, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
mergedNodeCodePoints); mergedNodeCodePoints);
} }

View file

@ -29,18 +29,17 @@ namespace latinime {
class DicNodeProperties { class DicNodeProperties {
public: public:
AK_FORCE_INLINE DicNodeProperties() AK_FORCE_INLINE DicNodeProperties()
: mPtNodePos(NOT_A_DICT_POS), mChildrenPtNodeArrayPos(NOT_A_DICT_POS), : mChildrenPtNodeArrayPos(NOT_A_DICT_POS), mProbability(NOT_A_PROBABILITY),
mProbability(NOT_A_PROBABILITY), mDicNodeCodePoint(NOT_A_CODE_POINT), mDicNodeCodePoint(NOT_A_CODE_POINT), mWordId(NOT_A_WORD_ID),
mWordId(NOT_A_WORD_ID), mHasChildrenPtNodes(false), mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false), mDepth(0),
mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {} mLeavingDepth(0) {}
~DicNodeProperties() {} ~DicNodeProperties() {}
// Should be called only once per DicNode is initialized. // Should be called only once per DicNode is initialized.
void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability, void init(const int childrenPos, const int nodeCodePoint, const int probability,
const int wordId, const bool hasChildren, const bool isBlacklistedOrNotAWord, const int wordId, const bool hasChildren, const bool isBlacklistedOrNotAWord,
const uint16_t depth, const uint16_t leavingDepth, const int *const prevWordIds) { const uint16_t depth, const uint16_t leavingDepth, const int *const prevWordIds) {
mPtNodePos = pos;
mChildrenPtNodeArrayPos = childrenPos; mChildrenPtNodeArrayPos = childrenPos;
mDicNodeCodePoint = nodeCodePoint; mDicNodeCodePoint = nodeCodePoint;
mProbability = probability; mProbability = probability;
@ -54,7 +53,6 @@ class DicNodeProperties {
// Init for root with prevWordsPtNodePos which is used for n-gram // Init for root with prevWordsPtNodePos which is used for n-gram
void init(const int rootPtNodeArrayPos, const int *const prevWordIds) { void init(const int rootPtNodeArrayPos, const int *const prevWordIds) {
mPtNodePos = NOT_A_DICT_POS;
mChildrenPtNodeArrayPos = rootPtNodeArrayPos; mChildrenPtNodeArrayPos = rootPtNodeArrayPos;
mDicNodeCodePoint = NOT_A_CODE_POINT; mDicNodeCodePoint = NOT_A_CODE_POINT;
mProbability = NOT_A_PROBABILITY; mProbability = NOT_A_PROBABILITY;
@ -67,7 +65,6 @@ class DicNodeProperties {
} }
void initByCopy(const DicNodeProperties *const dicNodeProp) { void initByCopy(const DicNodeProperties *const dicNodeProp) {
mPtNodePos = dicNodeProp->mPtNodePos;
mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos; mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos;
mDicNodeCodePoint = dicNodeProp->mDicNodeCodePoint; mDicNodeCodePoint = dicNodeProp->mDicNodeCodePoint;
mProbability = dicNodeProp->mProbability; mProbability = dicNodeProp->mProbability;
@ -81,7 +78,6 @@ class DicNodeProperties {
// Init as passing child // Init as passing child
void init(const DicNodeProperties *const dicNodeProp, const int codePoint) { void init(const DicNodeProperties *const dicNodeProp, const int codePoint) {
mPtNodePos = dicNodeProp->mPtNodePos;
mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos; mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos;
mDicNodeCodePoint = codePoint; // Overwrite the node char of a passing child mDicNodeCodePoint = codePoint; // Overwrite the node char of a passing child
mProbability = dicNodeProp->mProbability; mProbability = dicNodeProp->mProbability;
@ -93,10 +89,6 @@ class DicNodeProperties {
memmove(mPrevWordIds, dicNodeProp->mPrevWordIds, sizeof(mPrevWordIds)); memmove(mPrevWordIds, dicNodeProp->mPrevWordIds, sizeof(mPrevWordIds));
} }
int getPtNodePos() const {
return mPtNodePos;
}
int getChildrenPtNodeArrayPos() const { int getChildrenPtNodeArrayPos() const {
return mChildrenPtNodeArrayPos; return mChildrenPtNodeArrayPos;
} }
@ -142,7 +134,6 @@ class DicNodeProperties {
// Caution!!! // Caution!!!
// Use a default copy constructor and an assign operator because shallow copies are ok // Use a default copy constructor and an assign operator because shallow copies are ok
// for this class // for this class
int mPtNodePos;
int mChildrenPtNodeArrayPos; int mChildrenPtNodeArrayPos;
int mProbability; int mProbability;
int mDicNodeCodePoint; int mDicNodeCodePoint;

View file

@ -77,9 +77,8 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
continue; continue;
} }
const int wordId = isTerminal ? ptNodeParams.getHeadPos() : NOT_A_WORD_ID; const int wordId = isTerminal ? ptNodeParams.getHeadPos() : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getHeadPos(), childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
ptNodeParams.getChildrenPos(), ptNodeParams.getProbability(), wordId, ptNodeParams.getProbability(), wordId, ptNodeParams.hasChildren(),
ptNodeParams.hasChildren(),
ptNodeParams.isBlacklisted() ptNodeParams.isBlacklisted()
|| ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */, || ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */,
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints()); ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());

View file

@ -377,7 +377,7 @@ int PatriciaTriePolicy::createAndGetLeavingChildNode(const DicNode *const dicNod
// Skip PtNodes don't start with Unicode code point because they represent non-word information. // Skip PtNodes don't start with Unicode code point because they represent non-word information.
if (CharUtils::isInUnicodeSpace(mergedNodeCodePoints[0])) { if (CharUtils::isInUnicodeSpace(mergedNodeCodePoints[0])) {
const int wordId = PatriciaTrieReadingUtils::isTerminal(flags) ? ptNodePos : NOT_A_WORD_ID; const int wordId = PatriciaTrieReadingUtils::isTerminal(flags) ? ptNodePos : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, ptNodePos, childrenPos, probability, wordId, childDicNodes->pushLeavingChild(dicNode, childrenPos, probability, wordId,
PatriciaTrieReadingUtils::hasChildrenInFlags(flags), PatriciaTrieReadingUtils::hasChildrenInFlags(flags),
PatriciaTrieReadingUtils::isBlacklisted(flags) PatriciaTrieReadingUtils::isBlacklisted(flags)
|| PatriciaTrieReadingUtils::isNotAWord(flags), || PatriciaTrieReadingUtils::isNotAWord(flags),

View file

@ -67,9 +67,8 @@ void Ver4PatriciaTriePolicy::createAndGetAllChildDicNodes(const DicNode *const d
continue; continue;
} }
const int wordId = isTerminal ? ptNodeParams.getTerminalId() : NOT_A_WORD_ID; const int wordId = isTerminal ? ptNodeParams.getTerminalId() : NOT_A_WORD_ID;
childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getHeadPos(), childDicNodes->pushLeavingChild(dicNode, ptNodeParams.getChildrenPos(),
ptNodeParams.getChildrenPos(), ptNodeParams.getProbability(), wordId, ptNodeParams.getProbability(), wordId, ptNodeParams.hasChildren(),
ptNodeParams.hasChildren(),
ptNodeParams.isBlacklisted() ptNodeParams.isBlacklisted()
|| ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */, || ptNodeParams.isNotAWord() /* isBlacklistedOrNotAWord */,
ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints()); ptNodeParams.getCodePointCount(), ptNodeParams.getCodePoints());