diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 11:40:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 12:42:11 +0000 |
commit | 5d87695f37678f96492b258bbab36486c59866b4 (patch) | |
tree | be9783bbaf04fb930c4d74ca9c00b5e7954c8bc6 /chromium/third_party/cld_3/src/src/language_identifier_main.cc | |
parent | 6c11fb357ec39bf087b8b632e2b1e375aef1b38b (diff) | |
download | qtwebengine-chromium-5d87695f37678f96492b258bbab36486c59866b4.tar.gz |
BASELINE: Update Chromium to 75.0.3770.56
Change-Id: I86d2007fd27a45d5797eee06f4c9369b8b50ac4f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/cld_3/src/src/language_identifier_main.cc')
-rw-r--r-- | chromium/third_party/cld_3/src/src/language_identifier_main.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chromium/third_party/cld_3/src/src/language_identifier_main.cc b/chromium/third_party/cld_3/src/src/language_identifier_main.cc new file mode 100644 index 00000000000..b44f785bf23 --- /dev/null +++ b/chromium/third_party/cld_3/src/src/language_identifier_main.cc @@ -0,0 +1,54 @@ +/* Copyright 2016 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include <iostream> +#include <string> + +#include "base.h" +#include "nnet_language_identifier.h" + +using chrome_lang_id::NNetLanguageIdentifier; + +// Runs a neural net model for language identification. +int main(int argc, char **argv) { + NNetLanguageIdentifier lang_id(/*min_num_bytes=*/0, + /*max_num_bytes=*/1000); + + const std::vector<std::string> texts{"This text is written in English.", + "Text in deutscher Sprache verfasst."}; + for (const std::string &text : texts) { + const NNetLanguageIdentifier::Result result = lang_id.FindLanguage(text); + std::cout << "text: " << text << std::endl + << " language: " << result.language << std::endl + << " probability: " << result.probability << std::endl + << " reliable: " << result.is_reliable << std::endl + << " proportion: " << result.proportion << std::endl + << std::endl; + } + + const std::string &text = + "This piece of text is in English. Този текст е на Български."; + std::cout << "text: " << text << std::endl; + const std::vector<NNetLanguageIdentifier::Result> results = + lang_id.FindTopNMostFreqLangs(text, /*num_langs*/ 3); + for (const NNetLanguageIdentifier::Result &result : results) { + std::cout << " language: " << result.language << std::endl + << " probability: " << result.probability << std::endl + << " reliable: " << result.is_reliable << std::endl + << " proportion: " << result.proportion << std::endl + << std::endl; + } + return 0; +} |