Merge "Check adjacent proximity chars for insertion for typing"

This commit is contained in:
Keisuke Kuroynagi 2013-06-24 00:52:02 +00:00 committed by Android (Google) Code Review
commit 940cca4fa9
4 changed files with 17 additions and 22 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}