am bd44c981: Merge "Improve DicNode handling."

* commit 'bd44c9815d0a4d7f411d6160ccd512b0303f0d25':
  Improve DicNode handling.
main
Keisuke Kuroyanagi 2014-03-10 02:23:44 -07:00 committed by Android Git Automerger
commit 07195e92c5
8 changed files with 35 additions and 45 deletions

View File

@ -97,7 +97,7 @@ class DicNode {
DicNode(const DicNode &dicNode); DicNode(const DicNode &dicNode);
DicNode &operator=(const DicNode &dicNode); DicNode &operator=(const DicNode &dicNode);
virtual ~DicNode() {} ~DicNode() {}
// Init for copy // Init for copy
void initByCopy(const DicNode *const dicNode) { void initByCopy(const DicNode *const dicNode) {

View File

@ -33,7 +33,7 @@ class DicNodeProperties {
mIsTerminal(false), mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false), mIsTerminal(false), mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false),
mDepth(0), mLeavingDepth(0) {} mDepth(0), mLeavingDepth(0) {}
virtual ~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 pos, const int childrenPos, const int nodeCodePoint, const int probability,

View File

@ -37,7 +37,18 @@ class DicNodeState {
mDicNodeStateScoring() { mDicNodeStateScoring() {
} }
virtual ~DicNodeState() {} ~DicNodeState() {}
DicNodeState &operator=(const DicNodeState& src) {
init(&src);
return *this;
}
DicNodeState(const DicNodeState& src)
: mDicNodeStateInput(), mDicNodeStateOutput(), mDicNodeStatePrevWord(),
mDicNodeStateScoring() {
init(&src);
}
// Init with prevWordPos // Init with prevWordPos
void init(const int prevWordPos) { void init(const int prevWordPos) {
@ -62,11 +73,6 @@ class DicNodeState {
mDicNodeStateOutput.addMergedNodeCodePoints( mDicNodeStateOutput.addMergedNodeCodePoints(
mergedNodeCodePointCount, mergedNodeCodePoints); mergedNodeCodePointCount, mergedNodeCodePoints);
} }
private:
// Caution!!!
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_DIC_NODE_STATE_H #endif // LATINIME_DIC_NODE_STATE_H

View File

@ -25,7 +25,7 @@ namespace latinime {
class DicNodeStateInput { class DicNodeStateInput {
public: public:
DicNodeStateInput() {} DicNodeStateInput() {}
virtual ~DicNodeStateInput() {} ~DicNodeStateInput() {}
// TODO: Merge into DicNodeStatePrevWord::truncate // TODO: Merge into DicNodeStatePrevWord::truncate
void truncate(const int commitPoint) { void truncate(const int commitPoint) {
@ -89,9 +89,8 @@ class DicNodeStateInput {
} }
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateInput);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
int mInputIndex[MAX_POINTER_COUNT_G]; int mInputIndex[MAX_POINTER_COUNT_G];
int mPrevCodePoint[MAX_POINTER_COUNT_G]; int mPrevCodePoint[MAX_POINTER_COUNT_G];
float mTerminalDiffCost[MAX_POINTER_COUNT_G]; float mTerminalDiffCost[MAX_POINTER_COUNT_G];

View File

@ -27,11 +27,9 @@ namespace latinime {
class DicNodeStateOutput { class DicNodeStateOutput {
public: public:
DicNodeStateOutput() : mOutputtedCodePointCount(0) { DicNodeStateOutput() : mOutputtedCodePointCount(0) {}
init();
}
virtual ~DicNodeStateOutput() {} ~DicNodeStateOutput() {}
void init() { void init() {
mOutputtedCodePointCount = 0; mOutputtedCodePointCount = 0;
@ -72,9 +70,8 @@ class DicNodeStateOutput {
int mCodePointsBuf[MAX_WORD_LENGTH]; int mCodePointsBuf[MAX_WORD_LENGTH];
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateOutput);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
uint16_t mOutputtedCodePointCount; uint16_t mOutputtedCodePointCount;
}; };
} // namespace latinime } // namespace latinime

View File

@ -31,20 +31,9 @@ class DicNodeStatePrevWord {
public: public:
AK_FORCE_INLINE DicNodeStatePrevWord() AK_FORCE_INLINE DicNodeStatePrevWord()
: mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0), : mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0),
mPrevWordPtNodePos(NOT_A_DICT_POS), mSecondWordFirstInputIndex(NOT_AN_INDEX) { mPrevWordPtNodePos(NOT_A_DICT_POS), mSecondWordFirstInputIndex(NOT_AN_INDEX) {}
memset(mPrevWord, 0, sizeof(mPrevWord));
}
virtual ~DicNodeStatePrevWord() {} ~DicNodeStatePrevWord() {}
void init() {
mPrevWordLength = 0;
mPrevWordCount = 0;
mPrevWordStart = 0;
mPrevWordProbability = -1;
mPrevWordPtNodePos = NOT_A_DICT_POS;
mSecondWordFirstInputIndex = NOT_AN_INDEX;
}
void init(const int prevWordNodePos) { void init(const int prevWordNodePos) {
mPrevWordLength = 0; mPrevWordLength = 0;
@ -53,6 +42,7 @@ class DicNodeStatePrevWord {
mPrevWordProbability = -1; mPrevWordProbability = -1;
mPrevWordPtNodePos = prevWordNodePos; mPrevWordPtNodePos = prevWordNodePos;
mSecondWordFirstInputIndex = NOT_AN_INDEX; mSecondWordFirstInputIndex = NOT_AN_INDEX;
mPrevWord[0] = 0;
} }
// Init by copy // Init by copy
@ -141,9 +131,8 @@ class DicNodeStatePrevWord {
int mPrevWord[MAX_WORD_LENGTH]; int mPrevWord[MAX_WORD_LENGTH];
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStatePrevWord);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
int16_t mPrevWordCount; int16_t mPrevWordCount;
int16_t mPrevWordLength; int16_t mPrevWordLength;
int16_t mPrevWordStart; int16_t mPrevWordStart;

View File

@ -37,7 +37,7 @@ class DicNodeStateScoring {
mNormalizedCompoundDistanceAfterFirstWord(MAX_VALUE_FOR_WEIGHTING) { mNormalizedCompoundDistanceAfterFirstWord(MAX_VALUE_FOR_WEIGHTING) {
} }
virtual ~DicNodeStateScoring() {} ~DicNodeStateScoring() {}
void init() { void init() {
mEditCorrectionCount = 0; mEditCorrectionCount = 0;
@ -175,9 +175,8 @@ class DicNodeStateScoring {
} }
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateScoring);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
DoubleLetterLevel mDoubleLetterLevel; DoubleLetterLevel mDoubleLetterLevel;
DigraphUtils::DigraphCodePointIndex mDigraphIndex; DigraphUtils::DigraphCodePointIndex mDigraphIndex;

View File

@ -248,17 +248,16 @@ void Suggest::processTerminalDicNode(
if (dicNode->shouldBeFilteredBySafetyNetForBigram()) { if (dicNode->shouldBeFilteredBySafetyNetForBigram()) {
return; return;
} }
if (!dicNode->hasMatchedOrProximityCodePoints()) {
return;
}
// Create a non-cached node here. // Create a non-cached node here.
DicNode terminalDicNode; DicNode terminalDicNode(*dicNode);
DicNodeUtils::initByCopy(dicNode, &terminalDicNode);
if (TRAVERSAL->needsToTraverseAllUserInput() if (TRAVERSAL->needsToTraverseAllUserInput()
&& dicNode->getInputIndex(0) < traverseSession->getInputSize()) { && dicNode->getInputIndex(0) < traverseSession->getInputSize()) {
Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL_INSERTION, traverseSession, 0, Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL_INSERTION, traverseSession, 0,
&terminalDicNode, traverseSession->getMultiBigramMap()); &terminalDicNode, traverseSession->getMultiBigramMap());
} }
if (!dicNode->hasMatchedOrProximityCodePoints()) {
return;
}
Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL, traverseSession, 0, Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL, traverseSession, 0,
&terminalDicNode, traverseSession->getMultiBigramMap()); &terminalDicNode, traverseSession->getMultiBigramMap());
traverseSession->getDicTraverseCache()->copyPushTerminal(&terminalDicNode); traverseSession->getDicTraverseCache()->copyPushTerminal(&terminalDicNode);
@ -375,6 +374,7 @@ void Suggest::processDicNodeAsTransposition(DicTraverseSession *traverseSession,
DicNode *dicNode) const { DicNode *dicNode) const {
const int16_t pointIndex = dicNode->getInputIndex(0); const int16_t pointIndex = dicNode->getInputIndex(0);
DicNodeVector childDicNodes1; DicNodeVector childDicNodes1;
DicNodeVector childDicNodes2;
DicNodeUtils::getAllChildDicNodes(dicNode, traverseSession->getDictionaryStructurePolicy(), DicNodeUtils::getAllChildDicNodes(dicNode, traverseSession->getDictionaryStructurePolicy(),
&childDicNodes1); &childDicNodes1);
const int childSize1 = childDicNodes1.getSizeAndLock(); const int childSize1 = childDicNodes1.getSizeAndLock();
@ -386,7 +386,7 @@ void Suggest::processDicNodeAsTransposition(DicTraverseSession *traverseSession,
continue; continue;
} }
if (childDicNodes1[i]->hasChildren()) { if (childDicNodes1[i]->hasChildren()) {
DicNodeVector childDicNodes2; childDicNodes2.clear();
DicNodeUtils::getAllChildDicNodes(childDicNodes1[i], DicNodeUtils::getAllChildDicNodes(childDicNodes1[i],
traverseSession->getDictionaryStructurePolicy(), &childDicNodes2); traverseSession->getDictionaryStructurePolicy(), &childDicNodes2);
const int childSize2 = childDicNodes2.getSizeAndLock(); const int childSize2 = childDicNodes2.getSizeAndLock();