Surface the distance after first word for autocommit.
Bug: 9059617 Change-Id: Ie9b4cc8148ae8e0ff437b3337ab6c1bde95500f5main
parent
ef084229f6
commit
da06e385f5
|
@ -375,7 +375,7 @@ typedef enum {
|
||||||
CT_TERMINAL,
|
CT_TERMINAL,
|
||||||
CT_TERMINAL_INSERTION,
|
CT_TERMINAL_INSERTION,
|
||||||
// Create new word with space omission
|
// Create new word with space omission
|
||||||
CT_NEW_WORD_SPACE_OMITTION,
|
CT_NEW_WORD_SPACE_OMISSION,
|
||||||
// Create new word with space substitution
|
// Create new word with space substitution
|
||||||
CT_NEW_WORD_SPACE_SUBSTITUTION,
|
CT_NEW_WORD_SPACE_SUBSTITUTION,
|
||||||
} CorrectionType;
|
} CorrectionType;
|
||||||
|
|
|
@ -38,10 +38,10 @@
|
||||||
INTS_TO_CHARS(mDicNodeState.mDicNodeStatePrevWord.mPrevWord, \
|
INTS_TO_CHARS(mDicNodeState.mDicNodeStatePrevWord.mPrevWord, \
|
||||||
mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(), prevWordCharBuf, \
|
mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(), prevWordCharBuf, \
|
||||||
NELEMS(prevWordCharBuf)); \
|
NELEMS(prevWordCharBuf)); \
|
||||||
AKLOGI("#%8s, %5f, %5f, %5f, %5f, %s, %s, %d,,", header, \
|
AKLOGI("#%8s, %5f, %5f, %5f, %5f, %s, %s, %d, %5f,", header, \
|
||||||
getSpatialDistanceForScoring(), getLanguageDistanceForScoring(), \
|
getSpatialDistanceForScoring(), getLanguageDistanceForScoring(), \
|
||||||
getNormalizedCompoundDistance(), getRawLength(), prevWordCharBuf, charBuf, \
|
getNormalizedCompoundDistance(), getRawLength(), prevWordCharBuf, charBuf, \
|
||||||
getInputIndex(0)); \
|
getInputIndex(0), getNormalizedCompoundDistanceAfterFirstWord()); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define LOGI_SHOW_ADD_COST_PROP
|
#define LOGI_SHOW_ADD_COST_PROP
|
||||||
|
@ -434,6 +434,13 @@ class DicNode {
|
||||||
return mDicNodeState.mDicNodeStateScoring.getLanguageDistance();
|
return mDicNodeState.mDicNodeStateScoring.getLanguageDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For space-aware gestures, we store the normalized distance at the char index
|
||||||
|
// that ends the first word of the suggestion. We call this the distance after
|
||||||
|
// first word.
|
||||||
|
float getNormalizedCompoundDistanceAfterFirstWord() const {
|
||||||
|
return mDicNodeState.mDicNodeStateScoring.getNormalizedCompoundDistanceAfterFirstWord();
|
||||||
|
}
|
||||||
|
|
||||||
float getLanguageDistanceRatePerWordForScoring() const {
|
float getLanguageDistanceRatePerWordForScoring() const {
|
||||||
const float langDist = getLanguageDistanceForScoring();
|
const float langDist = getLanguageDistanceForScoring();
|
||||||
const float totalWordCount =
|
const float totalWordCount =
|
||||||
|
@ -565,6 +572,12 @@ class DicNode {
|
||||||
inputSize, getTotalInputIndex(), errorType);
|
inputSize, getTotalInputIndex(), errorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves the current normalized compound distance for space-aware gestures.
|
||||||
|
// See getNormalizedCompoundDistanceAfterFirstWord for details.
|
||||||
|
AK_FORCE_INLINE void saveNormalizedCompoundDistanceAfterFirstWordIfNoneYet() {
|
||||||
|
mDicNodeState.mDicNodeStateScoring.saveNormalizedCompoundDistanceAfterFirstWordIfNoneYet();
|
||||||
|
}
|
||||||
|
|
||||||
// Caveat: Must not be called outside Weighting
|
// Caveat: Must not be called outside Weighting
|
||||||
// This restriction is guaranteed by "friend"
|
// This restriction is guaranteed by "friend"
|
||||||
AK_FORCE_INLINE void forwardInputIndex(const int pointerId, const int count,
|
AK_FORCE_INLINE void forwardInputIndex(const int pointerId, const int count,
|
||||||
|
|
|
@ -31,7 +31,8 @@ class DicNodeStateScoring {
|
||||||
mDigraphIndex(DigraphUtils::NOT_A_DIGRAPH_INDEX),
|
mDigraphIndex(DigraphUtils::NOT_A_DIGRAPH_INDEX),
|
||||||
mEditCorrectionCount(0), mProximityCorrectionCount(0),
|
mEditCorrectionCount(0), mProximityCorrectionCount(0),
|
||||||
mNormalizedCompoundDistance(0.0f), mSpatialDistance(0.0f), mLanguageDistance(0.0f),
|
mNormalizedCompoundDistance(0.0f), mSpatialDistance(0.0f), mLanguageDistance(0.0f),
|
||||||
mRawLength(0.0f), mExactMatch(true) {
|
mRawLength(0.0f), mExactMatch(true),
|
||||||
|
mNormalizedCompoundDistanceAfterFirstWord(MAX_VALUE_FOR_WEIGHTING) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~DicNodeStateScoring() {}
|
virtual ~DicNodeStateScoring() {}
|
||||||
|
@ -45,6 +46,7 @@ class DicNodeStateScoring {
|
||||||
mRawLength = 0.0f;
|
mRawLength = 0.0f;
|
||||||
mDoubleLetterLevel = NOT_A_DOUBLE_LETTER;
|
mDoubleLetterLevel = NOT_A_DOUBLE_LETTER;
|
||||||
mDigraphIndex = DigraphUtils::NOT_A_DIGRAPH_INDEX;
|
mDigraphIndex = DigraphUtils::NOT_A_DIGRAPH_INDEX;
|
||||||
|
mNormalizedCompoundDistanceAfterFirstWord = MAX_VALUE_FOR_WEIGHTING;
|
||||||
mExactMatch = true;
|
mExactMatch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +60,8 @@ class DicNodeStateScoring {
|
||||||
mDoubleLetterLevel = scoring->mDoubleLetterLevel;
|
mDoubleLetterLevel = scoring->mDoubleLetterLevel;
|
||||||
mDigraphIndex = scoring->mDigraphIndex;
|
mDigraphIndex = scoring->mDigraphIndex;
|
||||||
mExactMatch = scoring->mExactMatch;
|
mExactMatch = scoring->mExactMatch;
|
||||||
|
mNormalizedCompoundDistanceAfterFirstWord =
|
||||||
|
scoring->mNormalizedCompoundDistanceAfterFirstWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addCost(const float spatialCost, const float languageCost, const bool doNormalization,
|
void addCost(const float spatialCost, const float languageCost, const bool doNormalization,
|
||||||
|
@ -86,6 +90,17 @@ class DicNodeStateScoring {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves the current normalized distance for space-aware gestures.
|
||||||
|
// See getNormalizedCompoundDistanceAfterFirstWord for details.
|
||||||
|
void saveNormalizedCompoundDistanceAfterFirstWordIfNoneYet() {
|
||||||
|
// We get called here after each word. We only want to store the distance after
|
||||||
|
// the first word, so if we already have a distance we skip saving -- hence "IfNoneYet"
|
||||||
|
// in the method name.
|
||||||
|
if (mNormalizedCompoundDistanceAfterFirstWord >= MAX_VALUE_FOR_WEIGHTING) {
|
||||||
|
mNormalizedCompoundDistanceAfterFirstWord = getNormalizedCompoundDistance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addRawLength(const float rawLength) {
|
void addRawLength(const float rawLength) {
|
||||||
mRawLength += rawLength;
|
mRawLength += rawLength;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +117,13 @@ class DicNodeStateScoring {
|
||||||
return mNormalizedCompoundDistance;
|
return mNormalizedCompoundDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For space-aware gestures, we store the normalized distance at the char index
|
||||||
|
// that ends the first word of the suggestion. We call this the distance after
|
||||||
|
// first word.
|
||||||
|
float getNormalizedCompoundDistanceAfterFirstWord() const {
|
||||||
|
return mNormalizedCompoundDistanceAfterFirstWord;
|
||||||
|
}
|
||||||
|
|
||||||
float getSpatialDistance() const {
|
float getSpatialDistance() const {
|
||||||
return mSpatialDistance;
|
return mSpatialDistance;
|
||||||
}
|
}
|
||||||
|
@ -178,6 +200,7 @@ class DicNodeStateScoring {
|
||||||
float mLanguageDistance;
|
float mLanguageDistance;
|
||||||
float mRawLength;
|
float mRawLength;
|
||||||
bool mExactMatch;
|
bool mExactMatch;
|
||||||
|
float mNormalizedCompoundDistanceAfterFirstWord;
|
||||||
|
|
||||||
AK_FORCE_INLINE void addDistance(float spatialDistance, float languageDistance,
|
AK_FORCE_INLINE void addDistance(float spatialDistance, float languageDistance,
|
||||||
bool doNormalization, int inputSize, int totalInputIndex) {
|
bool doNormalization, int inputSize, int totalInputIndex) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ static inline void profile(const CorrectionType correctionType, DicNode *const n
|
||||||
case CT_SUBSTITUTION:
|
case CT_SUBSTITUTION:
|
||||||
PROF_SUBSTITUTION(node->mProfiler);
|
PROF_SUBSTITUTION(node->mProfiler);
|
||||||
return;
|
return;
|
||||||
case CT_NEW_WORD_SPACE_OMITTION:
|
case CT_NEW_WORD_SPACE_OMISSION:
|
||||||
PROF_NEW_WORD(node->mProfiler);
|
PROF_NEW_WORD(node->mProfiler);
|
||||||
return;
|
return;
|
||||||
case CT_MATCH:
|
case CT_MATCH:
|
||||||
|
@ -93,6 +93,11 @@ static inline void profile(const CorrectionType correctionType, DicNode *const n
|
||||||
}
|
}
|
||||||
dicNode->addCost(spatialCost, languageCost, weighting->needsToNormalizeCompoundDistance(),
|
dicNode->addCost(spatialCost, languageCost, weighting->needsToNormalizeCompoundDistance(),
|
||||||
inputSize, errorType);
|
inputSize, errorType);
|
||||||
|
if (CT_NEW_WORD_SPACE_OMISSION == correctionType) {
|
||||||
|
// When we are on a terminal, we save the current distance for evaluating
|
||||||
|
// when to auto-commit partial suggestions.
|
||||||
|
dicNode->saveNormalizedCompoundDistanceAfterFirstWordIfNoneYet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ float Weighting::getSpatialCost(const Weighting *const weighting,
|
/* static */ float Weighting::getSpatialCost(const Weighting *const weighting,
|
||||||
|
@ -108,7 +113,7 @@ static inline void profile(const CorrectionType correctionType, DicNode *const n
|
||||||
case CT_SUBSTITUTION:
|
case CT_SUBSTITUTION:
|
||||||
// only used for typing
|
// only used for typing
|
||||||
return weighting->getSubstitutionCost();
|
return weighting->getSubstitutionCost();
|
||||||
case CT_NEW_WORD_SPACE_OMITTION:
|
case CT_NEW_WORD_SPACE_OMISSION:
|
||||||
return weighting->getNewWordSpatialCost(traverseSession, dicNode, inputStateG);
|
return weighting->getNewWordSpatialCost(traverseSession, dicNode, inputStateG);
|
||||||
case CT_MATCH:
|
case CT_MATCH:
|
||||||
return weighting->getMatchedCost(traverseSession, dicNode, inputStateG);
|
return weighting->getMatchedCost(traverseSession, dicNode, inputStateG);
|
||||||
|
@ -138,7 +143,7 @@ static inline void profile(const CorrectionType correctionType, DicNode *const n
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
case CT_SUBSTITUTION:
|
case CT_SUBSTITUTION:
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
case CT_NEW_WORD_SPACE_OMITTION:
|
case CT_NEW_WORD_SPACE_OMISSION:
|
||||||
return weighting->getNewWordBigramLanguageCost(
|
return weighting->getNewWordBigramLanguageCost(
|
||||||
traverseSession, parentDicNode, multiBigramMap);
|
traverseSession, parentDicNode, multiBigramMap);
|
||||||
case CT_MATCH:
|
case CT_MATCH:
|
||||||
|
@ -173,7 +178,7 @@ static inline void profile(const CorrectionType correctionType, DicNode *const n
|
||||||
return 0; /* 0 because CT_MATCH will be called */
|
return 0; /* 0 because CT_MATCH will be called */
|
||||||
case CT_SUBSTITUTION:
|
case CT_SUBSTITUTION:
|
||||||
return 0; /* 0 because CT_MATCH will be called */
|
return 0; /* 0 because CT_MATCH will be called */
|
||||||
case CT_NEW_WORD_SPACE_OMITTION:
|
case CT_NEW_WORD_SPACE_OMISSION:
|
||||||
return 0;
|
return 0;
|
||||||
case CT_MATCH:
|
case CT_MATCH:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -574,7 +574,7 @@ void Suggest::createNextWordDicNode(DicTraverseSession *traverseSession, DicNode
|
||||||
DicNodeUtils::initAsRootWithPreviousWord(
|
DicNodeUtils::initAsRootWithPreviousWord(
|
||||||
traverseSession->getDictionaryStructurePolicy(), dicNode, &newDicNode);
|
traverseSession->getDictionaryStructurePolicy(), dicNode, &newDicNode);
|
||||||
const CorrectionType correctionType = spaceSubstitution ?
|
const CorrectionType correctionType = spaceSubstitution ?
|
||||||
CT_NEW_WORD_SPACE_SUBSTITUTION : CT_NEW_WORD_SPACE_OMITTION;
|
CT_NEW_WORD_SPACE_SUBSTITUTION : CT_NEW_WORD_SPACE_OMISSION;
|
||||||
Weighting::addCostAndForwardInputIndex(WEIGHTING, correctionType, traverseSession, dicNode,
|
Weighting::addCostAndForwardInputIndex(WEIGHTING, correctionType, traverseSession, dicNode,
|
||||||
&newDicNode, traverseSession->getMultiBigramMap());
|
&newDicNode, traverseSession->getMultiBigramMap());
|
||||||
if (newDicNode.getCompoundDistance() < static_cast<float>(MAX_VALUE_FOR_WEIGHTING)) {
|
if (newDicNode.getCompoundDistance() < static_cast<float>(MAX_VALUE_FOR_WEIGHTING)) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ ErrorType TypingWeighting::getErrorType(const CorrectionType correctionType,
|
||||||
case CT_TERMINAL_INSERTION:
|
case CT_TERMINAL_INSERTION:
|
||||||
case CT_TRANSPOSITION:
|
case CT_TRANSPOSITION:
|
||||||
return ET_EDIT_CORRECTION;
|
return ET_EDIT_CORRECTION;
|
||||||
case CT_NEW_WORD_SPACE_OMITTION:
|
case CT_NEW_WORD_SPACE_OMISSION:
|
||||||
case CT_NEW_WORD_SPACE_SUBSTITUTION:
|
case CT_NEW_WORD_SPACE_SUBSTITUTION:
|
||||||
return ET_NEW_WORD;
|
return ET_NEW_WORD;
|
||||||
case CT_TERMINAL:
|
case CT_TERMINAL:
|
||||||
|
|
Loading…
Reference in New Issue