ibm_watson 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ibm_watson.rb +1 -0
- data/lib/ibm_watson/assistant_v1.rb +282 -123
- data/lib/ibm_watson/assistant_v2.rb +16 -6
- data/lib/ibm_watson/compare_comply_v1.rb +653 -0
- data/lib/ibm_watson/discovery_v1.rb +322 -138
- data/lib/ibm_watson/language_translator_v3.rb +41 -30
- data/lib/ibm_watson/natural_language_classifier_v1.rb +32 -25
- data/lib/ibm_watson/natural_language_understanding_v1.rb +38 -17
- data/lib/ibm_watson/personality_insights_v3.rb +54 -36
- data/lib/ibm_watson/speech_to_text_v1.rb +247 -161
- data/lib/ibm_watson/text_to_speech_v1.rb +149 -41
- data/lib/ibm_watson/tone_analyzer_v3.rb +15 -9
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +113 -90
- data/test/integration/test_compare_comply_v1.rb +112 -0
- data/test/integration/test_personality_insights_v3.rb +3 -0
- data/test/integration/test_visual_recognition_v3.rb +1 -1
- data/test/unit/test_compare_comply_v1.rb +289 -0
- data/test/unit/test_personality_insights_v3.rb +4 -0
- data/test/unit/test_vcap_using_personality_insights.rb +3 -0
- data/test/unit/test_visual_recognition_v3.rb +6 -6
- metadata +5 -2
@@ -101,14 +101,17 @@ module IBMWatson
|
|
101
101
|
# **Note:** Currently, the v2 API does not support creating assistants.
|
102
102
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
103
103
|
def create_session(assistant_id:)
|
104
|
-
raise ArgumentError("assistant_id must be provided") if assistant_id.nil?
|
104
|
+
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?
|
105
105
|
|
106
106
|
headers = {
|
107
107
|
}
|
108
|
+
|
108
109
|
params = {
|
109
110
|
"version" => @version
|
110
111
|
}
|
112
|
+
|
111
113
|
method_url = "/v2/assistants/%s/sessions" % [ERB::Util.url_encode(assistant_id)]
|
114
|
+
|
112
115
|
response = request(
|
113
116
|
method: "POST",
|
114
117
|
url: method_url,
|
@@ -132,16 +135,19 @@ module IBMWatson
|
|
132
135
|
# @param session_id [String] Unique identifier of the session.
|
133
136
|
# @return [nil]
|
134
137
|
def delete_session(assistant_id:, session_id:)
|
135
|
-
raise ArgumentError("assistant_id must be provided") if assistant_id.nil?
|
138
|
+
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?
|
136
139
|
|
137
|
-
raise ArgumentError("session_id must be provided") if session_id.nil?
|
140
|
+
raise ArgumentError.new("session_id must be provided") if session_id.nil?
|
138
141
|
|
139
142
|
headers = {
|
140
143
|
}
|
144
|
+
|
141
145
|
params = {
|
142
146
|
"version" => @version
|
143
147
|
}
|
148
|
+
|
144
149
|
method_url = "/v2/assistants/%s/sessions/%s" % [ERB::Util.url_encode(assistant_id), ERB::Util.url_encode(session_id)]
|
150
|
+
|
145
151
|
request(
|
146
152
|
method: "DELETE",
|
147
153
|
url: method_url,
|
@@ -168,24 +174,28 @@ module IBMWatson
|
|
168
174
|
#
|
169
175
|
# **Note:** Currently, the v2 API does not support creating assistants.
|
170
176
|
# @param session_id [String] Unique identifier of the session.
|
171
|
-
# @param input [MessageInput]
|
177
|
+
# @param input [MessageInput] The user input.
|
172
178
|
# @param context [MessageContext] State information for the conversation.
|
173
179
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
174
180
|
def message(assistant_id:, session_id:, input: nil, context: nil)
|
175
|
-
raise ArgumentError("assistant_id must be provided") if assistant_id.nil?
|
181
|
+
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?
|
176
182
|
|
177
|
-
raise ArgumentError("session_id must be provided") if session_id.nil?
|
183
|
+
raise ArgumentError.new("session_id must be provided") if session_id.nil?
|
178
184
|
|
179
185
|
headers = {
|
180
186
|
}
|
187
|
+
|
181
188
|
params = {
|
182
189
|
"version" => @version
|
183
190
|
}
|
191
|
+
|
184
192
|
data = {
|
185
193
|
"input" => input,
|
186
194
|
"context" => context
|
187
195
|
}
|
196
|
+
|
188
197
|
method_url = "/v2/assistants/%s/sessions/%s/message" % [ERB::Util.url_encode(assistant_id), ERB::Util.url_encode(session_id)]
|
198
|
+
|
189
199
|
response = request(
|
190
200
|
method: "POST",
|
191
201
|
url: method_url,
|
@@ -0,0 +1,653 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 IBM All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# IBM Watson™ Compare and Comply analyzes governing documents to provide details
|
18
|
+
# about critical aspects of the documents.
|
19
|
+
|
20
|
+
require "concurrent"
|
21
|
+
require "erb"
|
22
|
+
require "json"
|
23
|
+
require_relative "./detailed_response"
|
24
|
+
|
25
|
+
require_relative "./watson_service"
|
26
|
+
|
27
|
+
# Module for the Watson APIs
|
28
|
+
module IBMWatson
|
29
|
+
##
|
30
|
+
# The Compare Comply V1 service.
|
31
|
+
class CompareComplyV1 < WatsonService
|
32
|
+
include Concurrent::Async
|
33
|
+
##
|
34
|
+
# @!method initialize(args)
|
35
|
+
# Construct a new client for the Compare Comply service.
|
36
|
+
#
|
37
|
+
# @param args [Hash] The args to initialize with
|
38
|
+
# @option args version [String] The API version date to use with the service, in
|
39
|
+
# "YYYY-MM-DD" format. Whenever the API is changed in a backwards
|
40
|
+
# incompatible way, a new minor version of the API is released.
|
41
|
+
# The service uses the API version for the date you specify, or
|
42
|
+
# the most recent version before that date. Note that you should
|
43
|
+
# not programmatically specify the current date at runtime, in
|
44
|
+
# case the API has been updated since your application's release.
|
45
|
+
# Instead, specify a version date that is compatible with your
|
46
|
+
# application, and don't change it until your application is
|
47
|
+
# ready for a later version.
|
48
|
+
# @option args url [String] The base url to use when contacting the service (e.g.
|
49
|
+
# "https://gateway.watsonplatform.net/compare-comply/api").
|
50
|
+
# The base url may differ between Bluemix regions.
|
51
|
+
# @option args iam_apikey [String] An API key that can be used to request IAM tokens. If
|
52
|
+
# this API key is provided, the SDK will manage the token and handle the
|
53
|
+
# refreshing.
|
54
|
+
# @option args iam_access_token [String] An IAM access token is fully managed by the application.
|
55
|
+
# Responsibility falls on the application to refresh the token, either before
|
56
|
+
# it expires or reactively upon receiving a 401 from the service as any requests
|
57
|
+
# made with an expired token will fail.
|
58
|
+
# @option args iam_url [String] An optional URL for the IAM service API. Defaults to
|
59
|
+
# 'https://iam.ng.bluemix.net/identity/token'.
|
60
|
+
def initialize(args = {})
|
61
|
+
@__async_initialized__ = false
|
62
|
+
defaults = {}
|
63
|
+
defaults[:version] = nil
|
64
|
+
defaults[:url] = "https://gateway.watsonplatform.net/compare-comply/api"
|
65
|
+
defaults[:iam_apikey] = nil
|
66
|
+
defaults[:iam_access_token] = nil
|
67
|
+
defaults[:iam_url] = nil
|
68
|
+
args = defaults.merge(args)
|
69
|
+
args[:vcap_services_name] = "compare-comply"
|
70
|
+
super
|
71
|
+
@version = args[:version]
|
72
|
+
end
|
73
|
+
|
74
|
+
#########################
|
75
|
+
# HTML conversion
|
76
|
+
#########################
|
77
|
+
|
78
|
+
##
|
79
|
+
# @!method convert_to_html(file:, model_id: nil, file_content_type: nil, filename: nil)
|
80
|
+
# Convert file to HTML.
|
81
|
+
# Uploads an input file. The response includes an HTML version of the document.
|
82
|
+
# @param file [File] The file to convert.
|
83
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
84
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
85
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
86
|
+
# well as to the methods' use in batch-processing requests.
|
87
|
+
# @param file_content_type [String] The content type of file.
|
88
|
+
# @param filename [String] The filename for file.
|
89
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
90
|
+
def convert_to_html(file:, model_id: nil, file_content_type: nil, filename: nil)
|
91
|
+
raise ArgumentError.new("file must be provided") if file.nil?
|
92
|
+
|
93
|
+
headers = {
|
94
|
+
}
|
95
|
+
|
96
|
+
params = {
|
97
|
+
"version" => @version,
|
98
|
+
"model_id" => model_id
|
99
|
+
}
|
100
|
+
|
101
|
+
form_data = {}
|
102
|
+
|
103
|
+
unless file.instance_of?(StringIO) || file.instance_of?(File)
|
104
|
+
file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file)
|
105
|
+
end
|
106
|
+
filename = file.path if filename.nil? && file.respond_to?(:path)
|
107
|
+
form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: filename)
|
108
|
+
|
109
|
+
method_url = "/v1/html_conversion"
|
110
|
+
|
111
|
+
response = request(
|
112
|
+
method: "POST",
|
113
|
+
url: method_url,
|
114
|
+
headers: headers,
|
115
|
+
params: params,
|
116
|
+
form: form_data,
|
117
|
+
accept_json: true
|
118
|
+
)
|
119
|
+
response
|
120
|
+
end
|
121
|
+
#########################
|
122
|
+
# Element classification
|
123
|
+
#########################
|
124
|
+
|
125
|
+
##
|
126
|
+
# @!method classify_elements(file:, model_id: nil, file_content_type: nil, filename: nil)
|
127
|
+
# Classify the elements of a document.
|
128
|
+
# Uploads a file. The response includes an analysis of the document's structural and
|
129
|
+
# semantic elements.
|
130
|
+
# @param file [File] The file to classify.
|
131
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
132
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
133
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
134
|
+
# well as to the methods' use in batch-processing requests.
|
135
|
+
# @param file_content_type [String] The content type of file.
|
136
|
+
# @param filename [String] The filename for file.
|
137
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
138
|
+
def classify_elements(file:, model_id: nil, file_content_type: nil, filename: nil)
|
139
|
+
raise ArgumentError.new("file must be provided") if file.nil?
|
140
|
+
|
141
|
+
headers = {
|
142
|
+
}
|
143
|
+
|
144
|
+
params = {
|
145
|
+
"version" => @version,
|
146
|
+
"model_id" => model_id
|
147
|
+
}
|
148
|
+
|
149
|
+
form_data = {}
|
150
|
+
|
151
|
+
unless file.instance_of?(StringIO) || file.instance_of?(File)
|
152
|
+
file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file)
|
153
|
+
end
|
154
|
+
filename = file.path if filename.nil? && file.respond_to?(:path)
|
155
|
+
form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: filename)
|
156
|
+
|
157
|
+
method_url = "/v1/element_classification"
|
158
|
+
|
159
|
+
response = request(
|
160
|
+
method: "POST",
|
161
|
+
url: method_url,
|
162
|
+
headers: headers,
|
163
|
+
params: params,
|
164
|
+
form: form_data,
|
165
|
+
accept_json: true
|
166
|
+
)
|
167
|
+
response
|
168
|
+
end
|
169
|
+
#########################
|
170
|
+
# Tables
|
171
|
+
#########################
|
172
|
+
|
173
|
+
##
|
174
|
+
# @!method extract_tables(file:, model_id: nil, file_content_type: nil, filename: nil)
|
175
|
+
# Extract a document's tables.
|
176
|
+
# Uploads a file. The response includes an analysis of the document's tables.
|
177
|
+
# @param file [File] The file on which to run table extraction.
|
178
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
179
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
180
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
181
|
+
# well as to the methods' use in batch-processing requests.
|
182
|
+
# @param file_content_type [String] The content type of file.
|
183
|
+
# @param filename [String] The filename for file.
|
184
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
185
|
+
def extract_tables(file:, model_id: nil, file_content_type: nil, filename: nil)
|
186
|
+
raise ArgumentError.new("file must be provided") if file.nil?
|
187
|
+
|
188
|
+
headers = {
|
189
|
+
}
|
190
|
+
|
191
|
+
params = {
|
192
|
+
"version" => @version,
|
193
|
+
"model_id" => model_id
|
194
|
+
}
|
195
|
+
|
196
|
+
form_data = {}
|
197
|
+
|
198
|
+
unless file.instance_of?(StringIO) || file.instance_of?(File)
|
199
|
+
file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file)
|
200
|
+
end
|
201
|
+
filename = file.path if filename.nil? && file.respond_to?(:path)
|
202
|
+
form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: filename)
|
203
|
+
|
204
|
+
method_url = "/v1/tables"
|
205
|
+
|
206
|
+
response = request(
|
207
|
+
method: "POST",
|
208
|
+
url: method_url,
|
209
|
+
headers: headers,
|
210
|
+
params: params,
|
211
|
+
form: form_data,
|
212
|
+
accept_json: true
|
213
|
+
)
|
214
|
+
response
|
215
|
+
end
|
216
|
+
#########################
|
217
|
+
# Comparison
|
218
|
+
#########################
|
219
|
+
|
220
|
+
##
|
221
|
+
# @!method compare_documents(file_1:, file_2:, file_1_label: nil, file_2_label: nil, model_id: nil, file_1_content_type: nil, file_1_filename: nil, file_2_content_type: nil, file_2_filename: nil)
|
222
|
+
# Compare two documents.
|
223
|
+
# Uploads two input files. The response includes JSON comparing the two documents.
|
224
|
+
# Uploaded files must be in the same file format.
|
225
|
+
# @param file_1 [File] The first file to compare.
|
226
|
+
# @param file_2 [File] The second file to compare.
|
227
|
+
# @param file_1_label [String] A text label for the first file.
|
228
|
+
# @param file_2_label [String] A text label for the second file.
|
229
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
230
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
231
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
232
|
+
# well as to the methods' use in batch-processing requests.
|
233
|
+
# @param file_1_content_type [String] The content type of file_1.
|
234
|
+
# @param file_1_filename [String] The filename for file_1.
|
235
|
+
# @param file_2_content_type [String] The content type of file_2.
|
236
|
+
# @param file_2_filename [String] The filename for file_2.
|
237
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
238
|
+
def compare_documents(file_1:, file_2:, file_1_label: nil, file_2_label: nil, model_id: nil, file_1_content_type: nil, file_1_filename: nil, file_2_content_type: nil, file_2_filename: nil)
|
239
|
+
raise ArgumentError.new("file_1 must be provided") if file_1.nil?
|
240
|
+
|
241
|
+
raise ArgumentError.new("file_2 must be provided") if file_2.nil?
|
242
|
+
|
243
|
+
headers = {
|
244
|
+
}
|
245
|
+
|
246
|
+
params = {
|
247
|
+
"version" => @version,
|
248
|
+
"file_1_label" => file_1_label,
|
249
|
+
"file_2_label" => file_2_label,
|
250
|
+
"model_id" => model_id
|
251
|
+
}
|
252
|
+
|
253
|
+
form_data = {}
|
254
|
+
|
255
|
+
unless file_1.instance_of?(StringIO) || file_1.instance_of?(File)
|
256
|
+
file_1 = file_1.respond_to?(:to_json) ? StringIO.new(file_1.to_json) : StringIO.new(file_1)
|
257
|
+
end
|
258
|
+
file_1_filename = file_1.path if file_1_filename.nil? && file_1.respond_to?(:path)
|
259
|
+
form_data[:file_1] = HTTP::FormData::File.new(file_1, content_type: file_1_content_type.nil? ? "application/octet-stream" : file_1_content_type, filename: file_1_filename)
|
260
|
+
|
261
|
+
unless file_2.instance_of?(StringIO) || file_2.instance_of?(File)
|
262
|
+
file_2 = file_2.respond_to?(:to_json) ? StringIO.new(file_2.to_json) : StringIO.new(file_2)
|
263
|
+
end
|
264
|
+
file_2_filename = file_2.path if file_2_filename.nil? && file_2.respond_to?(:path)
|
265
|
+
form_data[:file_2] = HTTP::FormData::File.new(file_2, content_type: file_2_content_type.nil? ? "application/octet-stream" : file_2_content_type, filename: file_2_filename)
|
266
|
+
|
267
|
+
method_url = "/v1/comparison"
|
268
|
+
|
269
|
+
response = request(
|
270
|
+
method: "POST",
|
271
|
+
url: method_url,
|
272
|
+
headers: headers,
|
273
|
+
params: params,
|
274
|
+
form: form_data,
|
275
|
+
accept_json: true
|
276
|
+
)
|
277
|
+
response
|
278
|
+
end
|
279
|
+
#########################
|
280
|
+
# Feedback
|
281
|
+
#########################
|
282
|
+
|
283
|
+
##
|
284
|
+
# @!method add_feedback(feedback_data:, user_id: nil, comment: nil)
|
285
|
+
# Add feedback.
|
286
|
+
# Adds feedback in the form of _labels_ from a subject-matter expert (SME) to a
|
287
|
+
# governing document.
|
288
|
+
# **Important:** Feedback is not immediately incorporated into the training model,
|
289
|
+
# nor is it guaranteed to be incorporated at a later date. Instead, submitted
|
290
|
+
# feedback is used to suggest future updates to the training model.
|
291
|
+
# @param feedback_data [FeedbackDataInput] Feedback data for submission.
|
292
|
+
# @param user_id [String] An optional string identifying the user.
|
293
|
+
# @param comment [String] An optional comment on or description of the feedback.
|
294
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
295
|
+
def add_feedback(feedback_data:, user_id: nil, comment: nil)
|
296
|
+
raise ArgumentError.new("feedback_data must be provided") if feedback_data.nil?
|
297
|
+
|
298
|
+
headers = {
|
299
|
+
}
|
300
|
+
|
301
|
+
params = {
|
302
|
+
"version" => @version
|
303
|
+
}
|
304
|
+
|
305
|
+
data = {
|
306
|
+
"feedback_data" => feedback_data,
|
307
|
+
"user_id" => user_id,
|
308
|
+
"comment" => comment
|
309
|
+
}
|
310
|
+
|
311
|
+
method_url = "/v1/feedback"
|
312
|
+
|
313
|
+
response = request(
|
314
|
+
method: "POST",
|
315
|
+
url: method_url,
|
316
|
+
headers: headers,
|
317
|
+
params: params,
|
318
|
+
json: data,
|
319
|
+
accept_json: true
|
320
|
+
)
|
321
|
+
response
|
322
|
+
end
|
323
|
+
|
324
|
+
##
|
325
|
+
# @!method list_feedback(feedback_type: nil, before: nil, after: nil, document_title: nil, model_id: nil, model_version: nil, category_removed: nil, category_added: nil, category_not_changed: nil, type_removed: nil, type_added: nil, type_not_changed: nil, page_limit: nil, cursor: nil, sort: nil, include_total: nil)
|
326
|
+
# List the feedback in documents.
|
327
|
+
# @param feedback_type [String] An optional string that filters the output to include only feedback with the
|
328
|
+
# specified feedback type. The only permitted value is `element_classification`.
|
329
|
+
# @param before [Time] An optional string in the format `YYYY-MM-DD` that filters the output to include
|
330
|
+
# only feedback that was added before the specified date.
|
331
|
+
# @param after [Time] An optional string in the format `YYYY-MM-DD` that filters the output to include
|
332
|
+
# only feedback that was added after the specified date.
|
333
|
+
# @param document_title [String] An optional string that filters the output to include only feedback from the
|
334
|
+
# document with the specified `document_title`.
|
335
|
+
# @param model_id [String] An optional string that filters the output to include only feedback with the
|
336
|
+
# specified `model_id`. The only permitted value is `contracts`.
|
337
|
+
# @param model_version [String] An optional string that filters the output to include only feedback with the
|
338
|
+
# specified `model_version`.
|
339
|
+
# @param category_removed [String] An optional string in the form of a comma-separated list of categories. If this is
|
340
|
+
# specified, the service filters the output to include only feedback that has at
|
341
|
+
# least one category from the list removed.
|
342
|
+
# @param category_added [String] An optional string in the form of a comma-separated list of categories. If this is
|
343
|
+
# specified, the service filters the output to include only feedback that has at
|
344
|
+
# least one category from the list added.
|
345
|
+
# @param category_not_changed [String] An optional string in the form of a comma-separated list of categories. If this is
|
346
|
+
# specified, the service filters the output to include only feedback that has at
|
347
|
+
# least one category from the list unchanged.
|
348
|
+
# @param type_removed [String] An optional string of comma-separated `nature`:`party` pairs. If this is
|
349
|
+
# specified, the service filters the output to include only feedback that has at
|
350
|
+
# least one `nature`:`party` pair from the list removed.
|
351
|
+
# @param type_added [String] An optional string of comma-separated `nature`:`party` pairs. If this is
|
352
|
+
# specified, the service filters the output to include only feedback that has at
|
353
|
+
# least one `nature`:`party` pair from the list removed.
|
354
|
+
# @param type_not_changed [String] An optional string of comma-separated `nature`:`party` pairs. If this is
|
355
|
+
# specified, the service filters the output to include only feedback that has at
|
356
|
+
# least one `nature`:`party` pair from the list unchanged.
|
357
|
+
# @param page_limit [Fixnum] An optional integer specifying the number of documents that you want the service
|
358
|
+
# to return.
|
359
|
+
# @param cursor [String] An optional string that returns the set of documents after the previous set. Use
|
360
|
+
# this parameter with the `page_limit` parameter.
|
361
|
+
# @param sort [String] An optional comma-separated list of fields in the document to sort on. You can
|
362
|
+
# optionally specify the sort direction by prefixing the value of the field with `-`
|
363
|
+
# for descending order or `+` for ascending order (the default). Currently permitted
|
364
|
+
# sorting fields are `created`, `user_id`, and `document_title`.
|
365
|
+
# @param include_total [Boolean] An optional boolean value. If specified as `true`, the `pagination` object in the
|
366
|
+
# output includes a value called `total` that gives the total count of feedback
|
367
|
+
# created.
|
368
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
369
|
+
def list_feedback(feedback_type: nil, before: nil, after: nil, document_title: nil, model_id: nil, model_version: nil, category_removed: nil, category_added: nil, category_not_changed: nil, type_removed: nil, type_added: nil, type_not_changed: nil, page_limit: nil, cursor: nil, sort: nil, include_total: nil)
|
370
|
+
headers = {
|
371
|
+
}
|
372
|
+
|
373
|
+
params = {
|
374
|
+
"version" => @version,
|
375
|
+
"feedback_type" => feedback_type,
|
376
|
+
"before" => before,
|
377
|
+
"after" => after,
|
378
|
+
"document_title" => document_title,
|
379
|
+
"model_id" => model_id,
|
380
|
+
"model_version" => model_version,
|
381
|
+
"category_removed" => category_removed,
|
382
|
+
"category_added" => category_added,
|
383
|
+
"category_not_changed" => category_not_changed,
|
384
|
+
"type_removed" => type_removed,
|
385
|
+
"type_added" => type_added,
|
386
|
+
"type_not_changed" => type_not_changed,
|
387
|
+
"page_limit" => page_limit,
|
388
|
+
"cursor" => cursor,
|
389
|
+
"sort" => sort,
|
390
|
+
"include_total" => include_total
|
391
|
+
}
|
392
|
+
|
393
|
+
method_url = "/v1/feedback"
|
394
|
+
|
395
|
+
response = request(
|
396
|
+
method: "GET",
|
397
|
+
url: method_url,
|
398
|
+
headers: headers,
|
399
|
+
params: params,
|
400
|
+
accept_json: true
|
401
|
+
)
|
402
|
+
response
|
403
|
+
end
|
404
|
+
|
405
|
+
##
|
406
|
+
# @!method get_feedback(feedback_id:, model_id: nil)
|
407
|
+
# List a specified feedback entry.
|
408
|
+
# @param feedback_id [String] An string that specifies the feedback entry to be included in the output.
|
409
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
410
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
411
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
412
|
+
# well as to the methods' use in batch-processing requests.
|
413
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
414
|
+
def get_feedback(feedback_id:, model_id: nil)
|
415
|
+
raise ArgumentError.new("feedback_id must be provided") if feedback_id.nil?
|
416
|
+
|
417
|
+
headers = {
|
418
|
+
}
|
419
|
+
|
420
|
+
params = {
|
421
|
+
"version" => @version,
|
422
|
+
"model_id" => model_id
|
423
|
+
}
|
424
|
+
|
425
|
+
method_url = "/v1/feedback/%s" % [ERB::Util.url_encode(feedback_id)]
|
426
|
+
|
427
|
+
response = request(
|
428
|
+
method: "GET",
|
429
|
+
url: method_url,
|
430
|
+
headers: headers,
|
431
|
+
params: params,
|
432
|
+
accept_json: true
|
433
|
+
)
|
434
|
+
response
|
435
|
+
end
|
436
|
+
|
437
|
+
##
|
438
|
+
# @!method delete_feedback(feedback_id:, model_id: nil)
|
439
|
+
# Deletes a specified feedback entry.
|
440
|
+
# @param feedback_id [String] An string that specifies the feedback entry to be deleted from the document.
|
441
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
442
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
443
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
444
|
+
# well as to the methods' use in batch-processing requests.
|
445
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
446
|
+
def delete_feedback(feedback_id:, model_id: nil)
|
447
|
+
raise ArgumentError.new("feedback_id must be provided") if feedback_id.nil?
|
448
|
+
|
449
|
+
headers = {
|
450
|
+
}
|
451
|
+
|
452
|
+
params = {
|
453
|
+
"version" => @version,
|
454
|
+
"model_id" => model_id
|
455
|
+
}
|
456
|
+
|
457
|
+
method_url = "/v1/feedback/%s" % [ERB::Util.url_encode(feedback_id)]
|
458
|
+
|
459
|
+
response = request(
|
460
|
+
method: "DELETE",
|
461
|
+
url: method_url,
|
462
|
+
headers: headers,
|
463
|
+
params: params,
|
464
|
+
accept_json: true
|
465
|
+
)
|
466
|
+
response
|
467
|
+
end
|
468
|
+
#########################
|
469
|
+
# Batches
|
470
|
+
#########################
|
471
|
+
|
472
|
+
##
|
473
|
+
# @!method create_batch(function:, input_credentials_file:, input_bucket_location:, input_bucket_name:, output_credentials_file:, output_bucket_location:, output_bucket_name:, model_id: nil, input_credentials_filename: nil, output_credentials_filename: nil)
|
474
|
+
# Submit a batch-processing request.
|
475
|
+
# Run Compare and Comply methods over a collection of input documents.
|
476
|
+
# **Important:** Batch processing requires the use of the [IBM Cloud Object Storage
|
477
|
+
# service](https://console.bluemix.net/docs/services/cloud-object-storage/about-cos.html#about-ibm-cloud-object-storage).
|
478
|
+
# The use of IBM Cloud Object Storage with Compare and Comply is discussed at [Using
|
479
|
+
# batch
|
480
|
+
# processing](https://console.bluemix.net/docs/services/compare-comply/batching.html#before-you-batch).
|
481
|
+
# @param function [String] The Compare and Comply method to run across the submitted input documents.
|
482
|
+
# @param input_credentials_file [File] A JSON file containing the input Cloud Object Storage credentials. At a minimum,
|
483
|
+
# the credentials must enable `READ` permissions on the bucket defined by the
|
484
|
+
# `input_bucket_name` parameter.
|
485
|
+
# @param input_bucket_location [String] The geographical location of the Cloud Object Storage input bucket as listed on
|
486
|
+
# the **Endpoint** tab of your Cloud Object Storage instance; for example, `us-geo`,
|
487
|
+
# `eu-geo`, or `ap-geo`.
|
488
|
+
# @param input_bucket_name [String] The name of the Cloud Object Storage input bucket.
|
489
|
+
# @param output_credentials_file [File] A JSON file that lists the Cloud Object Storage output credentials. At a minimum,
|
490
|
+
# the credentials must enable `READ` and `WRITE` permissions on the bucket defined
|
491
|
+
# by the `output_bucket_name` parameter.
|
492
|
+
# @param output_bucket_location [String] The geographical location of the Cloud Object Storage output bucket as listed on
|
493
|
+
# the **Endpoint** tab of your Cloud Object Storage instance; for example, `us-geo`,
|
494
|
+
# `eu-geo`, or `ap-geo`.
|
495
|
+
# @param output_bucket_name [String] The name of the Cloud Object Storage output bucket.
|
496
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
497
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
498
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
499
|
+
# well as to the methods' use in batch-processing requests.
|
500
|
+
# @param input_credentials_filename [String] The filename for input_credentials_file.
|
501
|
+
# @param output_credentials_filename [String] The filename for output_credentials_file.
|
502
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
503
|
+
def create_batch(function:, input_credentials_file:, input_bucket_location:, input_bucket_name:, output_credentials_file:, output_bucket_location:, output_bucket_name:, model_id: nil, input_credentials_filename: nil, output_credentials_filename: nil)
|
504
|
+
raise ArgumentError.new("function must be provided") if function.nil?
|
505
|
+
|
506
|
+
raise ArgumentError.new("input_credentials_file must be provided") if input_credentials_file.nil?
|
507
|
+
|
508
|
+
raise ArgumentError.new("input_bucket_location must be provided") if input_bucket_location.nil?
|
509
|
+
|
510
|
+
raise ArgumentError.new("input_bucket_name must be provided") if input_bucket_name.nil?
|
511
|
+
|
512
|
+
raise ArgumentError.new("output_credentials_file must be provided") if output_credentials_file.nil?
|
513
|
+
|
514
|
+
raise ArgumentError.new("output_bucket_location must be provided") if output_bucket_location.nil?
|
515
|
+
|
516
|
+
raise ArgumentError.new("output_bucket_name must be provided") if output_bucket_name.nil?
|
517
|
+
|
518
|
+
headers = {
|
519
|
+
}
|
520
|
+
|
521
|
+
params = {
|
522
|
+
"version" => @version,
|
523
|
+
"function" => function,
|
524
|
+
"model_id" => model_id
|
525
|
+
}
|
526
|
+
|
527
|
+
form_data = {}
|
528
|
+
|
529
|
+
unless input_credentials_file.instance_of?(StringIO) || input_credentials_file.instance_of?(File)
|
530
|
+
input_credentials_file = input_credentials_file.respond_to?(:to_json) ? StringIO.new(input_credentials_file.to_json) : StringIO.new(input_credentials_file)
|
531
|
+
end
|
532
|
+
input_credentials_filename = input_credentials_file.path if input_credentials_filename.nil? && input_credentials_file.respond_to?(:path)
|
533
|
+
form_data[:input_credentials_file] = HTTP::FormData::File.new(input_credentials_file, content_type: "application/json", filename: input_credentials_filename)
|
534
|
+
|
535
|
+
form_data[:input_bucket_location] = HTTP::FormData::Part.new(input_bucket_location.to_s, content_type: "text/plain")
|
536
|
+
|
537
|
+
form_data[:input_bucket_name] = HTTP::FormData::Part.new(input_bucket_name.to_s, content_type: "text/plain")
|
538
|
+
|
539
|
+
unless output_credentials_file.instance_of?(StringIO) || output_credentials_file.instance_of?(File)
|
540
|
+
output_credentials_file = output_credentials_file.respond_to?(:to_json) ? StringIO.new(output_credentials_file.to_json) : StringIO.new(output_credentials_file)
|
541
|
+
end
|
542
|
+
output_credentials_filename = output_credentials_file.path if output_credentials_filename.nil? && output_credentials_file.respond_to?(:path)
|
543
|
+
form_data[:output_credentials_file] = HTTP::FormData::File.new(output_credentials_file, content_type: "application/json", filename: output_credentials_filename)
|
544
|
+
|
545
|
+
form_data[:output_bucket_location] = HTTP::FormData::Part.new(output_bucket_location.to_s, content_type: "text/plain")
|
546
|
+
|
547
|
+
form_data[:output_bucket_name] = HTTP::FormData::Part.new(output_bucket_name.to_s, content_type: "text/plain")
|
548
|
+
|
549
|
+
method_url = "/v1/batches"
|
550
|
+
|
551
|
+
response = request(
|
552
|
+
method: "POST",
|
553
|
+
url: method_url,
|
554
|
+
headers: headers,
|
555
|
+
params: params,
|
556
|
+
form: form_data,
|
557
|
+
accept_json: true
|
558
|
+
)
|
559
|
+
response
|
560
|
+
end
|
561
|
+
|
562
|
+
##
|
563
|
+
# @!method list_batches
|
564
|
+
# Gets the list of submitted batch-processing jobs.
|
565
|
+
# Gets the list of batch-processing jobs submitted by users.
|
566
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
567
|
+
def list_batches
|
568
|
+
headers = {
|
569
|
+
}
|
570
|
+
|
571
|
+
params = {
|
572
|
+
"version" => @version
|
573
|
+
}
|
574
|
+
|
575
|
+
method_url = "/v1/batches"
|
576
|
+
|
577
|
+
response = request(
|
578
|
+
method: "GET",
|
579
|
+
url: method_url,
|
580
|
+
headers: headers,
|
581
|
+
params: params,
|
582
|
+
accept_json: true
|
583
|
+
)
|
584
|
+
response
|
585
|
+
end
|
586
|
+
|
587
|
+
##
|
588
|
+
# @!method get_batch(batch_id:)
|
589
|
+
# Gets information about a specific batch-processing request.
|
590
|
+
# Gets information about a batch-processing request with a specified ID.
|
591
|
+
# @param batch_id [String] The ID of the batch-processing request whose information you want to retrieve.
|
592
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
593
|
+
def get_batch(batch_id:)
|
594
|
+
raise ArgumentError.new("batch_id must be provided") if batch_id.nil?
|
595
|
+
|
596
|
+
headers = {
|
597
|
+
}
|
598
|
+
|
599
|
+
params = {
|
600
|
+
"version" => @version
|
601
|
+
}
|
602
|
+
|
603
|
+
method_url = "/v1/batches/%s" % [ERB::Util.url_encode(batch_id)]
|
604
|
+
|
605
|
+
response = request(
|
606
|
+
method: "GET",
|
607
|
+
url: method_url,
|
608
|
+
headers: headers,
|
609
|
+
params: params,
|
610
|
+
accept_json: true
|
611
|
+
)
|
612
|
+
response
|
613
|
+
end
|
614
|
+
|
615
|
+
##
|
616
|
+
# @!method update_batch(batch_id:, action:, model_id: nil)
|
617
|
+
# Updates a pending or active batch-processing request.
|
618
|
+
# Updates a pending or active batch-processing request. You can rescan the input
|
619
|
+
# bucket to check for new documents or cancel a request.
|
620
|
+
# @param batch_id [String] The ID of the batch-processing request you want to update.
|
621
|
+
# @param action [String] The action you want to perform on the specified batch-processing request.
|
622
|
+
# @param model_id [String] The analysis model to be used by the service. For the `/v1/element_classification`
|
623
|
+
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables`
|
624
|
+
# method, the default is `tables`. These defaults apply to the standalone methods as
|
625
|
+
# well as to the methods' use in batch-processing requests.
|
626
|
+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
627
|
+
def update_batch(batch_id:, action:, model_id: nil)
|
628
|
+
raise ArgumentError.new("batch_id must be provided") if batch_id.nil?
|
629
|
+
|
630
|
+
raise ArgumentError.new("action must be provided") if action.nil?
|
631
|
+
|
632
|
+
headers = {
|
633
|
+
}
|
634
|
+
|
635
|
+
params = {
|
636
|
+
"version" => @version,
|
637
|
+
"action" => action,
|
638
|
+
"model_id" => model_id
|
639
|
+
}
|
640
|
+
|
641
|
+
method_url = "/v1/batches/%s" % [ERB::Util.url_encode(batch_id)]
|
642
|
+
|
643
|
+
response = request(
|
644
|
+
method: "PUT",
|
645
|
+
url: method_url,
|
646
|
+
headers: headers,
|
647
|
+
params: params,
|
648
|
+
accept_json: true
|
649
|
+
)
|
650
|
+
response
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|