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

@@ -1,3 +1,6 @@
2021-01-27 Version: patch
- Add New BatchTranslate API.
2021-01-27 Version: patch
- DetectFaceAttributes Add Score.

View File

@@ -25,6 +25,8 @@ set(alimt_public_header_model
include/alibabacloud/alimt/model/CreateDocTranslateTaskResult.h
include/alibabacloud/alimt/model/CreateImageTranslateTaskRequest.h
include/alibabacloud/alimt/model/CreateImageTranslateTaskResult.h
include/alibabacloud/alimt/model/GetBatchTranslateRequest.h
include/alibabacloud/alimt/model/GetBatchTranslateResult.h
include/alibabacloud/alimt/model/GetDetectLanguageRequest.h
include/alibabacloud/alimt/model/GetDetectLanguageResult.h
include/alibabacloud/alimt/model/GetDocTranslateTaskRequest.h
@@ -58,6 +60,8 @@ set(alimt_src
src/model/CreateDocTranslateTaskResult.cc
src/model/CreateImageTranslateTaskRequest.cc
src/model/CreateImageTranslateTaskResult.cc
src/model/GetBatchTranslateRequest.cc
src/model/GetBatchTranslateResult.cc
src/model/GetDetectLanguageRequest.cc
src/model/GetDetectLanguageResult.cc
src/model/GetDocTranslateTaskRequest.cc

View File

@@ -26,6 +26,8 @@
#include "model/CreateDocTranslateTaskResult.h"
#include "model/CreateImageTranslateTaskRequest.h"
#include "model/CreateImageTranslateTaskResult.h"
#include "model/GetBatchTranslateRequest.h"
#include "model/GetBatchTranslateResult.h"
#include "model/GetDetectLanguageRequest.h"
#include "model/GetDetectLanguageResult.h"
#include "model/GetDocTranslateTaskRequest.h"
@@ -67,6 +69,9 @@ namespace AlibabaCloud
typedef Outcome<Error, Model::CreateImageTranslateTaskResult> CreateImageTranslateTaskOutcome;
typedef std::future<CreateImageTranslateTaskOutcome> CreateImageTranslateTaskOutcomeCallable;
typedef std::function<void(const AlimtClient*, const Model::CreateImageTranslateTaskRequest&, const CreateImageTranslateTaskOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> CreateImageTranslateTaskAsyncHandler;
typedef Outcome<Error, Model::GetBatchTranslateResult> GetBatchTranslateOutcome;
typedef std::future<GetBatchTranslateOutcome> GetBatchTranslateOutcomeCallable;
typedef std::function<void(const AlimtClient*, const Model::GetBatchTranslateRequest&, const GetBatchTranslateOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> GetBatchTranslateAsyncHandler;
typedef Outcome<Error, Model::GetDetectLanguageResult> GetDetectLanguageOutcome;
typedef std::future<GetDetectLanguageOutcome> GetDetectLanguageOutcomeCallable;
typedef std::function<void(const AlimtClient*, const Model::GetDetectLanguageRequest&, const GetDetectLanguageOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> GetDetectLanguageAsyncHandler;
@@ -117,6 +122,9 @@ namespace AlibabaCloud
CreateImageTranslateTaskOutcome createImageTranslateTask(const Model::CreateImageTranslateTaskRequest &request)const;
void createImageTranslateTaskAsync(const Model::CreateImageTranslateTaskRequest& request, const CreateImageTranslateTaskAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
CreateImageTranslateTaskOutcomeCallable createImageTranslateTaskCallable(const Model::CreateImageTranslateTaskRequest& request) const;
GetBatchTranslateOutcome getBatchTranslate(const Model::GetBatchTranslateRequest &request)const;
void getBatchTranslateAsync(const Model::GetBatchTranslateRequest& request, const GetBatchTranslateAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
GetBatchTranslateOutcomeCallable getBatchTranslateCallable(const Model::GetBatchTranslateRequest& request) const;
GetDetectLanguageOutcome getDetectLanguage(const Model::GetDetectLanguageRequest &request)const;
void getDetectLanguageAsync(const Model::GetDetectLanguageRequest& request, const GetDetectLanguageAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
GetDetectLanguageOutcomeCallable getDetectLanguageCallable(const Model::GetDetectLanguageRequest& request) const;

View File

@@ -0,0 +1,63 @@
/*
* 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.
*/
#ifndef ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATEREQUEST_H_
#define ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATEREQUEST_H_
#include <string>
#include <vector>
#include <alibabacloud/core/RpcServiceRequest.h>
#include <alibabacloud/alimt/AlimtExport.h>
namespace AlibabaCloud
{
namespace Alimt
{
namespace Model
{
class ALIBABACLOUD_ALIMT_EXPORT GetBatchTranslateRequest : public RpcServiceRequest
{
public:
GetBatchTranslateRequest();
~GetBatchTranslateRequest();
std::string getSourceLanguage()const;
void setSourceLanguage(const std::string& sourceLanguage);
std::string getSourceText()const;
void setSourceText(const std::string& sourceText);
std::string getFormatType()const;
void setFormatType(const std::string& formatType);
std::string getApiType()const;
void setApiType(const std::string& apiType);
std::string getScene()const;
void setScene(const std::string& scene);
std::string getTargetLanguage()const;
void setTargetLanguage(const std::string& targetLanguage);
private:
std::string sourceLanguage_;
std::string sourceText_;
std::string formatType_;
std::string apiType_;
std::string scene_;
std::string targetLanguage_;
};
}
}
}
#endif // !ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATEREQUEST_H_

View File

@@ -0,0 +1,55 @@
/*
* 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.
*/
#ifndef ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATERESULT_H_
#define ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATERESULT_H_
#include <string>
#include <vector>
#include <utility>
#include <alibabacloud/core/ServiceResult.h>
#include <alibabacloud/alimt/AlimtExport.h>
namespace AlibabaCloud
{
namespace Alimt
{
namespace Model
{
class ALIBABACLOUD_ALIMT_EXPORT GetBatchTranslateResult : public ServiceResult
{
public:
GetBatchTranslateResult();
explicit GetBatchTranslateResult(const std::string &payload);
~GetBatchTranslateResult();
std::string getMessage()const;
std::vector<std::string> getTranslatedList()const;
int getCode()const;
protected:
void parse(const std::string &payload);
private:
std::string message_;
std::vector<std::string> translatedList_;
int code_;
};
}
}
}
#endif // !ALIBABACLOUD_ALIMT_MODEL_GETBATCHTRANSLATERESULT_H_

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_;
}