Codebase list mozc / 3afcf1f
Enable English word prediction for Qwerty mobile layouts This CL enables English word prediction with Japanese Qwerty layouts when language aware suggestion is turned on. Examples: Input: hell Before: へっ, へっ, 経っ, etc. After: へっ, へっ, hell, he'll, hello, etc. Input: st Before: st, st, ST, St, etc. After: stood, stall, stub, stan, etc. Implementation note: For English prediction, GetQueryForPrediction was used but it's replaced by GetRawString without breaking the previous behavior. REF_BUG=68479641 REF_CL=174962997 REF_TIME=2017-11-08T15:52:18+09:00 REF_TIME_RAW=1510123938 +0900 Noriyuki Takahashi 6 years ago
3 changed file(s) with 98 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
2929
3030 MAJOR=2
3131 MINOR=23
32 BUILD=2762
32 BUILD=2763
3333 REVISION=102
3434 # This version represents the version of Mozc IME engine (converter, predictor,
3535 # etc.). This version info is included both in the Mozc server and in the Mozc
6868
6969 DECLARE_bool(enable_typing_correction);
7070
71 using mozc::dictionary::DictionaryInterface;
72 using mozc::dictionary::POSMatcher;
73 using mozc::dictionary::Token;
74 using mozc::usage_stats::UsageStats;
75
7671 namespace mozc {
72 namespace {
7773
7874 using commands::Request;
79
80 namespace {
75 using dictionary::DictionaryInterface;
76 using dictionary::POSMatcher;
77 using dictionary::Token;
78 using usage_stats::UsageStats;
8179
8280 // Used to emulate positive infinity for cost. This value is set for those
8381 // candidates that are thought to be aggressive; thus we can eliminate such
10199 return (request.has_composer() &&
102100 (request.composer().GetInputMode() == transliteration::HALF_ASCII ||
103101 request.composer().GetInputMode() == transliteration::FULL_ASCII));
102 }
103
104 bool IsQwertyMobileTable(const ConversionRequest &request) {
105 const auto table = request.request().special_romanji_table();
106 return (table == commands::Request::QWERTY_MOBILE_TO_HIRAGANA ||
107 table == commands::Request::QWERTY_MOBILE_TO_HALFWIDTHASCII);
104108 }
105109
106110 // Returns true if |segments| contains number history.
16821686 }
16831687
16841688 string input_key;
1685 request.composer().GetQueryForPrediction(&input_key);
1689 request.composer().GetRawString(&input_key);
16861690 // We don't look up English words when key length is one.
16871691 if (input_key.size() < 2) {
16881692 return;
20262030 if ((segments.request_type() == Segments::PREDICTION && key_len >= 1) ||
20272031 key_len >= kMinUnigramKeyLen) {
20282032 result |= UNIGRAM;
2033
2034 const auto lang_aware = request.request().language_aware_input();
2035 if (lang_aware == commands::Request::LANGUAGE_AWARE_SUGGESTION &&
2036 IsQwertyMobileTable(request)) {
2037 result |= ENGLISH;
2038 }
20292039 }
20302040
20312041 const size_t history_segments_size = segments.history_segments_size();
10241024 EXPECT_EQ(DictionaryPredictor::REALTIME,
10251025 DictionaryPredictor::GetPredictionTypes(*convreq_, segments));
10261026 }
1027
1028 // When romaji table is qwerty mobile => ENGLISH is included depending on the
1029 // language aware input setting.
1030 {
1031 const auto orig_input_mode = composer_->GetInputMode();
1032 const auto orig_table = request_->special_romanji_table();
1033 const auto orig_lang_aware = request_->language_aware_input();
1034 const bool orig_use_dictionary_suggest = config_->use_dictionary_suggest();
1035
1036 composer_->SetInputMode(transliteration::HIRAGANA);
1037 config_->set_use_dictionary_suggest(true);
1038
1039 // The case where romaji table is set to qwerty. ENGLISH is turned on if
1040 // language aware input is enabled.
1041 for (const auto table :
1042 {commands::Request::QWERTY_MOBILE_TO_HIRAGANA,
1043 commands::Request::QWERTY_MOBILE_TO_HALFWIDTHASCII}) {
1044 request_->set_special_romanji_table(table);
1045
1046 // Language aware input is default: No English prediction.
1047 request_->set_language_aware_input(
1048 commands::Request::DEFAULT_LANGUAGE_AWARE_BEHAVIOR);
1049 auto type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1050 EXPECT_EQ(0, type & DictionaryPredictor::ENGLISH);
1051
1052 // Language aware input is off: No English prediction.
1053 request_->set_language_aware_input(
1054 commands::Request::NO_LANGUAGE_AWARE_INPUT);
1055 type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1056 EXPECT_EQ(0, type & DictionaryPredictor::ENGLISH);
1057
1058 // Language aware input is on: English prediction is included.
1059 request_->set_language_aware_input(
1060 commands::Request::LANGUAGE_AWARE_SUGGESTION);
1061 type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1062 EXPECT_EQ(DictionaryPredictor::ENGLISH,
1063 type & DictionaryPredictor::ENGLISH);
1064 }
1065
1066 // The case where romaji table is not qwerty. ENGLISH is turned off
1067 // regardless of language aware input setting.
1068 for (const auto table : {
1069 commands::Request::FLICK_TO_HALFWIDTHASCII,
1070 commands::Request::FLICK_TO_HIRAGANA,
1071 commands::Request::GODAN_TO_HALFWIDTHASCII,
1072 commands::Request::GODAN_TO_HIRAGANA,
1073 commands::Request::NOTOUCH_TO_HALFWIDTHASCII,
1074 commands::Request::NOTOUCH_TO_HIRAGANA,
1075 commands::Request::TOGGLE_FLICK_TO_HALFWIDTHASCII,
1076 commands::Request::TOGGLE_FLICK_TO_HIRAGANA,
1077 commands::Request::TWELVE_KEYS_TO_HALFWIDTHASCII,
1078 commands::Request::TWELVE_KEYS_TO_HIRAGANA,
1079 }) {
1080 request_->set_special_romanji_table(table);
1081
1082 // Language aware input is default.
1083 request_->set_language_aware_input(
1084 commands::Request::DEFAULT_LANGUAGE_AWARE_BEHAVIOR);
1085 auto type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1086 EXPECT_EQ(0, type & DictionaryPredictor::ENGLISH);
1087
1088 // Language aware input is off.
1089 request_->set_language_aware_input(
1090 commands::Request::NO_LANGUAGE_AWARE_INPUT);
1091 type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1092 EXPECT_EQ(0, type & DictionaryPredictor::ENGLISH);
1093
1094 // Language aware input is on.
1095 request_->set_language_aware_input(
1096 commands::Request::LANGUAGE_AWARE_SUGGESTION);
1097 type = DictionaryPredictor::GetPredictionTypes(*convreq_, segments);
1098 EXPECT_EQ(0, type & DictionaryPredictor::ENGLISH);
1099 }
1100
1101 config_->set_use_dictionary_suggest(orig_use_dictionary_suggest);
1102 request_->set_language_aware_input(orig_lang_aware);
1103 request_->set_special_romanji_table(orig_table);
1104 composer_->SetInputMode(orig_input_mode);
1105 }
10271106 }
10281107
10291108 TEST_F(DictionaryPredictorTest, GetPredictionTypesTestWithTypingCorrection) {