Allow force auto commit when the top is long multiword.

Bug: 9688196
Change-Id: I73ff2cd77b932bf7307b3541ea9da3fa4afa11b4
main
Keisuke Kuroynagi 2013-07-04 17:39:01 +09:00
parent 55de0bd981
commit a829188f54
3 changed files with 22 additions and 17 deletions

View File

@ -45,7 +45,7 @@ class Traversal {
const DicNode *const dicNode) const = 0; const DicNode *const dicNode) const = 0;
virtual bool needsToTraverseAllUserInput() const = 0; virtual bool needsToTraverseAllUserInput() const = 0;
virtual float getMaxSpatialDistance() const = 0; virtual float getMaxSpatialDistance() const = 0;
virtual bool allowPartialCommit() const = 0; virtual bool autoCorrectsToMultiWordSuggestionIfTop() const = 0;
virtual int getDefaultExpandDicNodeSize() const = 0; virtual int getDefaultExpandDicNodeSize() const = 0;
virtual int getMaxCacheSize() const = 0; virtual int getMaxCacheSize() const = 0;
virtual bool isPossibleOmissionChildNode(const DicTraverseSession *const traverseSession, virtual bool isPossibleOmissionChildNode(const DicTraverseSession *const traverseSession,

View File

@ -85,9 +85,9 @@ void Suggest::initializeSearch(DicTraverseSession *traverseSession, int commitPo
if (!traverseSession->getProximityInfoState(0)->isUsed()) { if (!traverseSession->getProximityInfoState(0)->isUsed()) {
return; return;
} }
if (TRAVERSAL->allowPartialCommit()) {
commitPoint = 0; // Never auto partial commit for now.
} commitPoint = 0;
if (traverseSession->getInputSize() > MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE if (traverseSession->getInputSize() > MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE
&& traverseSession->isContinuousSuggestionPossible()) { && traverseSession->isContinuousSuggestionPossible()) {
@ -151,6 +151,17 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
int maxScore = S_INT_MIN; int maxScore = S_INT_MIN;
int bestExactMatchedNodeTerminalIndex = -1; int bestExactMatchedNodeTerminalIndex = -1;
int bestExactMatchedNodeOutputWordIndex = -1; int bestExactMatchedNodeOutputWordIndex = -1;
// Force autocorrection for obvious long multi-word suggestions when the top suggestion is
// a long multiple words suggestion.
// TODO: Implement a smarter auto-commit method for handling multi-word suggestions.
// traverseSession->isPartiallyCommited() always returns false because we never auto partial
// commit for now.
const bool forceCommitMultiWords = (terminalSize > 0) ?
TRAVERSAL->autoCorrectsToMultiWordSuggestionIfTop()
&& (traverseSession->isPartiallyCommited()
|| (traverseSession->getInputSize()
>= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT
&& terminals[0].hasMultipleWords())) : false;
// Output suggestion results here // Output suggestion results here
for (int terminalIndex = 0; terminalIndex < terminalSize && outputWordIndex < MAX_RESULTS; for (int terminalIndex = 0; terminalIndex < terminalSize && outputWordIndex < MAX_RESULTS;
++terminalIndex) { ++terminalIndex) {
@ -180,22 +191,16 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
// Increase output score of top typing suggestion to ensure autocorrection. // Increase output score of top typing suggestion to ensure autocorrection.
// TODO: Better integration with java side autocorrection logic. // TODO: Better integration with java side autocorrection logic.
// Force autocorrection for obvious long multi-word suggestions.
const bool isForceCommitMultiWords = TRAVERSAL->allowPartialCommit()
&& (traverseSession->isPartiallyCommited()
|| (traverseSession->getInputSize() >= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT
&& terminalDicNode->hasMultipleWords()));
const int finalScore = SCORING->calculateFinalScore( const int finalScore = SCORING->calculateFinalScore(
compoundDistance, traverseSession->getInputSize(), compoundDistance, traverseSession->getInputSize(),
isForceCommitMultiWords || (isValidWord && SCORING->doesAutoCorrectValidWord())); (forceCommitMultiWords && terminalDicNode->hasMultipleWords())
|| (isValidWord && SCORING->doesAutoCorrectValidWord()));
maxScore = max(maxScore, finalScore); maxScore = max(maxScore, finalScore);
if (TRAVERSAL->allowPartialCommit()) { // TODO: Implement a smarter auto-commit method for handling multi-word suggestions.
// Index for top typing suggestion should be 0. // Index for top typing suggestion should be 0.
if (isValidWord && outputWordIndex == 0) { if (isValidWord && outputWordIndex == 0) {
terminalDicNode->outputSpacePositionsResult(spaceIndices); terminalDicNode->outputSpacePositionsResult(spaceIndices);
}
} }
// Don't output invalid words. However, we still need to submit their shortcuts if any. // Don't output invalid words. However, we still need to submit their shortcuts if any.

View File

@ -137,7 +137,7 @@ class TypingTraversal : public Traversal {
return ScoringParams::MAX_SPATIAL_DISTANCE; return ScoringParams::MAX_SPATIAL_DISTANCE;
} }
AK_FORCE_INLINE bool allowPartialCommit() const { AK_FORCE_INLINE bool autoCorrectsToMultiWordSuggestionIfTop() const {
return true; return true;
} }