Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: extensions/renderer/i18n_custom_bindings.cc

Issue 2359793003: Modifying language detection code (Closed)
Patch Set: Modifying the bindings code to ignore xx-Latn predictions Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/translate/core/language_detection/language_detection_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/i18n_custom_bindings.h" 5 #include "extensions/renderer/i18n_custom_bindings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 } 129 }
130 130
131 #elif BUILDFLAG(CLD_VERSION) == 3 131 #elif BUILDFLAG(CLD_VERSION) == 3
132 void InitDetectedLanguages( 132 void InitDetectedLanguages(
133 const std::vector<chrome_lang_id::NNetLanguageIdentifier::Result>& 133 const std::vector<chrome_lang_id::NNetLanguageIdentifier::Result>&
134 lang_results, 134 lang_results,
135 LanguageDetectionResult* result) { 135 LanguageDetectionResult* result) {
136 std::vector<std::unique_ptr<DetectedLanguage>>* detected_languages = 136 std::vector<std::unique_ptr<DetectedLanguage>>* detected_languages =
137 &result->languages; 137 &result->languages;
138 detected_languages->clear();
Devlin 2016/09/27 18:34:42 Isn't this always the case? Could we DCHECK(detec
Anton Bakalov 2016/09/27 20:00:48 Done.
138 bool* is_reliable = &result->is_reliable; 139 bool* is_reliable = &result->is_reliable;
139 140
140 // is_reliable is set to "true", so that the reliability can be calculated by 141 // is_reliable is set to "true", so that the reliability can be calculated by
141 // &&'ing the reliability of each predicted language. 142 // &&'ing the reliability of each predicted language.
142 *is_reliable = true; 143 *is_reliable = true;
143 for (size_t i = 0; i < lang_results.size(); ++i) { 144 for (size_t i = 0; i < lang_results.size(); ++i) {
144 const chrome_lang_id::NNetLanguageIdentifier::Result& lang_result = 145 const chrome_lang_id::NNetLanguageIdentifier::Result& lang_result =
145 lang_results.at(i); 146 lang_results.at(i);
146 const std::string& language_code = lang_result.language; 147 const std::string& language_code = lang_result.language;
148
149 // If the first language is kUnknown, then all languages are kUnknown.
147 if (language_code == chrome_lang_id::NNetLanguageIdentifier::kUnknown) { 150 if (language_code == chrome_lang_id::NNetLanguageIdentifier::kUnknown) {
148 // If the first language is kUnknown, then all languages are kUnknown.
149 // Thus, is_reliable is set to "false".
150 if (i == 0) {
151 *is_reliable = false;
152 }
153 break; 151 break;
154 } 152 }
155 153
154 // Ignore languages that are currently not supported.
Devlin 2016/09/27 18:34:42 Can we expand this comment to include why these ar
Anton Bakalov 2016/09/27 20:00:48 Done.
155 if (language_code == "bg-Latn" ||
156 language_code == "el-Latn" ||
157 language_code == "hi-Latn" ||
158 language_code == "ja-Latn" ||
159 language_code == "ru-Latn" ||
160 language_code == "zh-Latn") {
161 continue;
162 }
163
156 *is_reliable = *is_reliable && lang_result.is_reliable; 164 *is_reliable = *is_reliable && lang_result.is_reliable;
157 const int percent = static_cast<int>(100 * lang_result.proportion); 165 const int percent = static_cast<int>(100 * lang_result.proportion);
158 detected_languages->push_back( 166 detected_languages->push_back(
159 base::MakeUnique<DetectedLanguage>(language_code, percent)); 167 base::MakeUnique<DetectedLanguage>(language_code, percent));
160 } 168 }
169
170 if (detected_languages->empty()) {
171 *is_reliable = false;
172 }
161 } 173 }
162 #else 174 #else
163 # error "CLD_VERSION must be 2 or 3" 175 # error "CLD_VERSION must be 2 or 3"
164 #endif 176 #endif
165 177
166 } // namespace 178 } // namespace
167 179
168 I18NCustomBindings::I18NCustomBindings(ScriptContext* context) 180 I18NCustomBindings::I18NCustomBindings(ScriptContext* context)
169 : ObjectBackedNativeHandler(context) { 181 : ObjectBackedNativeHandler(context) {
170 RouteFunction( 182 RouteFunction(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Populate LanguageDetectionResult with prediction reliability, languages, 314 // Populate LanguageDetectionResult with prediction reliability, languages,
303 // and the corresponding percentages. 315 // and the corresponding percentages.
304 InitDetectedLanguages(lang_results, &result); 316 InitDetectedLanguages(lang_results, &result);
305 args.GetReturnValue().Set(result.ToValue(context())); 317 args.GetReturnValue().Set(result.ToValue(context()));
306 #else 318 #else
307 # error "CLD_VERSION must be 2 or 3" 319 # error "CLD_VERSION must be 2 or 3"
308 #endif 320 #endif
309 } 321 }
310 322
311 } // namespace extensions 323 } // namespace extensions
OLDNEW
« no previous file with comments | « components/translate/core/language_detection/language_detection_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698