am 9ee90955: Move methods for scoring from Traversal to Scoring.

* commit '9ee90955287d616158ad4cf099c4772f58c16942':
  Move methods for scoring from Traversal to Scoring.
main
Keisuke Kuroyanagi 2013-12-17 23:29:52 -08:00 committed by Android Git Automerger
commit b8f7aa23ba
5 changed files with 16 additions and 15 deletions

View File

@ -43,6 +43,9 @@ class Scoring {
const int doubleLetterTerminalIndex,
const DoubleLetterLevel doubleLetterLevel) const = 0;
virtual bool doesAutoCorrectValidWord() const = 0;
virtual bool autoCorrectsToMultiWordSuggestionIfTop() const = 0;
virtual bool sameAsTyped(const DicTraverseSession *const traverseSession,
const DicNode *const dicNode) const = 0;
protected:
Scoring() {}

View File

@ -41,11 +41,8 @@ class Traversal {
const DicNode *const dicNode) const = 0;
virtual ProximityType getProximityType(const DicTraverseSession *const traverseSession,
const DicNode *const dicNode, const DicNode *const childDicNode) const = 0;
virtual bool sameAsTyped(const DicTraverseSession *const traverseSession,
const DicNode *const dicNode) const = 0;
virtual bool needsToTraverseAllUserInput() const = 0;
virtual float getMaxSpatialDistance() const = 0;
virtual bool autoCorrectsToMultiWordSuggestionIfTop() const = 0;
virtual int getDefaultExpandDicNodeSize() const = 0;
virtual int getMaxCacheSize(const int inputSize) const = 0;
virtual bool isPossibleOmissionChildNode(const DicTraverseSession *const traverseSession,

View File

@ -158,7 +158,7 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
// traverseSession->isPartiallyCommited() always returns false because we never auto partial
// commit for now.
const bool forceCommitMultiWords = (terminalSize > 0) ?
TRAVERSAL->autoCorrectsToMultiWordSuggestionIfTop()
SCORING->autoCorrectsToMultiWordSuggestionIfTop()
&& (traverseSession->isPartiallyCommited()
|| (traverseSession->getInputSize()
>= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT
@ -234,7 +234,7 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
->getShortcutPositionOfPtNode(terminalDicNode->getPtNodePos()));
// Shortcut is not supported for multiple words suggestions.
// TODO: Check shortcuts during traversal for multiple words suggestions.
const bool sameAsTyped = TRAVERSAL->sameAsTyped(traverseSession, terminalDicNode);
const bool sameAsTyped = SCORING->sameAsTyped(traverseSession, terminalDicNode);
const int shortcutBaseScore = SCORING->doesAutoCorrectValidWord() ?
SCORING->calculateFinalScore(compoundDistance, traverseSession->getInputSize(),
true /* forceCommit */) : finalScore;

View File

@ -19,6 +19,7 @@
#include "defines.h"
#include "suggest/core/policy/scoring.h"
#include "suggest/core/session/dic_traverse_session.h"
#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
@ -71,6 +72,16 @@ class TypingScoring : public Scoring {
return false;
}
AK_FORCE_INLINE bool autoCorrectsToMultiWordSuggestionIfTop() const {
return true;
}
AK_FORCE_INLINE bool sameAsTyped(
const DicTraverseSession *const traverseSession, const DicNode *const dicNode) const {
return traverseSession->getProximityInfoState(0)->sameAsTyped(
dicNode->getOutputWordBuf(), dicNode->getNodeCodePointCount());
}
private:
DISALLOW_COPY_AND_ASSIGN(TypingScoring);
static const TypingScoring sInstance;

View File

@ -137,20 +137,10 @@ class TypingTraversal : public Traversal {
return ScoringParams::MAX_SPATIAL_DISTANCE;
}
AK_FORCE_INLINE bool autoCorrectsToMultiWordSuggestionIfTop() const {
return true;
}
AK_FORCE_INLINE int getDefaultExpandDicNodeSize() const {
return DicNodeVector::DEFAULT_NODES_SIZE_FOR_OPTIMIZATION;
}
AK_FORCE_INLINE bool sameAsTyped(
const DicTraverseSession *const traverseSession, const DicNode *const dicNode) const {
return traverseSession->getProximityInfoState(0)->sameAsTyped(
dicNode->getOutputWordBuf(), dicNode->getNodeCodePointCount());
}
AK_FORCE_INLINE int getMaxCacheSize(const int inputSize) const {
return (inputSize <= 1) ? ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT
: ScoringParams::MAX_CACHE_DIC_NODE_SIZE;