Change method name of getDepth and getTotalLength.
Change-Id: I4b3aa54e17d7de7c31f956dc9d59941d79856fd7main
parent
93f74bafbb
commit
09858cbde4
|
@ -28,13 +28,13 @@
|
||||||
#if DEBUG_DICT
|
#if DEBUG_DICT
|
||||||
#define LOGI_SHOW_ADD_COST_PROP \
|
#define LOGI_SHOW_ADD_COST_PROP \
|
||||||
do { char charBuf[50]; \
|
do { char charBuf[50]; \
|
||||||
INTS_TO_CHARS(getOutputWordBuf(), getDepth(), charBuf); \
|
INTS_TO_CHARS(getOutputWordBuf(), getNodeCodePointCount(), charBuf); \
|
||||||
AKLOGI("%20s, \"%c\", size = %03d, total = %03d, index(0) = %02d, dist = %.4f, %s,,", \
|
AKLOGI("%20s, \"%c\", size = %03d, total = %03d, index(0) = %02d, dist = %.4f, %s,,", \
|
||||||
__FUNCTION__, getNodeCodePoint(), inputSize, getTotalInputIndex(), \
|
__FUNCTION__, getNodeCodePoint(), inputSize, getTotalInputIndex(), \
|
||||||
getInputIndex(0), getNormalizedCompoundDistance(), charBuf); } while (0)
|
getInputIndex(0), getNormalizedCompoundDistance(), charBuf); } while (0)
|
||||||
#define DUMP_WORD_AND_SCORE(header) \
|
#define DUMP_WORD_AND_SCORE(header) \
|
||||||
do { char charBuf[50]; char prevWordCharBuf[50]; \
|
do { char charBuf[50]; char prevWordCharBuf[50]; \
|
||||||
INTS_TO_CHARS(getOutputWordBuf(), getDepth(), charBuf); \
|
INTS_TO_CHARS(getOutputWordBuf(), getNodeCodePointCount(), charBuf); \
|
||||||
INTS_TO_CHARS(mDicNodeState.mDicNodeStatePrevWord.mPrevWord, \
|
INTS_TO_CHARS(mDicNodeState.mDicNodeStatePrevWord.mPrevWord, \
|
||||||
mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(), prevWordCharBuf); \
|
mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(), prevWordCharBuf); \
|
||||||
AKLOGI("#%8s, %5f, %5f, %5f, %5f, %s, %s, %d,,", header, \
|
AKLOGI("#%8s, %5f, %5f, %5f, %5f, %s, %s, %d,,", header, \
|
||||||
|
@ -162,7 +162,7 @@ class DicNode {
|
||||||
const bool isTerminal, const bool hasMultipleChars, const bool hasChildren,
|
const bool isTerminal, const bool hasMultipleChars, const bool hasChildren,
|
||||||
const uint16_t additionalSubwordLength, const int *additionalSubword) {
|
const uint16_t additionalSubwordLength, const int *additionalSubword) {
|
||||||
mIsUsed = true;
|
mIsUsed = true;
|
||||||
uint16_t newDepth = static_cast<uint16_t>(dicNode->getDepth() + 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() + additionalSubwordLength);
|
dicNode->mDicNodeProperties.getLeavingDepth() + additionalSubwordLength);
|
||||||
|
@ -185,7 +185,7 @@ class DicNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isRoot() const {
|
bool isRoot() const {
|
||||||
return getDepth() == 0;
|
return getNodeCodePointCount() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasChildren() const {
|
bool hasChildren() const {
|
||||||
|
@ -193,12 +193,12 @@ class DicNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isLeavingNode() const {
|
bool isLeavingNode() const {
|
||||||
ASSERT(getDepth() <= getLeavingDepth());
|
ASSERT(getNodeCodePointCount() <= getLeavingDepth());
|
||||||
return getDepth() == getLeavingDepth();
|
return getNodeCodePointCount() == getLeavingDepth();
|
||||||
}
|
}
|
||||||
|
|
||||||
AK_FORCE_INLINE bool isFirstLetter() const {
|
AK_FORCE_INLINE bool isFirstLetter() const {
|
||||||
return getDepth() == 1;
|
return getNodeCodePointCount() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCached() const {
|
bool isCached() const {
|
||||||
|
@ -211,7 +211,7 @@ class DicNode {
|
||||||
|
|
||||||
// Used to expand the node in DicNodeUtils
|
// Used to expand the node in DicNodeUtils
|
||||||
int getNodeTypedCodePoint() const {
|
int getNodeTypedCodePoint() const {
|
||||||
return mDicNodeState.mDicNodeStateOutput.getCodePointAt(getDepth());
|
return mDicNodeState.mDicNodeStateOutput.getCodePointAt(getNodeCodePointCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isImpossibleBigramWord() const {
|
bool isImpossibleBigramWord() const {
|
||||||
|
@ -220,7 +220,7 @@ class DicNode {
|
||||||
}
|
}
|
||||||
const int prevWordLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength()
|
const int prevWordLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength()
|
||||||
- mDicNodeState.mDicNodeStatePrevWord.getPrevWordStart() - 1;
|
- mDicNodeState.mDicNodeStatePrevWord.getPrevWordStart() - 1;
|
||||||
const int currentWordLen = getDepth();
|
const int currentWordLen = getNodeCodePointCount();
|
||||||
return (prevWordLen == 1 && currentWordLen == 1);
|
return (prevWordLen == 1 && currentWordLen == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,13 +268,13 @@ class DicNode {
|
||||||
|
|
||||||
AK_FORCE_INLINE bool isTerminalWordNode() const {
|
AK_FORCE_INLINE bool isTerminalWordNode() const {
|
||||||
const bool isTerminalNodes = mDicNodeProperties.isTerminal();
|
const bool isTerminalNodes = mDicNodeProperties.isTerminal();
|
||||||
const int currentNodeDepth = getDepth();
|
const int currentNodeDepth = getNodeCodePointCount();
|
||||||
const int terminalNodeDepth = mDicNodeProperties.getLeavingDepth();
|
const int terminalNodeDepth = mDicNodeProperties.getLeavingDepth();
|
||||||
return isTerminalNodes && currentNodeDepth > 0 && currentNodeDepth == terminalNodeDepth;
|
return isTerminalNodes && currentNodeDepth > 0 && currentNodeDepth == terminalNodeDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldBeFilterdBySafetyNetForBigram() const {
|
bool shouldBeFilterdBySafetyNetForBigram() const {
|
||||||
const uint16_t currentDepth = getDepth();
|
const uint16_t currentDepth = getNodeCodePointCount();
|
||||||
const int prevWordLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength()
|
const int prevWordLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength()
|
||||||
- mDicNodeState.mDicNodeStatePrevWord.getPrevWordStart() - 1;
|
- mDicNodeState.mDicNodeStatePrevWord.getPrevWordStart() - 1;
|
||||||
return !(currentDepth > 0 && (currentDepth != 1 || prevWordLen != 1));
|
return !(currentDepth > 0 && (currentDepth != 1 || prevWordLen != 1));
|
||||||
|
@ -286,7 +286,7 @@ class DicNode {
|
||||||
|
|
||||||
bool isTotalInputSizeExceedingLimit() const {
|
bool isTotalInputSizeExceedingLimit() const {
|
||||||
const int prevWordsLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
const int prevWordsLen = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
||||||
const int currentWordDepth = getDepth();
|
const int currentWordDepth = getNodeCodePointCount();
|
||||||
// TODO: 3 can be 2? Needs to be investigated.
|
// TODO: 3 can be 2? Needs to be investigated.
|
||||||
// TODO: Have a const variable for 3 (or 2)
|
// TODO: Have a const variable for 3 (or 2)
|
||||||
return prevWordsLen + currentWordDepth > MAX_WORD_LENGTH - 3;
|
return prevWordsLen + currentWordDepth > MAX_WORD_LENGTH - 3;
|
||||||
|
@ -321,7 +321,7 @@ class DicNode {
|
||||||
|
|
||||||
void outputResult(int *dest) const {
|
void outputResult(int *dest) const {
|
||||||
const uint16_t prevWordLength = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
const uint16_t prevWordLength = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
||||||
const uint16_t currentDepth = getDepth();
|
const uint16_t currentDepth = getNodeCodePointCount();
|
||||||
DicNodeUtils::appendTwoWords(mDicNodeState.mDicNodeStatePrevWord.mPrevWord,
|
DicNodeUtils::appendTwoWords(mDicNodeState.mDicNodeStatePrevWord.mPrevWord,
|
||||||
prevWordLength, getOutputWordBuf(), currentDepth, dest);
|
prevWordLength, getOutputWordBuf(), currentDepth, dest);
|
||||||
DUMP_WORD_AND_SCORE("OUTPUT");
|
DUMP_WORD_AND_SCORE("OUTPUT");
|
||||||
|
@ -480,13 +480,13 @@ class DicNode {
|
||||||
return mDicNodeProperties.getAttributesPos();
|
return mDicNodeProperties.getAttributesPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t getDepth() const {
|
inline uint16_t getNodeCodePointCount() const {
|
||||||
return mDicNodeProperties.getDepth();
|
return mDicNodeProperties.getDepth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Length" includes spaces.
|
// Returns code point count including spaces
|
||||||
inline uint16_t getTotalLength() const {
|
inline uint16_t getTotalNodeCodePointCount() const {
|
||||||
return getDepth() + mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
return getNodeCodePointCount() + mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
AK_FORCE_INLINE void dump(const char *tag) const {
|
AK_FORCE_INLINE void dump(const char *tag) const {
|
||||||
|
@ -521,8 +521,8 @@ class DicNode {
|
||||||
} else if (diff < -MIN_DIFF) {
|
} else if (diff < -MIN_DIFF) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int depth = getDepth();
|
const int depth = getNodeCodePointCount();
|
||||||
const int depthDiff = right->getDepth() - depth;
|
const int depthDiff = right->getNodeCodePointCount() - depth;
|
||||||
if (depthDiff != 0) {
|
if (depthDiff != 0) {
|
||||||
return depthDiff > 0;
|
return depthDiff > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ class TypingTraversal : public Traversal {
|
||||||
AK_FORCE_INLINE bool sameAsTyped(
|
AK_FORCE_INLINE bool sameAsTyped(
|
||||||
const DicTraverseSession *const traverseSession, const DicNode *const dicNode) const {
|
const DicTraverseSession *const traverseSession, const DicNode *const dicNode) const {
|
||||||
return traverseSession->getProximityInfoState(0)->sameAsTyped(
|
return traverseSession->getProximityInfoState(0)->sameAsTyped(
|
||||||
dicNode->getOutputWordBuf(), dicNode->getDepth());
|
dicNode->getOutputWordBuf(), dicNode->getNodeCodePointCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
AK_FORCE_INLINE int getMaxCacheSize() const {
|
AK_FORCE_INLINE int getMaxCacheSize() const {
|
||||||
|
@ -171,7 +171,7 @@ class TypingTraversal : public Traversal {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int c = dicNode->getOutputWordBuf()[0];
|
const int c = dicNode->getOutputWordBuf()[0];
|
||||||
const bool shortCappedWord = dicNode->getDepth()
|
const bool shortCappedWord = dicNode->getNodeCodePointCount()
|
||||||
< ScoringParams::THRESHOLD_SHORT_WORD_LENGTH && CharUtils::isAsciiUpper(c);
|
< ScoringParams::THRESHOLD_SHORT_WORD_LENGTH && CharUtils::isAsciiUpper(c);
|
||||||
return !shortCappedWord
|
return !shortCappedWord
|
||||||
|| probability >= ScoringParams::THRESHOLD_NEXT_WORD_PROBABILITY_FOR_CAPPED;
|
|| probability >= ScoringParams::THRESHOLD_NEXT_WORD_PROBABILITY_FOR_CAPPED;
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TypingWeighting : public Weighting {
|
||||||
const bool isZeroCostOmission = parentDicNode->isZeroCostOmission();
|
const bool isZeroCostOmission = parentDicNode->isZeroCostOmission();
|
||||||
const bool sameCodePoint = dicNode->isSameNodeCodePoint(parentDicNode);
|
const bool sameCodePoint = dicNode->isSameNodeCodePoint(parentDicNode);
|
||||||
// If the traversal omitted the first letter then the dicNode should now be on the second.
|
// If the traversal omitted the first letter then the dicNode should now be on the second.
|
||||||
const bool isFirstLetterOmission = dicNode->getDepth() == 2;
|
const bool isFirstLetterOmission = dicNode->getNodeCodePointCount() == 2;
|
||||||
float cost = 0.0f;
|
float cost = 0.0f;
|
||||||
if (isZeroCostOmission) {
|
if (isZeroCostOmission) {
|
||||||
cost = 0.0f;
|
cost = 0.0f;
|
||||||
|
@ -83,7 +83,7 @@ class TypingWeighting : public Weighting {
|
||||||
const bool isProximity = isProximityDicNode(traverseSession, dicNode);
|
const bool isProximity = isProximityDicNode(traverseSession, dicNode);
|
||||||
float cost = isProximity ? (isFirstChar ? ScoringParams::FIRST_PROXIMITY_COST
|
float cost = isProximity ? (isFirstChar ? ScoringParams::FIRST_PROXIMITY_COST
|
||||||
: ScoringParams::PROXIMITY_COST) : 0.0f;
|
: ScoringParams::PROXIMITY_COST) : 0.0f;
|
||||||
if (dicNode->getDepth() == 2) {
|
if (dicNode->getNodeCodePointCount() == 2) {
|
||||||
// At the second character of the current word, we check if the first char is uppercase
|
// At the second character of the current word, we check if the first char is uppercase
|
||||||
// and the word is a second or later word of a multiple word suggestion. We demote it
|
// and the word is a second or later word of a multiple word suggestion. We demote it
|
||||||
// if so.
|
// if so.
|
||||||
|
@ -131,7 +131,7 @@ class TypingWeighting : public Weighting {
|
||||||
const float dist = traverseSession->getProximityInfoState(0)->getPointToKeyLength(
|
const float dist = traverseSession->getProximityInfoState(0)->getPointToKeyLength(
|
||||||
parentPointIndex + 1, currentCodePoint);
|
parentPointIndex + 1, currentCodePoint);
|
||||||
const float weightedDistance = dist * ScoringParams::DISTANCE_WEIGHT_LENGTH;
|
const float weightedDistance = dist * ScoringParams::DISTANCE_WEIGHT_LENGTH;
|
||||||
const bool singleChar = dicNode->getDepth() == 1;
|
const bool singleChar = dicNode->getNodeCodePointCount() == 1;
|
||||||
const float cost = (singleChar ? ScoringParams::INSERTION_COST_FIRST_CHAR : 0.0f)
|
const float cost = (singleChar ? ScoringParams::INSERTION_COST_FIRST_CHAR : 0.0f)
|
||||||
+ (sameCodePoint ? ScoringParams::INSERTION_COST_SAME_CHAR
|
+ (sameCodePoint ? ScoringParams::INSERTION_COST_SAME_CHAR
|
||||||
: ScoringParams::INSERTION_COST);
|
: ScoringParams::INSERTION_COST);
|
||||||
|
|
Loading…
Reference in New Issue