ibm_watson 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/ibm_watson/version.rb
CHANGED
@@ -124,33 +124,40 @@ module IBMWatson
|
|
124
124
|
headers = {
|
125
125
|
"Accept-Language" => accept_language
|
126
126
|
}
|
127
|
+
|
127
128
|
params = {
|
128
129
|
"version" => @version
|
129
130
|
}
|
131
|
+
|
132
|
+
form_data = {}
|
133
|
+
|
130
134
|
unless images_file.nil?
|
131
|
-
mime_type = images_file_content_type.nil? ? "application/octet-stream" : images_file_content_type
|
132
135
|
unless images_file.instance_of?(StringIO) || images_file.instance_of?(File)
|
133
136
|
images_file = images_file.respond_to?(:to_json) ? StringIO.new(images_file.to_json) : StringIO.new(images_file)
|
134
137
|
end
|
135
|
-
if images_filename
|
136
|
-
|
137
|
-
else
|
138
|
-
images_file = images_file.instance_of?(StringIO) ? HTTP::FormData::File.new(images_file, content_type: mime_type) : HTTP::FormData::File.new(images_file.path, content_type: mime_type)
|
139
|
-
end
|
138
|
+
images_filename = images_file.path if images_filename.nil? && images_file.respond_to?(:path)
|
139
|
+
form_data[:images_file] = HTTP::FormData::File.new(images_file, content_type: images_file_content_type.nil? ? "application/octet-stream" : images_file_content_type, filename: images_filename)
|
140
140
|
end
|
141
|
+
|
142
|
+
classifier_ids *= "," unless classifier_ids.nil?
|
143
|
+
owners *= "," unless owners.nil?
|
144
|
+
|
145
|
+
form_data[:url] = HTTP::FormData::Part.new(url.to_s, content_type: "text/plain") unless url.nil?
|
146
|
+
|
147
|
+
form_data[:threshold] = HTTP::FormData::Part.new(threshold.to_s, content_type: "application/json") unless threshold.nil?
|
148
|
+
|
149
|
+
form_data[:owners] = HTTP::FormData::Part.new(owners, content_type: "application/json") unless owners.nil?
|
150
|
+
|
151
|
+
form_data[:classifier_ids] = HTTP::FormData::Part.new(classifier_ids, content_type: "application/json") unless classifier_ids.nil?
|
152
|
+
|
141
153
|
method_url = "/v3/classify"
|
154
|
+
|
142
155
|
response = request(
|
143
156
|
method: "POST",
|
144
157
|
url: method_url,
|
145
158
|
headers: headers,
|
146
159
|
params: params,
|
147
|
-
form:
|
148
|
-
images_file: images_file,
|
149
|
-
url: url,
|
150
|
-
threshold: threshold,
|
151
|
-
owners: owners,
|
152
|
-
classifier_ids: classifier_ids
|
153
|
-
},
|
160
|
+
form: form_data,
|
154
161
|
accept_json: true
|
155
162
|
)
|
156
163
|
response
|
@@ -193,30 +200,31 @@ module IBMWatson
|
|
193
200
|
def detect_faces(images_file: nil, url: nil, images_file_content_type: nil, images_filename: nil)
|
194
201
|
headers = {
|
195
202
|
}
|
203
|
+
|
196
204
|
params = {
|
197
205
|
"version" => @version
|
198
206
|
}
|
207
|
+
|
208
|
+
form_data = {}
|
209
|
+
|
199
210
|
unless images_file.nil?
|
200
|
-
mime_type = images_file_content_type.nil? ? "application/octet-stream" : images_file_content_type
|
201
211
|
unless images_file.instance_of?(StringIO) || images_file.instance_of?(File)
|
202
212
|
images_file = images_file.respond_to?(:to_json) ? StringIO.new(images_file.to_json) : StringIO.new(images_file)
|
203
213
|
end
|
204
|
-
if images_filename
|
205
|
-
|
206
|
-
else
|
207
|
-
images_file = images_file.instance_of?(StringIO) ? HTTP::FormData::File.new(images_file, content_type: mime_type) : HTTP::FormData::File.new(images_file.path, content_type: mime_type)
|
208
|
-
end
|
214
|
+
images_filename = images_file.path if images_filename.nil? && images_file.respond_to?(:path)
|
215
|
+
form_data[:images_file] = HTTP::FormData::File.new(images_file, content_type: images_file_content_type.nil? ? "application/octet-stream" : images_file_content_type, filename: images_filename)
|
209
216
|
end
|
217
|
+
|
218
|
+
form_data[:url] = HTTP::FormData::Part.new(url.to_s, content_type: "text/plain") unless url.nil?
|
219
|
+
|
210
220
|
method_url = "/v3/detect_faces"
|
221
|
+
|
211
222
|
response = request(
|
212
223
|
method: "POST",
|
213
224
|
url: method_url,
|
214
225
|
headers: headers,
|
215
226
|
params: params,
|
216
|
-
form:
|
217
|
-
images_file: images_file,
|
218
|
-
url: url
|
219
|
-
},
|
227
|
+
form: form_data,
|
220
228
|
accept_json: true
|
221
229
|
)
|
222
230
|
response
|
@@ -226,7 +234,7 @@ module IBMWatson
|
|
226
234
|
#########################
|
227
235
|
|
228
236
|
##
|
229
|
-
# @!method create_classifier(name:,
|
237
|
+
# @!method create_classifier(name:, positive_examples:, negative_examples: nil, positive_examples_filename: nil, negative_examples_filename: nil)
|
230
238
|
# Create a classifier.
|
231
239
|
# Train a new multi-faceted classifier on the uploaded image data. Create your
|
232
240
|
# custom classifier with positive or negative examples. Include at least two sets of
|
@@ -237,8 +245,7 @@ module IBMWatson
|
|
237
245
|
# file names, and classifier and class names). The service assumes UTF-8 encoding if
|
238
246
|
# it encounters non-ASCII characters.
|
239
247
|
# @param name [String] The name of the new classifier. Encode special characters in UTF-8.
|
240
|
-
# @param
|
241
|
-
# @option args classname_positive_examples [File] A .zip file of images that depict the visual subject of a class in the new
|
248
|
+
# @param positive_examples [Hash] A .zip file of images that depict the visual subject of a class in the new
|
242
249
|
# classifier. You can include more than one positive example file in a call.
|
243
250
|
#
|
244
251
|
# Specify the parameter name by appending `_positive_examples` to the class name.
|
@@ -254,53 +261,54 @@ module IBMWatson
|
|
254
261
|
# of the new classifier. Must contain a minimum of 10 images.
|
255
262
|
#
|
256
263
|
# Encode special characters in the file name in UTF-8.
|
257
|
-
# @
|
258
|
-
# @
|
264
|
+
# @param positive_examples_filename [Hash] The filename for positive_examples.
|
265
|
+
# @param negative_examples_filename [String] The filename for negative_examples.
|
259
266
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
260
|
-
def create_classifier(name:,
|
261
|
-
raise ArgumentError("name must be provided") if name.nil?
|
267
|
+
def create_classifier(name:, positive_examples:, negative_examples: nil, positive_examples_filename: nil, negative_examples_filename: nil)
|
268
|
+
raise ArgumentError.new("name must be provided") if name.nil?
|
262
269
|
|
263
|
-
raise ArgumentError("
|
270
|
+
raise ArgumentError.new("positive_examples must be a hash") unless positive_examples.is_a?(Hash)
|
271
|
+
raise ArgumentError.new("positive_examples must have at least one hash entry") if positive_examples.empty?
|
272
|
+
|
273
|
+
raise ArgumentError.new("positive_examples_filename must be a hash") unless positive_examples_filename.nil? || positive_examples_filename.is_a?(Hash)
|
264
274
|
|
265
|
-
positive_keys = args.keys
|
266
|
-
positive_keys.keep_if { |key| key.to_s.end_with?("_positive_examples") }
|
267
275
|
headers = {
|
268
276
|
}
|
277
|
+
|
269
278
|
params = {
|
270
279
|
"version" => @version
|
271
280
|
}
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
+
|
282
|
+
form_data = {}
|
283
|
+
|
284
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain")
|
285
|
+
|
286
|
+
positive_examples&.each do |key, value|
|
287
|
+
part_name = "%s_positive_examples" % key.to_s
|
288
|
+
unless value.instance_of?(StringIO) || value.instance_of?(File)
|
289
|
+
value = value.respond_to?(:to_json) ? StringIO.new(value.to_json) : StringIO.new(value)
|
281
290
|
end
|
291
|
+
filename = positive_examples_filename[key] if !positive_examples_filename.nil? && positive_examples_filename.key?(key)
|
292
|
+
filename = value.path if filename.nil? && value.respond_to?(:path)
|
293
|
+
form_data[part_name.to_sym] = HTTP::FormData::File.new(value, content_type: "application/octet-stream", filename: filename)
|
282
294
|
end
|
283
|
-
|
284
|
-
|
285
|
-
unless
|
286
|
-
|
287
|
-
end
|
288
|
-
if args[:negative_examples_filename]
|
289
|
-
args[:negative_examples] = args[:negative_examples].instance_of?(StringIO) ? HTTP::FormData::File.new(args[:negative_examples], content_type: mime_type, filename: args[:negative_examples_filename]) : HTTP::FormData::File.new(args[:negative_examples].path, content_type: mime_type, filename: args[:negative_examples_filename])
|
290
|
-
else
|
291
|
-
args[:negative_examples] = args[:negative_examples].instance_of?(StringIO) ? HTTP::FormData::File.new(args[:negative_examples], content_type: mime_type) : HTTP::FormData::File.new(args[:negative_examples].path, content_type: mime_type)
|
295
|
+
|
296
|
+
unless negative_examples.nil?
|
297
|
+
unless negative_examples.instance_of?(StringIO) || negative_examples.instance_of?(File)
|
298
|
+
negative_examples = negative_examples.respond_to?(:to_json) ? StringIO.new(negative_examples.to_json) : StringIO.new(negative_examples)
|
292
299
|
end
|
300
|
+
negative_examples_filename = negative_examples.path if negative_examples_filename.nil? && negative_examples.respond_to?(:path)
|
301
|
+
form_data[:negative_examples] = HTTP::FormData::File.new(negative_examples, content_type: "application/octet-stream", filename: negative_examples_filename)
|
293
302
|
end
|
294
|
-
|
295
|
-
positive_keys.each { |k| form_hash[k] = args[k] }
|
296
|
-
form_hash[:negative_examples] = args[:negative_examples] unless args[:negative_examples].nil?
|
303
|
+
|
297
304
|
method_url = "/v3/classifiers"
|
305
|
+
|
298
306
|
response = request(
|
299
307
|
method: "POST",
|
300
308
|
url: method_url,
|
301
309
|
headers: headers,
|
302
310
|
params: params,
|
303
|
-
form:
|
311
|
+
form: form_data,
|
304
312
|
accept_json: true
|
305
313
|
)
|
306
314
|
response
|
@@ -315,11 +323,14 @@ module IBMWatson
|
|
315
323
|
def list_classifiers(verbose: nil)
|
316
324
|
headers = {
|
317
325
|
}
|
326
|
+
|
318
327
|
params = {
|
319
328
|
"version" => @version,
|
320
329
|
"verbose" => verbose
|
321
330
|
}
|
331
|
+
|
322
332
|
method_url = "/v3/classifiers"
|
333
|
+
|
323
334
|
response = request(
|
324
335
|
method: "GET",
|
325
336
|
url: method_url,
|
@@ -337,14 +348,17 @@ module IBMWatson
|
|
337
348
|
# @param classifier_id [String] The ID of the classifier.
|
338
349
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
339
350
|
def get_classifier(classifier_id:)
|
340
|
-
raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
|
351
|
+
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
341
352
|
|
342
353
|
headers = {
|
343
354
|
}
|
355
|
+
|
344
356
|
params = {
|
345
357
|
"version" => @version
|
346
358
|
}
|
359
|
+
|
347
360
|
method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
|
361
|
+
|
348
362
|
response = request(
|
349
363
|
method: "GET",
|
350
364
|
url: method_url,
|
@@ -356,7 +370,7 @@ module IBMWatson
|
|
356
370
|
end
|
357
371
|
|
358
372
|
##
|
359
|
-
# @!method update_classifier(classifier_id:,
|
373
|
+
# @!method update_classifier(classifier_id:, positive_examples: nil, negative_examples: nil, positive_examples_filename: nil, negative_examples_filename: nil)
|
360
374
|
# Update a classifier.
|
361
375
|
# Update a custom classifier by adding new positive or negative classes (examples)
|
362
376
|
# or by adding new images to existing classes. You must supply at least one set of
|
@@ -372,7 +386,7 @@ module IBMWatson
|
|
372
386
|
# previous requests. The retrained property shows the last time the classifier
|
373
387
|
# retraining finished.
|
374
388
|
# @param classifier_id [String] The ID of the classifier.
|
375
|
-
# @
|
389
|
+
# @param positive_examples [Hash] A .zip file of images that depict the visual subject of a class in the classifier.
|
376
390
|
# The positive examples create or update classes in the classifier. You can include
|
377
391
|
# more than one positive example file in a call.
|
378
392
|
#
|
@@ -385,55 +399,55 @@ module IBMWatson
|
|
385
399
|
# MB per .zip file.
|
386
400
|
#
|
387
401
|
# Encode special characters in the file name in UTF-8.
|
388
|
-
# @
|
402
|
+
# @param negative_examples [File] A .zip file of images that do not depict the visual subject of any of the classes
|
389
403
|
# of the new classifier. Must contain a minimum of 10 images.
|
390
404
|
#
|
391
405
|
# Encode special characters in the file name in UTF-8.
|
392
|
-
# @
|
393
|
-
# @
|
406
|
+
# @param positive_examples_filename [Hash] The filename for positive_examples.
|
407
|
+
# @param negative_examples_filename [String] The filename for negative_examples.
|
394
408
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
395
|
-
def update_classifier(classifier_id:,
|
396
|
-
raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
|
409
|
+
def update_classifier(classifier_id:, positive_examples: nil, negative_examples: nil, positive_examples_filename: nil, negative_examples_filename: nil)
|
410
|
+
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
411
|
+
|
412
|
+
raise ArgumentError.new("positive_examples must be a hash") unless positive_examples.nil? || positive_examples.is_a?(Hash)
|
413
|
+
|
414
|
+
raise ArgumentError.new("positive_examples_filename must be a hash") unless positive_examples_filename.nil? || positive_examples_filename.is_a?(Hash)
|
397
415
|
|
398
416
|
headers = {
|
399
417
|
}
|
418
|
+
|
400
419
|
params = {
|
401
420
|
"version" => @version
|
402
421
|
}
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
if !args[(k.to_s + "_filename").to_sym].nil?
|
411
|
-
args[k] = args[k].instance_of?(StringIO) ? HTTP::FormData::File.new(args[k], content_type: mime_type, filename: args[(k.to_s + "_filename").to_sym]) : HTTP::FormData::File.new(args[k].path, content_type: mime_type, filename: args[(k.to_s + "_filename").to_sym])
|
412
|
-
else
|
413
|
-
args[k] = args[k].instance_of?(StringIO) ? HTTP::FormData::File.new(args[k], content_type: mime_type) : HTTP::FormData::File.new(args[k].path, content_type: mime_type)
|
422
|
+
|
423
|
+
form_data = {}
|
424
|
+
|
425
|
+
positive_examples&.each do |key, value|
|
426
|
+
part_name = "%s_positive_examples" % key.to_s
|
427
|
+
unless value.instance_of?(StringIO) || value.instance_of?(File)
|
428
|
+
value = value.respond_to?(:to_json) ? StringIO.new(value.to_json) : StringIO.new(value)
|
414
429
|
end
|
430
|
+
filename = positive_examples_filename[key] if !positive_examples_filename.nil? && positive_examples_filename.key?(key)
|
431
|
+
filename = value.path if filename.nil? && value.respond_to?(:path)
|
432
|
+
form_data[part_name.to_sym] = HTTP::FormData::File.new(value, content_type: "application/octet-stream", filename: filename)
|
415
433
|
end
|
416
|
-
|
417
|
-
|
418
|
-
unless
|
419
|
-
|
420
|
-
end
|
421
|
-
if args[:negative_examples_filename]
|
422
|
-
args[:negative_examples] = args[:negative_examples].instance_of?(StringIO) ? HTTP::FormData::File.new(args[:negative_examples], content_type: mime_type, filename: args[:negative_examples_filename]) : HTTP::FormData::File.new(args[:negative_examples].path, content_type: mime_type, filename: args[:negative_examples_filename])
|
423
|
-
else
|
424
|
-
args[:negative_examples] = args[:negative_examples].instance_of?(StringIO) ? HTTP::FormData::File.new(args[:negative_examples], content_type: mime_type) : HTTP::FormData::File.new(args[:negative_examples].path, content_type: mime_type)
|
434
|
+
|
435
|
+
unless negative_examples.nil?
|
436
|
+
unless negative_examples.instance_of?(StringIO) || negative_examples.instance_of?(File)
|
437
|
+
negative_examples = negative_examples.respond_to?(:to_json) ? StringIO.new(negative_examples.to_json) : StringIO.new(negative_examples)
|
425
438
|
end
|
439
|
+
negative_examples_filename = negative_examples.path if negative_examples_filename.nil? && negative_examples.respond_to?(:path)
|
440
|
+
form_data[:negative_examples] = HTTP::FormData::File.new(negative_examples, content_type: "application/octet-stream", filename: negative_examples_filename)
|
426
441
|
end
|
427
|
-
|
428
|
-
positive_keys.each { |k| form_hash[k] = args[k] }
|
429
|
-
form_hash[:negative_examples] = args[:negative_examples] unless args[:negative_examples].nil?
|
442
|
+
|
430
443
|
method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
|
444
|
+
|
431
445
|
response = request(
|
432
446
|
method: "POST",
|
433
447
|
url: method_url,
|
434
448
|
headers: headers,
|
435
449
|
params: params,
|
436
|
-
form:
|
450
|
+
form: form_data,
|
437
451
|
accept_json: true
|
438
452
|
)
|
439
453
|
response
|
@@ -445,14 +459,17 @@ module IBMWatson
|
|
445
459
|
# @param classifier_id [String] The ID of the classifier.
|
446
460
|
# @return [nil]
|
447
461
|
def delete_classifier(classifier_id:)
|
448
|
-
raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
|
462
|
+
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
449
463
|
|
450
464
|
headers = {
|
451
465
|
}
|
466
|
+
|
452
467
|
params = {
|
453
468
|
"version" => @version
|
454
469
|
}
|
470
|
+
|
455
471
|
method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
|
472
|
+
|
456
473
|
request(
|
457
474
|
method: "DELETE",
|
458
475
|
url: method_url,
|
@@ -474,14 +491,17 @@ module IBMWatson
|
|
474
491
|
# @param classifier_id [String] The ID of the classifier.
|
475
492
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
476
493
|
def get_core_ml_model(classifier_id:)
|
477
|
-
raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
|
494
|
+
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
478
495
|
|
479
496
|
headers = {
|
480
497
|
}
|
498
|
+
|
481
499
|
params = {
|
482
500
|
"version" => @version
|
483
501
|
}
|
502
|
+
|
484
503
|
method_url = "/v3/classifiers/%s/core_ml_model" % [ERB::Util.url_encode(classifier_id)]
|
504
|
+
|
485
505
|
response = request(
|
486
506
|
method: "GET",
|
487
507
|
url: method_url,
|
@@ -508,15 +528,18 @@ module IBMWatson
|
|
508
528
|
# @param customer_id [String] The customer ID for which all data is to be deleted.
|
509
529
|
# @return [nil]
|
510
530
|
def delete_user_data(customer_id:)
|
511
|
-
raise ArgumentError("customer_id must be provided") if customer_id.nil?
|
531
|
+
raise ArgumentError.new("customer_id must be provided") if customer_id.nil?
|
512
532
|
|
513
533
|
headers = {
|
514
534
|
}
|
535
|
+
|
515
536
|
params = {
|
516
537
|
"version" => @version,
|
517
538
|
"customer_id" => customer_id
|
518
539
|
}
|
540
|
+
|
519
541
|
method_url = "/v3/user_data"
|
542
|
+
|
520
543
|
request(
|
521
544
|
method: "DELETE",
|
522
545
|
url: method_url,
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative("./../test_helper.rb")
|
4
|
+
require("minitest/hooks/test")
|
5
|
+
|
6
|
+
if !ENV["COMPARE_COMPLY_APIKEY"].nil?
|
7
|
+
# Integration tests for the Discovery V1 Service
|
8
|
+
class CompareComplyV1Test < Minitest::Test
|
9
|
+
include Minitest::Hooks
|
10
|
+
attr_accessor :service, :environment_id, :collection_id
|
11
|
+
|
12
|
+
def before_all
|
13
|
+
@service = IBMWatson::CompareComplyV1.new(
|
14
|
+
iam_apikey: ENV["COMPARE_COMPLY_APIKEY"],
|
15
|
+
version: "2018-10-15"
|
16
|
+
)
|
17
|
+
@service.add_default_headers(
|
18
|
+
headers: {
|
19
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
20
|
+
"X-Watson-Test" => "1"
|
21
|
+
}
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_convert_to_html
|
26
|
+
File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
|
27
|
+
response = @service.convert_to_html(
|
28
|
+
file: file_info
|
29
|
+
).result
|
30
|
+
refute(response.nil?)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_classiffy_elements
|
35
|
+
File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
|
36
|
+
response = @service.classify_elements(
|
37
|
+
file: file_info
|
38
|
+
).result
|
39
|
+
refute(response.nil?)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_extract_tables
|
44
|
+
File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
|
45
|
+
response = @service.extract_tables(
|
46
|
+
file: file_info
|
47
|
+
).result
|
48
|
+
refute(response.nil?)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_compare_documents
|
53
|
+
file_1 = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
54
|
+
file_2 = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
55
|
+
response = @service.compare_documents(
|
56
|
+
file_1: file_1,
|
57
|
+
file_2: file_2
|
58
|
+
).result
|
59
|
+
refute(response.nil?)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_list_feedback
|
63
|
+
response = @service.list_feedback.result
|
64
|
+
refute(response.nil?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_feedback
|
68
|
+
@service_dup = IBMWatson::CompareComplyV1.new(
|
69
|
+
iam_apikey: ENV["COMPARE_COMPLY_APIKEY"],
|
70
|
+
version: "2018-10-15"
|
71
|
+
)
|
72
|
+
@service_dup.add_default_headers(
|
73
|
+
headers: {
|
74
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
75
|
+
"X-Watson-Test" => "1",
|
76
|
+
"x-watson-metadata" => "customer_id=sdk-test-customer-id"
|
77
|
+
}
|
78
|
+
)
|
79
|
+
response = @service_dup.get_feedback(
|
80
|
+
feedback_id: ENV["COMPARE_COMPLY_FEEDBACK_ID"]
|
81
|
+
).result
|
82
|
+
refute(response.nil?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_create_batch
|
86
|
+
skip "Skip to allow for concurrent travis jobs"
|
87
|
+
input_file = File.open(Dir.getwd + "/resources/cnc_input_credentials_file.json")
|
88
|
+
output_file = File.open(Dir.getwd + "/resources/cnc_output_credentials_file.json")
|
89
|
+
response = @service.create_batch(
|
90
|
+
function: "tables",
|
91
|
+
input_credentials_file: input_file,
|
92
|
+
input_bucket_location: "us-south",
|
93
|
+
input_bucket_name: "compare-comply-integration-test-bucket-input",
|
94
|
+
output_credentials_file: output_file,
|
95
|
+
output_bucket_location: "us-south",
|
96
|
+
output_bucket_name: "compare-comply-integration-test-bucket-output"
|
97
|
+
).result
|
98
|
+
refute(response.nil?)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_list_batches
|
102
|
+
response = @service.list_batches.result
|
103
|
+
refute(response.nil?)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
else
|
107
|
+
class CompareComplyV1Test < Minitest::Test
|
108
|
+
def test_missing_credentials_skip_integration
|
109
|
+
skip "Skip discovery integration tests because credentials have not been provided"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|