mirror of
https://github.com/browsermt/bergamot-translator.git
synced 2024-09-17 16:47:18 +03:00
Change bergamot app to process stdin texts
This commit is contained in:
parent
bfb5e78602
commit
47db7e2b3e
@ -1,11 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* main.cpp
|
* main.cpp
|
||||||
*
|
*
|
||||||
* An example application to demonstrate the use of Bergamot translator.
|
* An application which accepts line separated texts in stdin and returns translated ones in stdout.
|
||||||
|
* It is convenient for batch processing and can be used with tools like SacreBLEU.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "TranslationModel.h"
|
#include "TranslationModel.h"
|
||||||
#include "translator/parser.h"
|
#include "translator/parser.h"
|
||||||
@ -23,22 +25,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
TranslationRequest translationRequest;
|
TranslationRequest translationRequest;
|
||||||
std::vector<std::string> texts;
|
std::vector<std::string> texts;
|
||||||
texts.emplace_back(
|
|
||||||
"The Bergamot project will add and improve client-side machine "
|
for (std::string line; std::getline(std::cin, line);) {
|
||||||
"translation in a web browser. Unlike current cloud-based "
|
texts.emplace_back(line);
|
||||||
"options, running directly on users’ machines empowers citizens to "
|
}
|
||||||
"preserve their privacy and increases the uptake of language "
|
|
||||||
"technologies in Europe in various sectors that require "
|
|
||||||
"confidentiality.");
|
|
||||||
texts.emplace_back(
|
|
||||||
"Free software integrated with an open-source web "
|
|
||||||
"browser, such as Mozilla Firefox, will enable bottom-up adoption "
|
|
||||||
"by non-experts, resulting in cost savings for private and public "
|
|
||||||
"sector users who would otherwise procure translation or operate "
|
|
||||||
"monolingually. Bergamot is a consortium coordinated by the "
|
|
||||||
"University of Edinburgh with partners Charles University in "
|
|
||||||
"Prague, the University of Sheffield, University of Tartu, and "
|
|
||||||
"Mozilla.");
|
|
||||||
|
|
||||||
auto results = model->translate(std::move(texts), translationRequest);
|
auto results = model->translate(std::move(texts), translationRequest);
|
||||||
|
|
||||||
@ -46,17 +36,7 @@ int main(int argc, char **argv) {
|
|||||||
//std::vector<TranslationResult> results = futureResults.get();
|
//std::vector<TranslationResult> results = futureResults.get();
|
||||||
|
|
||||||
for (auto &result : results) {
|
for (auto &result : results) {
|
||||||
std::cout << "[original]: " << result.getOriginalText() << std::endl;
|
std::cout << result.getTranslatedText() << std::endl;
|
||||||
std::cout << "[translated]: " << result.getTranslatedText() << std::endl;
|
|
||||||
auto mappings = result.getSentenceMappings();
|
|
||||||
for (auto &p : mappings) {
|
|
||||||
std::string_view src = p.first;
|
|
||||||
std::string_view tgt = p.second;
|
|
||||||
|
|
||||||
std::cout << " [src Sentence]: " << src << std::endl;
|
|
||||||
std::cout << " [tgt Sentence]: " << tgt << std::endl;
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user