diff --git a/app/bergamot-translator-app-bytearray.cpp b/app/bergamot-translator-app-bytearray.cpp index 5186242..1fa5748 100644 --- a/app/bergamot-translator-app-bytearray.cpp +++ b/app/bergamot-translator-app-bytearray.cpp @@ -24,22 +24,10 @@ int main(int argc, char **argv) { TranslationRequest translationRequest; std::vector texts; - texts.emplace_back( - "The Bergamot project will add and improve client-side machine " - "translation in a web browser. Unlike current cloud-based " - "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."); + + for (std::string line; std::getline(std::cin, line);) { + texts.emplace_back(line); + } auto results = model.translate(std::move(texts), translationRequest); @@ -47,17 +35,7 @@ int main(int argc, char **argv) { //std::vector results = futureResults.get(); for (auto &result : results) { - std::cout << "[original]: " << result.getOriginalText() << 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; + std::cout << result.getTranslatedText() << std::endl; } return 0; diff --git a/app/bergamot-translator-app.cpp b/app/bergamot-translator-app.cpp index 086b9ca..4fba00b 100644 --- a/app/bergamot-translator-app.cpp +++ b/app/bergamot-translator-app.cpp @@ -21,7 +21,7 @@ int main(int argc, char **argv) { std::string config = options->asYamlString(); // Route the config string to construct marian model through TranslationModel - auto model = std::make_shared(config); + TranslationModel model(config); TranslationRequest translationRequest; std::vector texts; @@ -30,7 +30,7 @@ int main(int argc, char **argv) { texts.emplace_back(line); } - auto results = model->translate(std::move(texts), translationRequest); + auto results = model.translate(std::move(texts), translationRequest); // Resolve the future and get the actual result //std::vector results = futureResults.get(); diff --git a/app/service-cli-bytearray.cpp b/app/service-cli-bytearray.cpp index 6b3948b..f868d4d 100644 --- a/app/service-cli-bytearray.cpp +++ b/app/service-cli-bytearray.cpp @@ -31,7 +31,56 @@ int main(int argc, char *argv[]) { std::future responseFuture = service.translate(std::move(input)); responseFuture.wait(); Response response = responseFuture.get(); - std::cout << response.target.text << std::endl; + + std::cout << "[original]: " << response.source.text << '\n'; + std::cout << "[translated]: " << response.target.text << '\n'; + for (int sentenceIdx = 0; sentenceIdx < response.size(); sentenceIdx++) { + std::cout << " [src Sentence]: " << response.source.sentence(sentenceIdx) + << '\n'; + std::cout << " [tgt Sentence]: " << response.target.sentence(sentenceIdx) + << '\n'; + std::cout << "Alignments" << '\n'; + typedef std::pair Point; + + // Initialize a point vector. + std::vector> aggregate( + response.source.numWords(sentenceIdx)); + + // Handle alignments + auto &alignments = response.alignments[sentenceIdx]; + for (auto &p : alignments) { + aggregate[p.src].emplace_back(p.tgt, p.prob); + } + + for (size_t src = 0; src < aggregate.size(); src++) { + std::cout << response.source.word(sentenceIdx, src) << ": "; + for (auto &p : aggregate[src]) { + std::cout << response.target.word(sentenceIdx, p.first) << "(" + << p.second << ") "; + } + std::cout << '\n'; + } + + // Handle quality. + auto &quality = response.qualityScores[sentenceIdx]; + std::cout << "Quality: whole(" << quality.sequence + << "), tokens below:" << '\n'; + size_t wordIdx = 0; + bool first = true; + for (auto &p : quality.word) { + if (first) { + first = false; + } else { + std::cout << " "; + } + std::cout << response.target.word(sentenceIdx, wordIdx) << "(" << p + << ")"; + wordIdx++; + } + std::cout << '\n'; + } + std::cout << "--------------------------\n"; + std::cout << '\n'; return 0; }