/
client.rb
281 lines (252 loc) · 12.9 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# frozen_string_literal: true
# Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. 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.
require 'json'
module TencentCloud
module Mrs
module V20200910
class Client < TencentCloud::Common::AbstractClient
def initialize(credential, region, profile = nil)
api_version = '2020-09-10'
api_endpoint = 'mrs.tencentcloudapi.com'
sdk_version = 'MRS_' + File.read(File.expand_path('../VERSION', __dir__)).strip
super(credential, region, api_version, api_endpoint, sdk_version, profile)
end
# 医疗报告图片脱敏接口
# @param request: Request instance for ImageMask.
# @type request: :class:`Tencentcloud::mrs::V20200910::ImageMaskRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::ImageMaskResponse`
def ImageMask(request)
body = send_request('ImageMask', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = ImageMaskResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 图片脱敏-异步接口
# @param request: Request instance for ImageMaskAsync.
# @type request: :class:`Tencentcloud::mrs::V20200910::ImageMaskAsyncRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::ImageMaskAsyncResponse`
def ImageMaskAsync(request)
body = send_request('ImageMaskAsync', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = ImageMaskAsyncResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 图片脱敏-异步获取结果接口
# @param request: Request instance for ImageMaskAsyncGetResult.
# @type request: :class:`Tencentcloud::mrs::V20200910::ImageMaskAsyncGetResultRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::ImageMaskAsyncGetResultResponse`
def ImageMaskAsyncGetResult(request)
body = send_request('ImageMaskAsyncGetResult', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = ImageMaskAsyncGetResultResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 图片分类
# @param request: Request instance for ImageToClass.
# @type request: :class:`Tencentcloud::mrs::V20200910::ImageToClassRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::ImageToClassResponse`
def ImageToClass(request)
body = send_request('ImageToClass', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = ImageToClassResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 图片转结构化对象
# @param request: Request instance for ImageToObject.
# @type request: :class:`Tencentcloud::mrs::V20200910::ImageToObjectRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::ImageToObjectResponse`
def ImageToObject(request)
body = send_request('ImageToObject', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = ImageToObjectResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 文本分类
# 适用场景:经过腾讯医疗专用 OCR 从图片识别之后的文本,并且需要加上每个字符的坐标信息,才可以调用此接口。通过其它 OCR 识别的文本可能不适配。医院的 XML 格式文本也不适配,XML 文件需要经过特殊转换才能直接调用此接口。单次调用传入的文本不宜超过 2000 字。如有需要调用此接口,建议先咨询产品团队。
# @param request: Request instance for TextToClass.
# @type request: :class:`Tencentcloud::mrs::V20200910::TextToClassRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::TextToClassResponse`
def TextToClass(request)
body = send_request('TextToClass', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = TextToClassResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 文本转结构化对象。
# 适用场景:经过腾讯医疗专用 OCR 从图片识别之后的文本,可以调用此接口。通过其它 OCR 识别的文本可能不适配。医院的 XML 格式文本也不适配,XML 文件需要经过特殊转换才能直接调用此接口。单次调用传入的文本不宜超过 2000 字。
# @param request: Request instance for TextToObject.
# @type request: :class:`Tencentcloud::mrs::V20200910::TextToObjectRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::TextToObjectResponse`
def TextToObject(request)
body = send_request('TextToObject', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = TextToObjectResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 将PDF格式的体检报告文件结构化,解析关键信息。
# 注意:该接口是按照体检报告 PDF 页面数量统计次数,不是按照 PDF 文件数量统计次数。通过该接口传入的报告必须是体检报告,非体检报告可能无法正确解析。
# @param request: Request instance for TurnPDFToObject.
# @type request: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectResponse`
def TurnPDFToObject(request)
body = send_request('TurnPDFToObject', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = TurnPDFToObjectResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 体检报告PDF文件结构化-异步接口
# @param request: Request instance for TurnPDFToObjectAsync.
# @type request: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectAsyncRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectAsyncResponse`
def TurnPDFToObjectAsync(request)
body = send_request('TurnPDFToObjectAsync', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = TurnPDFToObjectAsyncResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
# 体检报告PDF文件结构化异步获取结果接口
# @param request: Request instance for TurnPDFToObjectAsyncGetResult.
# @type request: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectAsyncGetResultRequest`
# @rtype: :class:`Tencentcloud::mrs::V20200910::TurnPDFToObjectAsyncGetResultResponse`
def TurnPDFToObjectAsyncGetResult(request)
body = send_request('TurnPDFToObjectAsyncGetResult', request.serialize)
response = JSON.parse(body)
if response['Response'].key?('Error') == false
model = TurnPDFToObjectAsyncGetResultResponse.new
model.deserialize(response['Response'])
model
else
code = response['Response']['Error']['Code']
message = response['Response']['Error']['Message']
reqid = response['Response']['RequestId']
raise TencentCloud::Common::TencentCloudSDKException.new(code, message, reqid)
end
rescue TencentCloud::Common::TencentCloudSDKException => e
raise e
rescue StandardError => e
raise TencentCloud::Common::TencentCloudSDKException.new(nil, e.inspect)
end
end
end
end
end