Merge "Don't boost exact matches for personalized dicts."

This commit is contained in:
Keisuke Kuroyanagi 2014-02-04 09:13:48 +00:00 committed by Android (Google) Code Review
commit 1d3058daa1
5 changed files with 17 additions and 7 deletions

View file

@ -78,7 +78,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
outputAutoCommitFirstWordConfidence[0] = outputAutoCommitFirstWordConfidence[0] =
computeFirstWordConfidence(&terminals[0]); computeFirstWordConfidence(&terminals[0]);
} }
const bool boostExactMatches = traverseSession->getDictionaryStructurePolicy()->
getHeaderStructurePolicy()->shouldBoostExactMatches();
// 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) {
@ -102,7 +103,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
&& !(isPossiblyOffensiveWord && isFirstCharUppercase); && !(isPossiblyOffensiveWord && isFirstCharUppercase);
const int outputTypeFlags = const int outputTypeFlags =
(isPossiblyOffensiveWord ? Dictionary::KIND_FLAG_POSSIBLY_OFFENSIVE : 0) (isPossiblyOffensiveWord ? Dictionary::KIND_FLAG_POSSIBLY_OFFENSIVE : 0)
| (isSafeExactMatch ? Dictionary::KIND_FLAG_EXACT_MATCH : 0); | ((isSafeExactMatch && boostExactMatches) ? Dictionary::KIND_FLAG_EXACT_MATCH : 0);
// Entries that are blacklisted or do not represent a word should not be output. // Entries that are blacklisted or do not represent a word should not be output.
const bool isValidWord = !terminalDicNode->isBlacklistedOrNotAWord(); const bool isValidWord = !terminalDicNode->isBlacklistedOrNotAWord();
@ -113,7 +114,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
compoundDistance, traverseSession->getInputSize(), compoundDistance, traverseSession->getInputSize(),
terminalDicNode->getContainedErrorTypes(), terminalDicNode->getContainedErrorTypes(),
(forceCommitMultiWords && terminalDicNode->hasMultipleWords()) (forceCommitMultiWords && terminalDicNode->hasMultipleWords())
|| (isValidWord && scoringPolicy->doesAutoCorrectValidWord())); || (isValidWord && scoringPolicy->doesAutoCorrectValidWord()),
boostExactMatches);
if (maxScore < finalScore && isValidWord) { if (maxScore < finalScore && isValidWord) {
maxScore = finalScore; maxScore = finalScore;
} }
@ -147,7 +149,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
scoringPolicy->calculateFinalScore(compoundDistance, scoringPolicy->calculateFinalScore(compoundDistance,
traverseSession->getInputSize(), traverseSession->getInputSize(),
terminalDicNode->getContainedErrorTypes(), terminalDicNode->getContainedErrorTypes(),
true /* forceCommit */) : finalScore; true /* forceCommit */, boostExactMatches) : finalScore;
const int updatedOutputWordIndex = outputShortcuts(&shortcutIt, const int updatedOutputWordIndex = outputShortcuts(&shortcutIt,
outputWordIndex, shortcutBaseScore, outputCodePoints, frequencies, outputTypes, outputWordIndex, shortcutBaseScore, outputCodePoints, frequencies, outputTypes,
sameAsTyped); sameAsTyped);

View file

@ -40,6 +40,8 @@ class DictionaryHeaderStructurePolicy {
virtual void readHeaderValueOrQuestionMark(const char *const key, int *outValue, virtual void readHeaderValueOrQuestionMark(const char *const key, int *outValue,
int outValueSize) const = 0; int outValueSize) const = 0;
virtual bool shouldBoostExactMatches() const = 0;
protected: protected:
DictionaryHeaderStructurePolicy() {} DictionaryHeaderStructurePolicy() {}

View file

@ -28,7 +28,8 @@ class DicTraverseSession;
class Scoring { class Scoring {
public: public:
virtual int calculateFinalScore(const float compoundDistance, const int inputSize, virtual int calculateFinalScore(const float compoundDistance, const int inputSize,
const ErrorTypeUtils::ErrorType containedErrorTypes, const bool forceCommit) const = 0; const ErrorTypeUtils::ErrorType containedErrorTypes, const bool forceCommit,
const bool boostExactMatches) const = 0;
virtual bool getMostProbableString(const DicTraverseSession *const traverseSession, virtual bool getMostProbableString(const DicTraverseSession *const traverseSession,
const int terminalSize, const float languageWeight, int *const outputCodePoints, const int terminalSize, const float languageWeight, int *const outputCodePoints,
int *const type, int *const freq) const = 0; int *const type, int *const freq) const = 0;

View file

@ -146,6 +146,11 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
return mHasHistoricalInfoOfWords; return mHasHistoricalInfoOfWords;
} }
AK_FORCE_INLINE bool shouldBoostExactMatches() const {
// TODO: Investigate better ways to handle exact matches for personalized dictionaries.
return !isDecayingDict();
}
void readHeaderValueOrQuestionMark(const char *const key, void readHeaderValueOrQuestionMark(const char *const key,
int *outValue, int outValueSize) const; int *outValue, int outValueSize) const;

View file

@ -50,14 +50,14 @@ class TypingScoring : public Scoring {
AK_FORCE_INLINE int calculateFinalScore(const float compoundDistance, AK_FORCE_INLINE int calculateFinalScore(const float compoundDistance,
const int inputSize, const ErrorTypeUtils::ErrorType containedErrorTypes, const int inputSize, const ErrorTypeUtils::ErrorType containedErrorTypes,
const bool forceCommit) const { const bool forceCommit, const bool boostExactMatches) const {
const float maxDistance = ScoringParams::DISTANCE_WEIGHT_LANGUAGE const float maxDistance = ScoringParams::DISTANCE_WEIGHT_LANGUAGE
+ static_cast<float>(inputSize) * ScoringParams::TYPING_MAX_OUTPUT_SCORE_PER_INPUT; + static_cast<float>(inputSize) * ScoringParams::TYPING_MAX_OUTPUT_SCORE_PER_INPUT;
float score = ScoringParams::TYPING_BASE_OUTPUT_SCORE - compoundDistance / maxDistance; float score = ScoringParams::TYPING_BASE_OUTPUT_SCORE - compoundDistance / maxDistance;
if (forceCommit) { if (forceCommit) {
score += ScoringParams::AUTOCORRECT_OUTPUT_THRESHOLD; score += ScoringParams::AUTOCORRECT_OUTPUT_THRESHOLD;
} }
if (ErrorTypeUtils::isExactMatch(containedErrorTypes)) { if (boostExactMatches && ErrorTypeUtils::isExactMatch(containedErrorTypes)) {
score += ScoringParams::EXACT_MATCH_PROMOTION; score += ScoringParams::EXACT_MATCH_PROMOTION;
if ((ErrorTypeUtils::MATCH_WITH_CASE_ERROR & containedErrorTypes) != 0) { if ((ErrorTypeUtils::MATCH_WITH_CASE_ERROR & containedErrorTypes) != 0) {
score -= ScoringParams::CASE_ERROR_PENALTY_FOR_EXACT_MATCH; score -= ScoringParams::CASE_ERROR_PENALTY_FOR_EXACT_MATCH;