ibm_watson 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -39
  3. data/lib/ibm_watson/assistant_v1.rb +5 -4
  4. data/lib/ibm_watson/assistant_v2.rb +3 -3
  5. data/lib/ibm_watson/discovery_v1.rb +7 -14
  6. data/lib/ibm_watson/discovery_v2.rb +109 -108
  7. data/lib/ibm_watson/language_translator_v3.rb +2 -2
  8. data/lib/ibm_watson/natural_language_understanding_v1.rb +12 -14
  9. data/lib/ibm_watson/speech_to_text_v1.rb +581 -402
  10. data/lib/ibm_watson/text_to_speech_v1.rb +87 -166
  11. data/lib/ibm_watson/version.rb +1 -1
  12. data/lib/ibm_watson.rb +0 -6
  13. metadata +2 -20
  14. data/lib/ibm_watson/compare_comply_v1.rb +0 -683
  15. data/lib/ibm_watson/natural_language_classifier_v1.rb +0 -258
  16. data/lib/ibm_watson/personality_insights_v3.rb +0 -223
  17. data/lib/ibm_watson/tone_analyzer_v3.rb +0 -230
  18. data/lib/ibm_watson/visual_recognition_v3.rb +0 -517
  19. data/lib/ibm_watson/visual_recognition_v4.rb +0 -930
  20. data/test/integration/test_compare_comply_v1.rb +0 -105
  21. data/test/integration/test_natural_language_classifier_v1.rb +0 -80
  22. data/test/integration/test_personality_insights_v3.rb +0 -81
  23. data/test/integration/test_tone_analyzer_v3.rb +0 -66
  24. data/test/integration/test_visual_recognition_v3.rb +0 -68
  25. data/test/integration/test_visual_recognition_v4.rb +0 -87
  26. data/test/unit/test_compare_comply_v1.rb +0 -232
  27. data/test/unit/test_natural_language_classifier_v1.rb +0 -191
  28. data/test/unit/test_personality_insights_v3.rb +0 -192
  29. data/test/unit/test_tone_analyzer_v3.rb +0 -217
  30. data/test/unit/test_visual_recognition_v3.rb +0 -300
  31. data/test/unit/test_visual_recognition_v4.rb +0 -422
@@ -1,422 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("webmock/minitest")
6
-
7
- WebMock.disable_net_connect!(allow_localhost: true)
8
-
9
- # Unit tests for the Visual Recognition V3 Service
10
- class VisualRecognitionV4Test < Minitest::Test
11
- include Minitest::Hooks
12
- attr_accessor :service
13
- def before_all
14
- authenticator = IBMWatson::Authenticators::NoAuthAuthenticator.new
15
- @service = IBMWatson::VisualRecognitionV4.new(
16
- version: "2018-03-19",
17
- authenticator: authenticator
18
- )
19
- end
20
-
21
- def test_analyze
22
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
23
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/analyze?version=2018-03-19").with do |req|
24
- assert_equal(req.headers["Accept"], "application/json")
25
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
26
- assert_match(/Content-Disposition: form-data/, req.body)
27
- assert_match(/Content-Disposition: form-data; name="images_file"; filename="dog.jpg"/, req.body)
28
- end
29
- service.analyze(
30
- images_file: [
31
- {
32
- "data": file,
33
- "filename": "dog.jpg",
34
- "content_type": "image/jpeg"
35
- }
36
- ],
37
- collection_ids: ["collid"],
38
- features: ["animal"]
39
- )
40
- end
41
-
42
- def test_analyze_url
43
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/analyze?version=2018-03-19").with do |req|
44
- assert_equal(req.headers["Accept"], "application/json")
45
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
46
- assert_match(/Content-Disposition: form-data; name="image_url"/, req.body)
47
- end
48
- service.analyze(
49
- image_url: [
50
- "www.somethingfunny.com"
51
- ],
52
- collection_ids: ["collid"],
53
- features: ["animal"]
54
- )
55
- end
56
-
57
- def test_create_collection
58
- response = {
59
- "collection_id" => "collid",
60
- "name" => "Dog Breeds",
61
- "owner" => "58b61352-678c-44d1-9f40-40edf4ea8d19",
62
- "status" => "passed",
63
- "created" => "2017-08-25T06:39:01.968Z",
64
- "classes" => [
65
- {
66
- "class" => "goldenretriever"
67
- }
68
- ]
69
- }
70
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections?version=2018-03-19")
71
- .with(
72
- headers: {
73
- "Accept" => "application/json",
74
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
75
- }
76
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
77
- service_response = service.create_collection(
78
- name: "my-collection",
79
- description: "A description of my collection"
80
- )
81
- assert_equal(response, service_response.result)
82
- end
83
-
84
- def test_list_collections
85
- response = {
86
- "collections" => []
87
- }
88
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections?version=2018-03-19")
89
- .with(
90
- headers: {
91
- "Accept" => "application/json",
92
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
93
- }
94
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
95
- service_response = service.list_collections
96
- assert_equal(response, service_response.result)
97
- end
98
-
99
- def test_get_collection
100
- response = {
101
- "collection_id" => "collid",
102
- "name" => "Dog Breeds",
103
- "owner" => "58b61352-678c-44d1-9f40-40edf4ea8d19",
104
- "status" => "failed",
105
- "created" => "2017-08-25T06:39:01.968Z",
106
- "classes" => [
107
- {
108
- "class" => "goldenretriever"
109
- }
110
- ]
111
- }
112
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
113
- .with(
114
- headers: {
115
- "Accept" => "application/json",
116
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
117
- }
118
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
119
- service_response = service.get_collection(
120
- collection_id: "collid"
121
- )
122
- assert_equal(response, service_response.result)
123
- end
124
-
125
- def test_update_collection
126
- response = {
127
- "collection_id" => "collid",
128
- "name" => "Dog Breeds",
129
- "owner" => "58b61352-678c-44d1-9f40-40edf4ea8d19",
130
- "status" => "failed",
131
- "created" => "2017-08-25T06:39:01.968Z",
132
- "classes" => [
133
- {
134
- "class" => "goldenretriever"
135
- }
136
- ]
137
- }
138
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
139
- .with(
140
- headers: {
141
- "Accept" => "application/json",
142
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
143
- }
144
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
145
- service_response = service.update_collection(
146
- collection_id: "collid"
147
- )
148
- assert_equal(response, service_response.result)
149
- end
150
-
151
- def test_delete_collection
152
- response = {}
153
- stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
154
- .with(
155
- headers: {
156
- "Accept" => "application/json",
157
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
158
- }
159
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
160
- service_response = service.delete_collection(
161
- collection_id: "collid"
162
- )
163
- assert_nil(service_response)
164
- end
165
-
166
- def test_add_images
167
- response = {
168
- "collection_id" => "collid"
169
- }
170
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
171
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images?version=2018-03-19")
172
- .with(
173
- headers: {
174
- "Accept" => "application/json",
175
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
176
- }
177
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
178
- service_response = service.add_images(
179
- collection_id: "collid",
180
- images_file: [
181
- {
182
- "data": file,
183
- "filename": "dog.jpg",
184
- "content_type": "image/jpeg"
185
- }
186
- ]
187
- )
188
- assert_equal(response, service_response.result)
189
- end
190
-
191
- def test_list_images
192
- response = {
193
- "collections" => []
194
- }
195
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images?version=2018-03-19")
196
- .with(
197
- headers: {
198
- "Accept" => "application/json",
199
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
200
- }
201
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
202
- service_response = service.list_images(
203
- collection_id: "collid"
204
- )
205
- assert_equal(response, service_response.result)
206
- end
207
-
208
- def test_get_image_details
209
- response = {
210
- "collection_id" => "collid"
211
- }
212
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid?version=2018-03-19")
213
- .with(
214
- headers: {
215
- "Accept" => "application/json",
216
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
217
- }
218
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
219
- service_response = service.get_image_details(
220
- collection_id: "collid",
221
- image_id: "imageid"
222
- )
223
- assert_equal(response, service_response.result)
224
- end
225
-
226
- def test_delete_image
227
- response = {}
228
- stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid?version=2018-03-19")
229
- .with(
230
- headers: {
231
- "Accept" => "application/json",
232
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
233
- }
234
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
235
- service_response = service.delete_image(
236
- collection_id: "collid",
237
- image_id: "imageid"
238
- )
239
- assert_nil(service_response)
240
- end
241
-
242
- def test_get_jpeg_image
243
- response = {
244
- "collection_id" => "collid"
245
- }
246
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid/jpeg?version=2018-03-19")
247
- .with(
248
- headers: {
249
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
250
- }
251
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
252
- service_response = service.get_jpeg_image(
253
- collection_id: "collid",
254
- image_id: "imageid"
255
- )
256
- assert_equal(response, service_response.result)
257
- end
258
-
259
- def test_train
260
- response = {
261
- "collection_id" => "collid"
262
- }
263
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/train?version=2018-03-19")
264
- .with(
265
- headers: {
266
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
267
- }
268
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
269
- service_response = service.train(
270
- collection_id: "collid"
271
- )
272
- assert_equal(response, service_response.result)
273
- end
274
-
275
- def test_add_image_training_data
276
- response = {
277
- "collection_id" => "collid"
278
- }
279
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid/training_data?version=2018-03-19")
280
- .with(
281
- headers: {
282
- "Accept" => "application/json",
283
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
284
- }
285
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
286
- service_response = service.add_image_training_data(
287
- collection_id: "collid",
288
- image_id: "imageid",
289
- objects: [
290
- {
291
- object: "2018-Fit",
292
- location: {
293
- top: 5,
294
- left: 13,
295
- width: 760,
296
- height: 419
297
- }
298
- }
299
- ]
300
- )
301
- assert_equal(response, service_response.result)
302
- end
303
-
304
- def test_delete_user_data
305
- response = {}
306
- stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/user_data?version=2018-03-19&customer_id=customer")
307
- .with(
308
- headers: {
309
- "Accept" => "application/json",
310
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
311
- }
312
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
313
- service_response = service.delete_user_data(
314
- customer_id: "customer"
315
- )
316
- assert_nil(service_response)
317
- end
318
-
319
- def test_get_training_usage
320
- response = {
321
- "usage" => "usage"
322
- }
323
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/training_usage?end_time=end&start_time=start&version=2018-03-19")
324
- .with(
325
- headers: {
326
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
327
- }
328
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
329
- service_response = service.get_training_usage(
330
- start_time: "start",
331
- end_time: "end"
332
- )
333
- assert_equal(response, service_response.result)
334
- end
335
-
336
- def test_list_object_metadata
337
- response = {
338
- "objects" => []
339
- }
340
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects?version=2018-03-19")
341
- .with(
342
- headers: {
343
- "Accept" => "application/json",
344
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
345
- }
346
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
347
- service_response = service.list_object_metadata(
348
- collection_id: "collid"
349
- )
350
- assert_equal(response, service_response.result)
351
- end
352
-
353
- def test_update_object_metadata
354
- response = {
355
- "objects" => []
356
- }
357
- stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/old_object?version=2018-03-19")
358
- .with(
359
- headers: {
360
- "Accept" => "application/json",
361
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
362
- }
363
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
364
- service_response = service.update_object_metadata(
365
- collection_id: "collid",
366
- object: "old_object",
367
- new_object: "new_object"
368
- )
369
- assert_equal(response, service_response.result)
370
- end
371
-
372
- def test_get_object_metadata
373
- response = {
374
- "objects" => []
375
- }
376
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/object?version=2018-03-19")
377
- .with(
378
- headers: {
379
- "Accept" => "application/json",
380
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
381
- }
382
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
383
- service_response = service.get_object_metadata(
384
- collection_id: "collid",
385
- object: "object"
386
- )
387
- assert_equal(response, service_response.result)
388
- end
389
-
390
- def test_delete_object
391
- stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/object?version=2018-03-19")
392
- .with(
393
- headers: {
394
- "Accept" => "application/json",
395
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
396
- }
397
- ).to_return(status: 200, body: {}.to_json, headers: { "Content-Type" => "application/json" })
398
- service_response = service.delete_object(
399
- collection_id: "collid",
400
- object: "object"
401
- )
402
- assert_nil(service_response)
403
- end
404
-
405
- def test_get_model_file
406
- response = {
407
- "binary" => []
408
- }
409
- stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/model?feature=objects&model_format=rscnn_ready&version=2018-03-19")
410
- .with(
411
- headers: {
412
- "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
413
- }
414
- ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
415
- service_response = service.get_model_file(
416
- collection_id: "collid",
417
- feature: "objects",
418
- model_format: "rscnn_ready"
419
- )
420
- assert_equal(response, service_response.result)
421
- end
422
- end