Skip to content

Commit

Permalink
Do not apply typing correction when the score is not enough.
Browse files Browse the repository at this point in the history
when score < 0, literal-on-top is triggered, so better not to show
the history candidate at the top.

PiperOrigin-RevId: 650146088
  • Loading branch information
taku910 authored and hiroyuki-komatsu committed Jul 8, 2024
1 parent 490dd84 commit dfab733
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/prediction/user_history_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,10 @@ void UserHistoryPredictor::GetResultsFromHistoryDictionary(
// Since dic_ is sorted in LRU, typing corrected queries are ranked lower
// than the original key.
for (const auto &c : corrected) {
if (LookupEntry(request_type, c.correction, c.correction, nullptr,
// Only apply when score > 0. When score < 0, we trigger literal-on-top
// in dictionary predictor.
if (c.score > 0.0 &&
LookupEntry(request_type, c.correction, c.correction, nullptr,
&(elm.value), prev_entry, results)) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/prediction/user_history_predictor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4408,7 +4408,7 @@ TEST_F(UserHistoryPredictorTest, TypingCorrection) {
std::vector<TypeCorrectedQuery> expected;
auto add_expected = [&](const std::string &key) {
expected.emplace_back(
TypeCorrectedQuery{key, TypeCorrectedQuery::CORRECTION});
TypeCorrectedQuery{key, TypeCorrectedQuery::CORRECTION, 1.0});
};

// かつこ -> がっこ and かっこ
Expand Down

0 comments on commit dfab733

Please sign in to comment.