Skip to content

Commit

Permalink
Add flag guard for the NO_POS introduction.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ensan-hcl authored and hiroyuki-komatsu committed Nov 6, 2023
1 parent 013e8aa commit e324bf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/dictionary/user_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/dictionary/user_dictionary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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},
Expand Down

0 comments on commit e324bf2

Please sign in to comment.