Move methods for scoring from Traversal to Scoring.

Bug: 8844931

Change-Id: I6137d06e597f4e7b81aaf29555199e18984f2c39
main
Keisuke Kuroyanagi 2013-12-18 15:44:50 +09:00
parent d5f5dd74c2
commit 9ee9095528
5 changed files with 16 additions and 15 deletions

View File

@ -43,6 +43,9 @@ class Scoring {
const int doubleLetterTerminalIndex, const int doubleLetterTerminalIndex,
const DoubleLetterLevel doubleLetterLevel) const = 0; const DoubleLetterLevel doubleLetterLevel) const = 0;
virtual bool doesAutoCorrectValidWord() 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: protected:
Scoring() {} Scoring() {}

View File

@ -41,11 +41,8 @@ class Traversal {
const DicNode *const dicNode) const = 0; const DicNode *const dicNode) const = 0;
virtual ProximityType getProximityType(const DicTraverseSession *const traverseSession, virtual ProximityType getProximityType(const DicTraverseSession *const traverseSession,
const DicNode *const dicNode, const DicNode *const childDicNode) const = 0; 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 bool needsToTraverseAllUserInput() const = 0;
virtual float getMaxSpatialDistance() const = 0; virtual float getMaxSpatialDistance() const = 0;
virtual bool autoCorrectsToMultiWordSuggestionIfTop() const = 0;
virtual int getDefaultExpandDicNodeSize() const = 0; virtual int getDefaultExpandDicNodeSize() const = 0;
virtual int getMaxCacheSize(const int inputSize) const = 0; virtual int getMaxCacheSize(const int inputSize) const = 0;
virtual bool isPossibleOmissionChildNode(const DicTraverseSession *const traverseSession, 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 // traverseSession->isPartiallyCommited() always returns false because we never auto partial
// commit for now. // commit for now.
const bool forceCommitMultiWords = (terminalSize > 0) ? const bool forceCommitMultiWords = (terminalSize > 0) ?
TRAVERSAL->autoCorrectsToMultiWordSuggestionIfTop() SCORING->autoCorrectsToMultiWordSuggestionIfTop()
&& (traverseSession->isPartiallyCommited() && (traverseSession->isPartiallyCommited()
|| (traverseSession->getInputSize() || (traverseSession->getInputSize()
>= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT >= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT
@ -234,7 +234,7 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
->getShortcutPositionOfPtNode(terminalDicNode->getPtNodePos())); ->getShortcutPositionOfPtNode(terminalDicNode->getPtNodePos()));
// Shortcut is not supported for multiple words suggestions. // Shortcut is not supported for multiple words suggestions.
// TODO: Check shortcuts during traversal 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() ? const int shortcutBaseScore = SCORING->doesAutoCorrectValidWord() ?
SCORING->calculateFinalScore(compoundDistance, traverseSession->getInputSize(), SCORING->calculateFinalScore(compoundDistance, traverseSession->getInputSize(),
true /* forceCommit */) : finalScore; true /* forceCommit */) : finalScore;

View File

@ -19,6 +19,7 @@
#include "defines.h" #include "defines.h"
#include "suggest/core/policy/scoring.h" #include "suggest/core/policy/scoring.h"
#include "suggest/core/session/dic_traverse_session.h"
#include "suggest/policyimpl/typing/scoring_params.h" #include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime { namespace latinime {
@ -71,6 +72,16 @@ class TypingScoring : public Scoring {
return false; 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: private:
DISALLOW_COPY_AND_ASSIGN(TypingScoring); DISALLOW_COPY_AND_ASSIGN(TypingScoring);
static const TypingScoring sInstance; static const TypingScoring sInstance;

View File

@ -137,20 +137,10 @@ class TypingTraversal : public Traversal {
return ScoringParams::MAX_SPATIAL_DISTANCE; return ScoringParams::MAX_SPATIAL_DISTANCE;
} }
AK_FORCE_INLINE bool autoCorrectsToMultiWordSuggestionIfTop() const {
return true;
}
AK_FORCE_INLINE int getDefaultExpandDicNodeSize() const { AK_FORCE_INLINE int getDefaultExpandDicNodeSize() const {
return DicNodeVector::DEFAULT_NODES_SIZE_FOR_OPTIMIZATION; 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 { AK_FORCE_INLINE int getMaxCacheSize(const int inputSize) const {
return (inputSize <= 1) ? ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT return (inputSize <= 1) ? ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT
: ScoringParams::MAX_CACHE_DIC_NODE_SIZE; : ScoringParams::MAX_CACHE_DIC_NODE_SIZE;