diff --git a/src/translator/TranslationModel.cpp b/src/translator/TranslationModel.cpp index 06b04eb5a..026a126ea 100644 --- a/src/translator/TranslationModel.cpp +++ b/src/translator/TranslationModel.cpp @@ -9,6 +9,7 @@ // All local project includes #include "TranslationModel.h" #include "translator/parser.h" +#include "translator/response.h" #include "translator/service.h" TranslationModel::TranslationModel(const std::string &config, @@ -21,31 +22,25 @@ TranslationModel::~TranslationModel() {} std::vector TranslationModel::translate(std::vector &&texts, TranslationRequest request) { - // Implementing a non-async version first. Unpleasant, but should work. - std::promise> promise; - auto future = promise.get_future(); // This code, move into async? std::vector translationResults; - for (auto &text : texts) { - // Collect future as marian::bergamot::TranslationResult - auto intermediate = service_.translate(std::move(text)); - intermediate.wait(); - auto marianResponse(std::move(intermediate.get())); - + std::vector responses = + service_.translateMultiple(std::move(texts), request); + for (auto &response : responses) { TranslationResult::SentenceMappings sentenceMappings; - for (size_t idx = 0; idx < marianResponse.size(); idx++) { - marian::string_view src = marianResponse.source.sentence(idx); - marian::string_view tgt = marianResponse.target.sentence(idx); + for (size_t idx = 0; idx < response.size(); idx++) { + marian::string_view src = response.source.sentence(idx); + marian::string_view tgt = response.target.sentence(idx); sentenceMappings.emplace_back(std::string_view(src.data(), src.size()), std::string_view(tgt.data(), tgt.size())); } // In place construction. translationResults.emplace_back( - std::move(marianResponse.source.text), // &&marianResponse.source_ - std::move(marianResponse.target.text), // &&marianResponse.translation_ - std::move(sentenceMappings) // &&sentenceMappings + std::move(response.source.text), // &&response.source_ + std::move(response.target.text), // &&response.translation_ + std::move(sentenceMappings) // &&sentenceMappings ); }