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

Commit 24706f8f authored by Keisuke Kuroynagi's avatar Keisuke Kuroynagi
Browse files

Check adjacent proximity chars for insertion for typing

Change-Id: I6ce1b065bba055516fca0c8af6f14853a111aa68
parent b7a2fd16
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
@@ -90,20 +90,7 @@ class ProximityInfoState {
        return false;
    }

    // TODO: Promote insertion letter correction if that letter is a proximity of the previous
    // letter like follows:
    // // Demotion for a word with excessive character
    // if (excessiveCount > 0) {
    //     multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq);
    //     if (!lastCharExceeded
    //             && !proximityInfoState->existsAdjacentProximityChars(excessivePos)) {
    //         // If an excessive character is not adjacent to the left char or the right char,
    //         // we will demote this word.
    //         multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE,
    //                 &finalFreq);
    //     }
    // }
    inline bool existsAdjacentProximityChars(const int index) const {
    AK_FORCE_INLINE bool existsAdjacentProximityChars(const int index) const {
        if (index < 0 || index >= mSampledInputSize) return false;
        const int currentCodePoint = getPrimaryCodePointAt(index);
        const int leftIndex = index - 1;
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ const float ScoringParams::OMISSION_COST_SAME_CHAR = 0.491f;
const float ScoringParams::OMISSION_COST_FIRST_CHAR = 0.582f;
const float ScoringParams::INSERTION_COST = 0.730f;
const float ScoringParams::INSERTION_COST_SAME_CHAR = 0.586f;
const float ScoringParams::INSERTION_COST_PROXIMITY_CHAR = 0.70f;
const float ScoringParams::INSERTION_COST_FIRST_CHAR = 0.623f;
const float ScoringParams::TRANSPOSITION_COST = 0.516f;
const float ScoringParams::SPACE_SUBSTITUTION_COST = 0.319f;
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class ScoringParams {
    static const float OMISSION_COST_FIRST_CHAR;
    static const float INSERTION_COST;
    static const float INSERTION_COST_SAME_CHAR;
    static const float INSERTION_COST_PROXIMITY_CHAR;
    static const float INSERTION_COST_FIRST_CHAR;
    static const float TRANSPOSITION_COST;
    static const float SPACE_SUBSTITUTION_COST;
+14 −8
Original line number Diff line number Diff line
@@ -122,19 +122,25 @@ class TypingWeighting : public Weighting {

    float getInsertionCost(const DicTraverseSession *const traverseSession,
            const DicNode *const parentDicNode, const DicNode *const dicNode) const {
        const int16_t parentPointIndex = parentDicNode->getInputIndex(0);
        const int prevCodePoint =
                traverseSession->getProximityInfoState(0)->getPrimaryCodePointAt(parentPointIndex);

        const int16_t insertedPointIndex = parentDicNode->getInputIndex(0);
        const int prevCodePoint = traverseSession->getProximityInfoState(0)->getPrimaryCodePointAt(
                insertedPointIndex);
        const int currentCodePoint = dicNode->getNodeCodePoint();
        const bool sameCodePoint = prevCodePoint == currentCodePoint;
        const bool existsAdjacentProximityChars = traverseSession->getProximityInfoState(0)
                ->existsAdjacentProximityChars(insertedPointIndex);
        const float dist = traverseSession->getProximityInfoState(0)->getPointToKeyLength(
                parentPointIndex + 1, currentCodePoint);
                insertedPointIndex + 1, dicNode->getNodeCodePoint());
        const float weightedDistance = dist * ScoringParams::DISTANCE_WEIGHT_LENGTH;
        const bool singleChar = dicNode->getNodeCodePointCount() == 1;
        const float cost = (singleChar ? ScoringParams::INSERTION_COST_FIRST_CHAR : 0.0f)
                + (sameCodePoint ? ScoringParams::INSERTION_COST_SAME_CHAR
                        : ScoringParams::INSERTION_COST);
        float cost = (singleChar ? ScoringParams::INSERTION_COST_FIRST_CHAR : 0.0f);
        if (sameCodePoint) {
            cost += ScoringParams::INSERTION_COST_SAME_CHAR;
        } else if (existsAdjacentProximityChars) {
            cost += ScoringParams::INSERTION_COST_PROXIMITY_CHAR;
        } else {
            cost += ScoringParams::INSERTION_COST;
        }
        return cost + weightedDistance;
    }