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