From e324bf2d2fe46dbe052ab3c1b4153f0b1c50a9a0 Mon Sep 17 00:00:00 2001 From: Keita Miwa Date: Mon, 6 Nov 2023 08:32:37 +0000 Subject: [PATCH] Add flag guard for the NO_POS introduction. This CL adds a flag that controls whether to use NO_POS as default POS of Japanese Personal Dictionary or not. This CL also re-implement special treatment of SUGGESTION_ONLY, which is planned to be removed after successful launch. PiperOrigin-RevId: 579750421 --- src/dictionary/user_dictionary.cc | 9 +++++++++ src/dictionary/user_dictionary_test.cc | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dictionary/user_dictionary.cc b/src/dictionary/user_dictionary.cc index e14aa4a41..88043feb5 100644 --- a/src/dictionary/user_dictionary.cc +++ b/src/dictionary/user_dictionary.cc @@ -161,6 +161,8 @@ class UserDictionary::TokensIndex { if (!dic.enabled() || dic.entries_size() == 0) { continue; } + const bool is_android_shortcuts = + (dic.name() == "__auto_imported_android_shortcuts_dictionary"); for (const UserDictionaryStorage::UserDictionaryEntry &entry : dic.entries()) { @@ -215,6 +217,13 @@ class UserDictionary::TokensIndex { absl::StripAsciiWhitespace(entry.comment()); for (auto &token : tokens) { strings::Assign(token.comment, comment); + if (is_android_shortcuts && + token.has_attribute(UserPos::Token::SUGGESTION_ONLY)) { + // TODO(b/295964970): This special implementation is planned to be + // removed after validating the safety of NO_POS implementation. + 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 ff0b55886..1098f7569 100644 --- a/src/dictionary/user_dictionary_test.cc +++ b/src/dictionary/user_dictionary_test.cc @@ -541,7 +541,7 @@ 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"); @@ -565,6 +565,7 @@ TEST_F(UserDictionaryTest, TestLookupWithShortCut) { const Entry kExpected2[] = { {"key", "noun", kNounId, kNounId}, {"key", "no_pos", kUnknownId, kUnknownId}, + {"key", "suggest_only", kUnknownId, kUnknownId}, }; const Entry kExpectedPrediction[] = { {"key", "noun", kNounId, kNounId},