Add New BatchTranslate API.

This commit is contained in:
sdk-team
2021-01-27 07:24:40 +00:00
parent 99cbb7279f
commit 9b90cedcbb
8 changed files with 330 additions and 0 deletions

View File

@@ -123,6 +123,42 @@ AlimtClient::CreateImageTranslateTaskOutcomeCallable AlimtClient::createImageTra
return task->get_future();
}
AlimtClient::GetBatchTranslateOutcome AlimtClient::getBatchTranslate(const GetBatchTranslateRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return GetBatchTranslateOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return GetBatchTranslateOutcome(GetBatchTranslateResult(outcome.result()));
else
return GetBatchTranslateOutcome(outcome.error());
}
void AlimtClient::getBatchTranslateAsync(const GetBatchTranslateRequest& request, const GetBatchTranslateAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, getBatchTranslate(request), context);
};
asyncExecute(new Runnable(fn));
}
AlimtClient::GetBatchTranslateOutcomeCallable AlimtClient::getBatchTranslateCallable(const GetBatchTranslateRequest &request) const
{
auto task = std::make_shared<std::packaged_task<GetBatchTranslateOutcome()>>(
[this, request]()
{
return this->getBatchTranslate(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
AlimtClient::GetDetectLanguageOutcome AlimtClient::getDetectLanguage(const GetDetectLanguageRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();

View File

@@ -0,0 +1,95 @@
/*
* Copyright 2009-2017 Alibaba Cloud 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 <alibabacloud/alimt/model/GetBatchTranslateRequest.h>
using AlibabaCloud::Alimt::Model::GetBatchTranslateRequest;
GetBatchTranslateRequest::GetBatchTranslateRequest() :
RpcServiceRequest("alimt", "2018-10-12", "GetBatchTranslate")
{
setMethod(HttpRequest::Method::Post);
}
GetBatchTranslateRequest::~GetBatchTranslateRequest()
{}
std::string GetBatchTranslateRequest::getSourceLanguage()const
{
return sourceLanguage_;
}
void GetBatchTranslateRequest::setSourceLanguage(const std::string& sourceLanguage)
{
sourceLanguage_ = sourceLanguage;
setBodyParameter("SourceLanguage", sourceLanguage);
}
std::string GetBatchTranslateRequest::getSourceText()const
{
return sourceText_;
}
void GetBatchTranslateRequest::setSourceText(const std::string& sourceText)
{
sourceText_ = sourceText;
setBodyParameter("SourceText", sourceText);
}
std::string GetBatchTranslateRequest::getFormatType()const
{
return formatType_;
}
void GetBatchTranslateRequest::setFormatType(const std::string& formatType)
{
formatType_ = formatType;
setBodyParameter("FormatType", formatType);
}
std::string GetBatchTranslateRequest::getApiType()const
{
return apiType_;
}
void GetBatchTranslateRequest::setApiType(const std::string& apiType)
{
apiType_ = apiType;
setBodyParameter("ApiType", apiType);
}
std::string GetBatchTranslateRequest::getScene()const
{
return scene_;
}
void GetBatchTranslateRequest::setScene(const std::string& scene)
{
scene_ = scene;
setBodyParameter("Scene", scene);
}
std::string GetBatchTranslateRequest::getTargetLanguage()const
{
return targetLanguage_;
}
void GetBatchTranslateRequest::setTargetLanguage(const std::string& targetLanguage)
{
targetLanguage_ = targetLanguage;
setBodyParameter("TargetLanguage", targetLanguage);
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2009-2017 Alibaba Cloud 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 <alibabacloud/alimt/model/GetBatchTranslateResult.h>
#include <json/json.h>
using namespace AlibabaCloud::Alimt;
using namespace AlibabaCloud::Alimt::Model;
GetBatchTranslateResult::GetBatchTranslateResult() :
ServiceResult()
{}
GetBatchTranslateResult::GetBatchTranslateResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
GetBatchTranslateResult::~GetBatchTranslateResult()
{}
void GetBatchTranslateResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
auto allTranslatedList = value["TranslatedList"]["Translated"];
for (const auto &item : allTranslatedList)
translatedList_.push_back(item.asString());
if(!value["Code"].isNull())
code_ = std::stoi(value["Code"].asString());
if(!value["Message"].isNull())
message_ = value["Message"].asString();
}
std::string GetBatchTranslateResult::getMessage()const
{
return message_;
}
std::vector<std::string> GetBatchTranslateResult::getTranslatedList()const
{
return translatedList_;
}
int GetBatchTranslateResult::getCode()const
{
return code_;
}