From dfab7335e8bb698af5ed37c65d990bf1e74b9b03 Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Mon, 8 Jul 2024 07:26:12 +0000 Subject: [PATCH] Do not apply typing correction when the score is not enough. when score < 0, literal-on-top is triggered, so better not to show the history candidate at the top. PiperOrigin-RevId: 650146088 --- src/prediction/user_history_predictor.cc | 5 ++++- src/prediction/user_history_predictor_test.cc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/prediction/user_history_predictor.cc b/src/prediction/user_history_predictor.cc index 78313b985..5089b9648 100644 --- a/src/prediction/user_history_predictor.cc +++ b/src/prediction/user_history_predictor.cc @@ -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; } diff --git a/src/prediction/user_history_predictor_test.cc b/src/prediction/user_history_predictor_test.cc index a87f63d2d..84fd7d9ab 100644 --- a/src/prediction/user_history_predictor_test.cc +++ b/src/prediction/user_history_predictor_test.cc @@ -4408,7 +4408,7 @@ TEST_F(UserHistoryPredictorTest, TypingCorrection) { std::vector expected; auto add_expected = [&](const std::string &key) { expected.emplace_back( - TypeCorrectedQuery{key, TypeCorrectedQuery::CORRECTION}); + TypeCorrectedQuery{key, TypeCorrectedQuery::CORRECTION, 1.0}); }; // かつこ -> がっこ and かっこ