mirror of
https://github.com/browsermt/bergamot-translator.git
synced 2024-09-11 05:35:33 +03:00
Fix HTML with pivoting (#323)
Previously BlockingService pivoting missed preproc and postproc for HTML leading to issues in WebAssembly API. This change adds fixes for the same, along with test coverage for the functionality over both async and blocking services.
This commit is contained in:
parent
cfdda155e2
commit
95de806d1d
@ -1 +1 @@
|
||||
Subproject commit f5e9eb15a0323e33a80d18b4a9234c93242fd399
|
||||
Subproject commit aaf315c80b7339c2ae6fcca080ca30d3f0a5e2f5
|
@ -71,6 +71,8 @@ void TestSuite<Service>::TestSuite::run(const std::string &opModeAsString, std::
|
||||
translationCache(models.front());
|
||||
} else if (opModeAsString == "test-pivot") {
|
||||
pivotTranslate(models);
|
||||
} else if (opModeAsString == "test-pivot-with-html") {
|
||||
pivotTranslateWithHTML(models);
|
||||
} else if (opModeAsString == "test-html-translation") {
|
||||
htmlTranslation(models.front());
|
||||
} else {
|
||||
@ -226,6 +228,19 @@ void TestSuite<Service>::translationCache(Ptr<TranslationModel> model) {
|
||||
std::cout << firstResponse.target.text;
|
||||
}
|
||||
|
||||
template <class Service>
|
||||
void TestSuite<Service>::pivotTranslateWithHTML(std::vector<Ptr<TranslationModel>> &models) {
|
||||
ABORT_IF(models.size() != 2, "Forward and backward test needs two models.");
|
||||
ResponseOptions responseOptions;
|
||||
responseOptions.HTML = true;
|
||||
std::string source = readFromStdin();
|
||||
std::promise<Response> responsePromise;
|
||||
std::future<Response> responseFuture = responsePromise.get_future();
|
||||
Response response = bridge_.pivot(service_, models.front(), models.back(), std::move(source), responseOptions);
|
||||
std::cout << response.source.text;
|
||||
std::cout << response.target.text;
|
||||
}
|
||||
|
||||
template <class Service>
|
||||
void TestSuite<Service>::pivotTranslate(std::vector<Ptr<TranslationModel>> &models) {
|
||||
// We expect a source -> pivot; pivot -> source model to get source -> source and build this test using accuracy of
|
||||
|
@ -88,6 +88,8 @@ class TestSuite {
|
||||
|
||||
void pivotTranslate(std::vector<Ptr<TranslationModel>> &models);
|
||||
|
||||
void pivotTranslateWithHTML(std::vector<Ptr<TranslationModel>> &models);
|
||||
|
||||
void htmlTranslation(Ptr<TranslationModel> model);
|
||||
};
|
||||
|
||||
|
@ -81,6 +81,11 @@ std::vector<Response> BlockingService::pivotMultiple(std::shared_ptr<Translation
|
||||
std::shared_ptr<TranslationModel> second,
|
||||
std::vector<std::string> &&sources,
|
||||
const ResponseOptions &responseOptions) {
|
||||
std::vector<HTML> htmls;
|
||||
for (auto &&source : sources) {
|
||||
htmls.emplace_back(std::move(source), responseOptions.HTML);
|
||||
}
|
||||
|
||||
// Translate source to pivots. This is same as calling translateMultiple.
|
||||
std::vector<Response> sourcesToPivots;
|
||||
sourcesToPivots = translateMultipleRaw(first, std::move(sources), responseOptions);
|
||||
@ -115,6 +120,10 @@ std::vector<Response> BlockingService::pivotMultiple(std::shared_ptr<Translation
|
||||
finalResponses.push_back(std::move(finalResponse));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < finalResponses.size(); i++) {
|
||||
htmls[i].restore(finalResponses[i]);
|
||||
}
|
||||
|
||||
return finalResponses;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user