diff --git a/src/dictionary/user_dictionary.cc b/src/dictionary/user_dictionary.cc index 54fbf7035d..31bf0245e4 100644 --- a/src/dictionary/user_dictionary.cc +++ b/src/dictionary/user_dictionary.cc @@ -161,6 +161,9 @@ class UserDictionary::TokensIndex { continue; } + const bool is_shortcuts = + (dic.name() == "__auto_imported_android_shortcuts_dictionary"); + for (const UserDictionaryStorage::UserDictionaryEntry &entry : dic.entries()) { if (!UserDictionaryUtil::IsValidEntry(*user_pos_, entry)) { @@ -214,6 +217,17 @@ class UserDictionary::TokensIndex { absl::StripAsciiWhitespace(entry.comment()); for (auto &token : tokens) { strings::Assign(token.comment, comment); + if (is_shortcuts && + token.has_attribute(UserPos::Token::SUGGESTION_ONLY)) { + // Words fed by Android shortcut are registered as SUGGESTION_ONLY + // POS in order to minimize the side-effect of extremely short + // reading. However, user expect that they should appear in the + // normal conversion. Here we replace the attribute from + // SUGGESTION_ONLY to SHORTCUT, which has more adaptive cost based + // on the length of the key. + token.remove_attribute(UserPos::Token::SUGGESTION_ONLY); + token.add_attribute(UserPos::Token::SHORTCUT); + } user_pos_tokens_.push_back(std::move(token)); } } diff --git a/src/dictionary/user_dictionary_test.cc b/src/dictionary/user_dictionary_test.cc index 3759c5310a..8c750df393 100644 --- a/src/dictionary/user_dictionary_test.cc +++ b/src/dictionary/user_dictionary_test.cc @@ -584,18 +584,12 @@ TEST_F(UserDictionaryTest, TestLookupWithShortCut) { entry->set_value("noun"); entry->set_pos(user_dictionary::UserDictionary::NOUN); - // SUGGESTION ONLY word is not handled as SHORTCUT word. + // SUGGESTION ONLY word is handled as SHORTCUT word. entry = dic->add_entries(); entry->set_key("key"); entry->set_value("suggest_only"); entry->set_pos(user_dictionary::UserDictionary::SUGGESTION_ONLY); - // NO POS word is handled as SHORTCUT word. - entry = dic->add_entries(); - entry->set_key("key"); - entry->set_value("no_pos"); - entry->set_pos(user_dictionary::UserDictionary::NO_POS); - user_dic->Load(storage.GetProto()); } @@ -607,18 +601,13 @@ TEST_F(UserDictionaryTest, TestLookupWithShortCut) { const uint16_t kUnknownId = pos_matcher.GetUnknownId(); const Entry kExpected2[] = { {"key", "noun", kNounId, kNounId}, - {"key", "no_pos", kUnknownId, kUnknownId}, - }; - const Entry kExpectedPrediction[] = { - {"key", "noun", kNounId, kNounId}, - {"key", "no_pos", kUnknownId, kUnknownId}, {"key", "suggest_only", kUnknownId, kUnknownId}, }; EXPECT_TRUE(TestLookupExactHelper(kExpected2, std::size(kExpected2), "key", 3, *user_dic)); - EXPECT_TRUE(TestLookupPredictiveHelper(kExpectedPrediction, - std::size(kExpectedPrediction), "ke", *user_dic)); + EXPECT_TRUE(TestLookupPredictiveHelper(kExpected2, std::size(kExpected2), + "ke", *user_dic)); EXPECT_TRUE(TestLookupPrefixHelper(kExpected2, std::size(kExpected2), "keykey", 3, *user_dic)); }