Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b85bf4eb authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Use word id to construct DicNode instead of isTerminal flag."

parents fe395232 7d475003
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -299,6 +299,7 @@ static inline void prof_out(void) {
#define NOT_AN_INDEX (-1)
#define NOT_A_PROBABILITY (-1)
#define NOT_A_DICT_POS (S_INT_MIN)
#define NOT_A_WORD_ID (S_INT_MIN)
#define NOT_A_TIMESTAMP (-1)
#define NOT_A_LANGUAGE_WEIGHT (-1.0f)

+2 −2
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ class DicNode {
    }

    void initAsChild(const DicNode *const dicNode, const int ptNodePos,
            const int childrenPtNodeArrayPos, const int probability, const bool isTerminal,
            const int childrenPtNodeArrayPos, const int probability, const int wordId,
            const bool hasChildren, const bool isBlacklistedOrNotAWord,
            const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
        uint16_t newDepth = static_cast<uint16_t>(dicNode->getNodeCodePointCount() + 1);
@@ -144,7 +144,7 @@ class DicNode {
        const uint16_t newLeavingDepth = static_cast<uint16_t>(
                dicNode->mDicNodeProperties.getLeavingDepth() + mergedNodeCodePointCount);
        mDicNodeProperties.init(ptNodePos, childrenPtNodeArrayPos, mergedNodeCodePoints[0],
                probability, isTerminal, hasChildren, isBlacklistedOrNotAWord, newDepth,
                probability, wordId, hasChildren, isBlacklistedOrNotAWord, newDepth,
                newLeavingDepth, dicNode->mDicNodeProperties.getPrevWordsTerminalPtNodePos());
        mDicNodeState.init(&dicNode->mDicNodeState, mergedNodeCodePointCount,
                mergedNodeCodePoints);
+2 −2
Original line number Diff line number Diff line
@@ -59,13 +59,13 @@ class DicNodeVector {
    }

    void pushLeavingChild(const DicNode *const dicNode, const int ptNodePos,
            const int childrenPtNodeArrayPos, const int probability, const bool isTerminal,
            const int childrenPtNodeArrayPos, const int probability, const int wordId,
            const bool hasChildren, const bool isBlacklistedOrNotAWord,
            const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
        ASSERT(!mLock);
        mDicNodes.emplace_back();
        mDicNodes.back().initAsChild(dicNode, ptNodePos, childrenPtNodeArrayPos, probability,
                isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
                wordId, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
                mergedNodeCodePoints);
    }

+8 −8
Original line number Diff line number Diff line
@@ -31,20 +31,20 @@ class DicNodeProperties {
    AK_FORCE_INLINE DicNodeProperties()
            : mPtNodePos(NOT_A_DICT_POS), mChildrenPtNodeArrayPos(NOT_A_DICT_POS),
              mProbability(NOT_A_PROBABILITY), mDicNodeCodePoint(NOT_A_CODE_POINT),
              mIsTerminal(false), mHasChildrenPtNodes(false),
              mWordId(NOT_A_WORD_ID), mHasChildrenPtNodes(false),
              mIsBlacklistedOrNotAWord(false), mDepth(0), mLeavingDepth(0) {}

    ~DicNodeProperties() {}

    // Should be called only once per DicNode is initialized.
    void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability,
            const bool isTerminal, 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 prevWordsNodePos) {
        mPtNodePos = pos;
        mChildrenPtNodeArrayPos = childrenPos;
        mDicNodeCodePoint = nodeCodePoint;
        mProbability = probability;
        mIsTerminal = isTerminal;
        mWordId = wordId;
        mHasChildrenPtNodes = hasChildren;
        mIsBlacklistedOrNotAWord = isBlacklistedOrNotAWord;
        mDepth = depth;
@@ -58,7 +58,7 @@ class DicNodeProperties {
        mChildrenPtNodeArrayPos = rootPtNodeArrayPos;
        mDicNodeCodePoint = NOT_A_CODE_POINT;
        mProbability = NOT_A_PROBABILITY;
        mIsTerminal = false;
        mWordId = NOT_A_WORD_ID;
        mHasChildrenPtNodes = true;
        mIsBlacklistedOrNotAWord = false;
        mDepth = 0;
@@ -71,7 +71,7 @@ class DicNodeProperties {
        mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos;
        mDicNodeCodePoint = dicNodeProp->mDicNodeCodePoint;
        mProbability = dicNodeProp->mProbability;
        mIsTerminal = dicNodeProp->mIsTerminal;
        mWordId = dicNodeProp->mWordId;
        mHasChildrenPtNodes = dicNodeProp->mHasChildrenPtNodes;
        mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord;
        mDepth = dicNodeProp->mDepth;
@@ -86,7 +86,7 @@ class DicNodeProperties {
        mChildrenPtNodeArrayPos = dicNodeProp->mChildrenPtNodeArrayPos;
        mDicNodeCodePoint = codePoint; // Overwrite the node char of a passing child
        mProbability = dicNodeProp->mProbability;
        mIsTerminal = dicNodeProp->mIsTerminal;
        mWordId = dicNodeProp->mWordId;
        mHasChildrenPtNodes = dicNodeProp->mHasChildrenPtNodes;
        mIsBlacklistedOrNotAWord = dicNodeProp->mIsBlacklistedOrNotAWord;
        mDepth = dicNodeProp->mDepth + 1; // Increment the depth of a passing child
@@ -121,7 +121,7 @@ class DicNodeProperties {
    }

    bool isTerminal() const {
        return mIsTerminal;
        return mWordId != NOT_A_WORD_ID;
    }

    bool hasChildren() const {
@@ -144,7 +144,7 @@ class DicNodeProperties {
    int mChildrenPtNodeArrayPos;
    int mProbability;
    int mDicNodeCodePoint;
    bool mIsTerminal;
    int mWordId;
    bool mHasChildrenPtNodes;
    bool mIsBlacklistedOrNotAWord;
    uint16_t mDepth;
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class UnigramProperty;
 * This class abstracts the structure of dictionaries.
 * Implement this policy to support additional dictionaries.
 */
// TODO: Use word id instead of terminal PtNode position.
class DictionaryStructureWithBufferPolicy {
 public:
    typedef std::unique_ptr<DictionaryStructureWithBufferPolicy> StructurePolicyPtr;
Loading