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,930 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # (C) Copyright IBM Corp. 2019, 2020.
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 OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
18
- #
19
- # IBM Watson™ Visual Recognition is discontinued. Existing instances are supported
20
- # until 1 December 2021, but as of 7 January 2021, you can't create instances. Any
21
- # instance that is provisioned on 1 December 2021 will be deleted.
22
- # {: deprecated}
23
- #
24
- # Provide images to the IBM Watson Visual Recognition service for analysis. The service
25
- # detects objects based on a set of images with training data.
26
-
27
- require "concurrent"
28
- require "erb"
29
- require "json"
30
- require "ibm_cloud_sdk_core"
31
- require_relative "./common.rb"
32
-
33
- module IBMWatson
34
- ##
35
- # The Visual Recognition V4 service.
36
- class VisualRecognitionV4 < IBMCloudSdkCore::BaseService
37
- include Concurrent::Async
38
- DEFAULT_SERVICE_NAME = "visual_recognition"
39
- DEFAULT_SERVICE_URL = "https://api.us-south.visual-recognition.watson.cloud.ibm.com"
40
- attr_accessor :version
41
- ##
42
- # @!method initialize(args)
43
- # Construct a new client for the Visual Recognition service.
44
- #
45
- # @param args [Hash] The args to initialize with
46
- # @option args version [String] Release date of the API version you want to use. Specify dates in YYYY-MM-DD
47
- # format. The current version is `2019-02-11`.
48
- # @option args service_url [String] The base service URL to use when contacting the service.
49
- # The base service_url may differ between IBM Cloud regions.
50
- # @option args authenticator [Object] The Authenticator instance to be configured for this service.
51
- # @option args service_name [String] The name of the service to configure. Will be used as the key to load
52
- # any external configuration, if applicable.
53
- def initialize(args = {})
54
- warn "On 1 December 2021, Visual Recognition will no longer be available. For more information, see https://github.com/watson-developer-cloud/ruby-sdk/tree/master#visual-recognition-deprecation."
55
- @__async_initialized__ = false
56
- defaults = {}
57
- defaults[:service_url] = DEFAULT_SERVICE_URL
58
- defaults[:service_name] = DEFAULT_SERVICE_NAME
59
- defaults[:authenticator] = nil
60
- defaults[:version] = nil
61
- user_service_url = args[:service_url] unless args[:service_url].nil?
62
- args = defaults.merge(args)
63
- @version = args[:version]
64
- raise ArgumentError.new("version must be provided") if @version.nil?
65
-
66
- args[:authenticator] = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: args[:service_name]) if args[:authenticator].nil?
67
- super
68
- @service_url = user_service_url unless user_service_url.nil?
69
- end
70
-
71
- #########################
72
- # Analysis
73
- #########################
74
-
75
- ##
76
- # @!method analyze(collection_ids:, features:, images_file: nil, image_url: nil, threshold: nil)
77
- # Analyze images.
78
- # Analyze images by URL, by file, or both against your own collection. Make sure
79
- # that **training_status.objects.ready** is `true` for the feature before you use a
80
- # collection to analyze images.
81
- #
82
- # Encode the image and .zip file names in UTF-8 if they contain non-ASCII
83
- # characters. The service assumes UTF-8 encoding if it encounters non-ASCII
84
- # characters.
85
- # @param collection_ids [Array[String]] The IDs of the collections to analyze.
86
- # @param features [Array[String]] The features to analyze.
87
- # @param images_file [Array[FileWithMetadata]] An array of image files (.jpg or .png) or .zip files with images.
88
- # - Include a maximum of 20 images in a request.
89
- # - Limit the .zip file to 100 MB.
90
- # - Limit each image file to 10 MB.
91
- #
92
- # You can also include an image with the **image_url** parameter.
93
- # @param image_url [Array[String]] An array of URLs of image files (.jpg or .png).
94
- # - Include a maximum of 20 images in a request.
95
- # - Limit each image file to 10 MB.
96
- # - Minimum width and height is 30 pixels, but the service tends to perform better
97
- # with images that are at least 300 x 300 pixels. Maximum is 5400 pixels for either
98
- # height or width.
99
- #
100
- # You can also include images with the **images_file** parameter.
101
- # @param threshold [Float] The minimum score a feature must have to be returned.
102
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
103
- def analyze(collection_ids:, features:, images_file: nil, image_url: nil, threshold: nil)
104
- raise ArgumentError.new("version must be provided") if version.nil?
105
-
106
- raise ArgumentError.new("collection_ids must be provided") if collection_ids.nil?
107
-
108
- raise ArgumentError.new("features must be provided") if features.nil?
109
-
110
- headers = {
111
- }
112
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "analyze")
113
- headers.merge!(sdk_headers)
114
-
115
- params = {
116
- "version" => @version
117
- }
118
-
119
- form_data = {}
120
-
121
- collection_ids *= "," unless collection_ids.nil?
122
- features *= "," unless features.nil?
123
-
124
- form_data[:collection_ids] = HTTP::FormData::Part.new(collection_ids.to_s, content_type: "text/plain")
125
-
126
- form_data[:features] = HTTP::FormData::Part.new(features.to_s, content_type: "text/plain")
127
-
128
- form_data[:images_file] = []
129
- images_file&.each do |item|
130
- unless item[:data].instance_of?(StringIO) || item[:data].instance_of?(File)
131
- item[:data] = item[:data].respond_to?(:to_json) ? StringIO.new(item[:data].to_json) : StringIO.new(item[:data])
132
- end
133
- item[:filename] = item[:data].path if item[:filename].nil? && item[:data].respond_to?(:path)
134
- form_data[:images_file].push(HTTP::FormData::File.new(item[:data], content_type: item[:content_type], filename: item[:filename]))
135
- end
136
-
137
- form_data[:image_url] = []
138
- image_url&.each do |item|
139
- form_data[:image_url].push(HTTP::FormData::Part.new(item.to_s, content_type: "text/plain"))
140
- end
141
-
142
- form_data[:threshold] = HTTP::FormData::Part.new(threshold.to_s, content_type: "application/json") unless threshold.nil?
143
-
144
- method_url = "/v4/analyze"
145
-
146
- response = request(
147
- method: "POST",
148
- url: method_url,
149
- headers: headers,
150
- params: params,
151
- form: form_data,
152
- accept_json: true
153
- )
154
- response
155
- end
156
- #########################
157
- # Collections
158
- #########################
159
-
160
- ##
161
- # @!method create_collection(name: nil, description: nil, training_status: nil)
162
- # Create a collection.
163
- # Create a collection that can be used to store images.
164
- #
165
- # To create a collection without specifying a name and description, include an empty
166
- # JSON object in the request body.
167
- #
168
- # Encode the name and description in UTF-8 if they contain non-ASCII characters. The
169
- # service assumes UTF-8 encoding if it encounters non-ASCII characters.
170
- # @param name [String] The name of the collection. The name can contain alphanumeric, underscore, hyphen,
171
- # and dot characters. It cannot begin with the reserved prefix `sys-`.
172
- # @param description [String] The description of the collection.
173
- # @param training_status [TrainingStatus] Training status information for the collection.
174
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
175
- def create_collection(name: nil, description: nil, training_status: nil)
176
- raise ArgumentError.new("version must be provided") if version.nil?
177
-
178
- headers = {
179
- }
180
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "create_collection")
181
- headers.merge!(sdk_headers)
182
-
183
- params = {
184
- "version" => @version
185
- }
186
-
187
- data = {
188
- "name" => name,
189
- "description" => description,
190
- "training_status" => training_status
191
- }
192
-
193
- method_url = "/v4/collections"
194
-
195
- response = request(
196
- method: "POST",
197
- url: method_url,
198
- headers: headers,
199
- params: params,
200
- json: data,
201
- accept_json: true
202
- )
203
- response
204
- end
205
-
206
- ##
207
- # @!method list_collections
208
- # List collections.
209
- # Retrieves a list of collections for the service instance.
210
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
211
- def list_collections
212
- raise ArgumentError.new("version must be provided") if version.nil?
213
-
214
- headers = {
215
- }
216
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "list_collections")
217
- headers.merge!(sdk_headers)
218
-
219
- params = {
220
- "version" => @version
221
- }
222
-
223
- method_url = "/v4/collections"
224
-
225
- response = request(
226
- method: "GET",
227
- url: method_url,
228
- headers: headers,
229
- params: params,
230
- accept_json: true
231
- )
232
- response
233
- end
234
-
235
- ##
236
- # @!method get_collection(collection_id:)
237
- # Get collection details.
238
- # Get details of one collection.
239
- # @param collection_id [String] The identifier of the collection.
240
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
241
- def get_collection(collection_id:)
242
- raise ArgumentError.new("version must be provided") if version.nil?
243
-
244
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
245
-
246
- headers = {
247
- }
248
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_collection")
249
- headers.merge!(sdk_headers)
250
-
251
- params = {
252
- "version" => @version
253
- }
254
-
255
- method_url = "/v4/collections/%s" % [ERB::Util.url_encode(collection_id)]
256
-
257
- response = request(
258
- method: "GET",
259
- url: method_url,
260
- headers: headers,
261
- params: params,
262
- accept_json: true
263
- )
264
- response
265
- end
266
-
267
- ##
268
- # @!method update_collection(collection_id:, name: nil, description: nil, training_status: nil)
269
- # Update a collection.
270
- # Update the name or description of a collection.
271
- #
272
- # Encode the name and description in UTF-8 if they contain non-ASCII characters. The
273
- # service assumes UTF-8 encoding if it encounters non-ASCII characters.
274
- # @param collection_id [String] The identifier of the collection.
275
- # @param name [String] The name of the collection. The name can contain alphanumeric, underscore, hyphen,
276
- # and dot characters. It cannot begin with the reserved prefix `sys-`.
277
- # @param description [String] The description of the collection.
278
- # @param training_status [TrainingStatus] Training status information for the collection.
279
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
280
- def update_collection(collection_id:, name: nil, description: nil, training_status: nil)
281
- raise ArgumentError.new("version must be provided") if version.nil?
282
-
283
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
284
-
285
- headers = {
286
- }
287
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "update_collection")
288
- headers.merge!(sdk_headers)
289
-
290
- params = {
291
- "version" => @version
292
- }
293
-
294
- data = {
295
- "name" => name,
296
- "description" => description,
297
- "training_status" => training_status
298
- }
299
-
300
- method_url = "/v4/collections/%s" % [ERB::Util.url_encode(collection_id)]
301
-
302
- response = request(
303
- method: "POST",
304
- url: method_url,
305
- headers: headers,
306
- params: params,
307
- json: data,
308
- accept_json: true
309
- )
310
- response
311
- end
312
-
313
- ##
314
- # @!method delete_collection(collection_id:)
315
- # Delete a collection.
316
- # Delete a collection from the service instance.
317
- # @param collection_id [String] The identifier of the collection.
318
- # @return [nil]
319
- def delete_collection(collection_id:)
320
- raise ArgumentError.new("version must be provided") if version.nil?
321
-
322
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
323
-
324
- headers = {
325
- }
326
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "delete_collection")
327
- headers.merge!(sdk_headers)
328
-
329
- params = {
330
- "version" => @version
331
- }
332
-
333
- method_url = "/v4/collections/%s" % [ERB::Util.url_encode(collection_id)]
334
-
335
- request(
336
- method: "DELETE",
337
- url: method_url,
338
- headers: headers,
339
- params: params,
340
- accept_json: true
341
- )
342
- nil
343
- end
344
-
345
- ##
346
- # @!method get_model_file(collection_id:, feature:, model_format:)
347
- # Get a model.
348
- # Download a model that you can deploy to detect objects in images. The collection
349
- # must include a generated model, which is indicated in the response for the
350
- # collection details as `"rscnn_ready": true`. If the value is `false`, train or
351
- # retrain the collection to generate the model.
352
- #
353
- # Currently, the model format is specific to Android apps. For more information
354
- # about how to deploy the model to your app, see the [Watson Visual Recognition on
355
- # Android](https://github.com/matt-ny/rscnn) project in GitHub.
356
- # @param collection_id [String] The identifier of the collection.
357
- # @param feature [String] The feature for the model.
358
- # @param model_format [String] The format of the returned model.
359
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
360
- def get_model_file(collection_id:, feature:, model_format:)
361
- raise ArgumentError.new("version must be provided") if version.nil?
362
-
363
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
364
-
365
- raise ArgumentError.new("feature must be provided") if feature.nil?
366
-
367
- raise ArgumentError.new("model_format must be provided") if model_format.nil?
368
-
369
- headers = {
370
- }
371
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_model_file")
372
- headers.merge!(sdk_headers)
373
-
374
- params = {
375
- "version" => @version,
376
- "feature" => feature,
377
- "model_format" => model_format
378
- }
379
-
380
- method_url = "/v4/collections/%s/model" % [ERB::Util.url_encode(collection_id)]
381
-
382
- response = request(
383
- method: "GET",
384
- url: method_url,
385
- headers: headers,
386
- params: params,
387
- accept_json: false
388
- )
389
- response
390
- end
391
- #########################
392
- # Images
393
- #########################
394
-
395
- ##
396
- # @!method add_images(collection_id:, images_file: nil, image_url: nil, training_data: nil)
397
- # Add images.
398
- # Add images to a collection by URL, by file, or both.
399
- #
400
- # Encode the image and .zip file names in UTF-8 if they contain non-ASCII
401
- # characters. The service assumes UTF-8 encoding if it encounters non-ASCII
402
- # characters.
403
- # @param collection_id [String] The identifier of the collection.
404
- # @param images_file [Array[FileWithMetadata]] An array of image files (.jpg or .png) or .zip files with images.
405
- # - Include a maximum of 20 images in a request.
406
- # - Limit the .zip file to 100 MB.
407
- # - Limit each image file to 10 MB.
408
- #
409
- # You can also include an image with the **image_url** parameter.
410
- # @param image_url [Array[String]] The array of URLs of image files (.jpg or .png).
411
- # - Include a maximum of 20 images in a request.
412
- # - Limit each image file to 10 MB.
413
- # - Minimum width and height is 30 pixels, but the service tends to perform better
414
- # with images that are at least 300 x 300 pixels. Maximum is 5400 pixels for either
415
- # height or width.
416
- #
417
- # You can also include images with the **images_file** parameter.
418
- # @param training_data [String] Training data for a single image. Include training data only if you add one image
419
- # with the request.
420
- #
421
- # The `object` property can contain alphanumeric, underscore, hyphen, space, and dot
422
- # characters. It cannot begin with the reserved prefix `sys-` and must be no longer
423
- # than 32 characters.
424
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
425
- def add_images(collection_id:, images_file: nil, image_url: nil, training_data: nil)
426
- raise ArgumentError.new("version must be provided") if version.nil?
427
-
428
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
429
-
430
- headers = {
431
- }
432
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "add_images")
433
- headers.merge!(sdk_headers)
434
-
435
- params = {
436
- "version" => @version
437
- }
438
-
439
- form_data = {}
440
-
441
- form_data[:images_file] = []
442
- images_file&.each do |item|
443
- unless item[:data].instance_of?(StringIO) || item[:data].instance_of?(File)
444
- item[:data] = item[:data].respond_to?(:to_json) ? StringIO.new(item[:data].to_json) : StringIO.new(item[:data])
445
- end
446
- item[:filename] = item[:data].path if item[:filename].nil? && item[:data].respond_to?(:path)
447
- form_data[:images_file].push(HTTP::FormData::File.new(item[:data], content_type: item[:content_type], filename: item[:filename]))
448
- end
449
-
450
- form_data[:image_url] = []
451
- image_url&.each do |item|
452
- form_data[:image_url].push(HTTP::FormData::Part.new(item.to_s, content_type: "text/plain"))
453
- end
454
-
455
- form_data[:training_data] = HTTP::FormData::Part.new(training_data.to_s, content_type: "text/plain") unless training_data.nil?
456
-
457
- method_url = "/v4/collections/%s/images" % [ERB::Util.url_encode(collection_id)]
458
-
459
- response = request(
460
- method: "POST",
461
- url: method_url,
462
- headers: headers,
463
- params: params,
464
- form: form_data,
465
- accept_json: true
466
- )
467
- response
468
- end
469
-
470
- ##
471
- # @!method list_images(collection_id:)
472
- # List images.
473
- # Retrieves a list of images in a collection.
474
- # @param collection_id [String] The identifier of the collection.
475
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
476
- def list_images(collection_id:)
477
- raise ArgumentError.new("version must be provided") if version.nil?
478
-
479
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
480
-
481
- headers = {
482
- }
483
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "list_images")
484
- headers.merge!(sdk_headers)
485
-
486
- params = {
487
- "version" => @version
488
- }
489
-
490
- method_url = "/v4/collections/%s/images" % [ERB::Util.url_encode(collection_id)]
491
-
492
- response = request(
493
- method: "GET",
494
- url: method_url,
495
- headers: headers,
496
- params: params,
497
- accept_json: true
498
- )
499
- response
500
- end
501
-
502
- ##
503
- # @!method get_image_details(collection_id:, image_id:)
504
- # Get image details.
505
- # Get the details of an image in a collection.
506
- # @param collection_id [String] The identifier of the collection.
507
- # @param image_id [String] The identifier of the image.
508
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
509
- def get_image_details(collection_id:, image_id:)
510
- raise ArgumentError.new("version must be provided") if version.nil?
511
-
512
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
513
-
514
- raise ArgumentError.new("image_id must be provided") if image_id.nil?
515
-
516
- headers = {
517
- }
518
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_image_details")
519
- headers.merge!(sdk_headers)
520
-
521
- params = {
522
- "version" => @version
523
- }
524
-
525
- method_url = "/v4/collections/%s/images/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(image_id)]
526
-
527
- response = request(
528
- method: "GET",
529
- url: method_url,
530
- headers: headers,
531
- params: params,
532
- accept_json: true
533
- )
534
- response
535
- end
536
-
537
- ##
538
- # @!method delete_image(collection_id:, image_id:)
539
- # Delete an image.
540
- # Delete one image from a collection.
541
- # @param collection_id [String] The identifier of the collection.
542
- # @param image_id [String] The identifier of the image.
543
- # @return [nil]
544
- def delete_image(collection_id:, image_id:)
545
- raise ArgumentError.new("version must be provided") if version.nil?
546
-
547
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
548
-
549
- raise ArgumentError.new("image_id must be provided") if image_id.nil?
550
-
551
- headers = {
552
- }
553
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "delete_image")
554
- headers.merge!(sdk_headers)
555
-
556
- params = {
557
- "version" => @version
558
- }
559
-
560
- method_url = "/v4/collections/%s/images/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(image_id)]
561
-
562
- request(
563
- method: "DELETE",
564
- url: method_url,
565
- headers: headers,
566
- params: params,
567
- accept_json: true
568
- )
569
- nil
570
- end
571
-
572
- ##
573
- # @!method get_jpeg_image(collection_id:, image_id:, size: nil)
574
- # Get a JPEG file of an image.
575
- # Download a JPEG representation of an image.
576
- # @param collection_id [String] The identifier of the collection.
577
- # @param image_id [String] The identifier of the image.
578
- # @param size [String] The image size. Specify `thumbnail` to return a version that maintains the
579
- # original aspect ratio but is no larger than 200 pixels in the larger dimension.
580
- # For example, an original 800 x 1000 image is resized to 160 x 200 pixels.
581
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
582
- def get_jpeg_image(collection_id:, image_id:, size: nil)
583
- raise ArgumentError.new("version must be provided") if version.nil?
584
-
585
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
586
-
587
- raise ArgumentError.new("image_id must be provided") if image_id.nil?
588
-
589
- headers = {
590
- }
591
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_jpeg_image")
592
- headers.merge!(sdk_headers)
593
-
594
- params = {
595
- "version" => @version,
596
- "size" => size
597
- }
598
-
599
- method_url = "/v4/collections/%s/images/%s/jpeg" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(image_id)]
600
-
601
- response = request(
602
- method: "GET",
603
- url: method_url,
604
- headers: headers,
605
- params: params,
606
- accept_json: false
607
- )
608
- response
609
- end
610
- #########################
611
- # Objects
612
- #########################
613
-
614
- ##
615
- # @!method list_object_metadata(collection_id:)
616
- # List object metadata.
617
- # Retrieves a list of object names in a collection.
618
- # @param collection_id [String] The identifier of the collection.
619
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
620
- def list_object_metadata(collection_id:)
621
- raise ArgumentError.new("version must be provided") if version.nil?
622
-
623
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
624
-
625
- headers = {
626
- }
627
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "list_object_metadata")
628
- headers.merge!(sdk_headers)
629
-
630
- params = {
631
- "version" => @version
632
- }
633
-
634
- method_url = "/v4/collections/%s/objects" % [ERB::Util.url_encode(collection_id)]
635
-
636
- response = request(
637
- method: "GET",
638
- url: method_url,
639
- headers: headers,
640
- params: params,
641
- accept_json: true
642
- )
643
- response
644
- end
645
-
646
- ##
647
- # @!method update_object_metadata(collection_id:, object:, new_object:)
648
- # Update an object name.
649
- # Update the name of an object. A successful request updates the training data for
650
- # all images that use the object.
651
- # @param collection_id [String] The identifier of the collection.
652
- # @param object [String] The name of the object.
653
- # @param new_object [String] The updated name of the object. The name can contain alphanumeric, underscore,
654
- # hyphen, space, and dot characters. It cannot begin with the reserved prefix
655
- # `sys-`.
656
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
657
- def update_object_metadata(collection_id:, object:, new_object:)
658
- raise ArgumentError.new("version must be provided") if version.nil?
659
-
660
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
661
-
662
- raise ArgumentError.new("object must be provided") if object.nil?
663
-
664
- raise ArgumentError.new("new_object must be provided") if new_object.nil?
665
-
666
- headers = {
667
- }
668
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "update_object_metadata")
669
- headers.merge!(sdk_headers)
670
-
671
- params = {
672
- "version" => @version
673
- }
674
-
675
- data = {
676
- "object" => new_object
677
- }
678
-
679
- method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
680
-
681
- response = request(
682
- method: "POST",
683
- url: method_url,
684
- headers: headers,
685
- params: params,
686
- json: data,
687
- accept_json: true
688
- )
689
- response
690
- end
691
-
692
- ##
693
- # @!method get_object_metadata(collection_id:, object:)
694
- # Get object metadata.
695
- # Get the number of bounding boxes for a single object in a collection.
696
- # @param collection_id [String] The identifier of the collection.
697
- # @param object [String] The name of the object.
698
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
699
- def get_object_metadata(collection_id:, object:)
700
- raise ArgumentError.new("version must be provided") if version.nil?
701
-
702
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
703
-
704
- raise ArgumentError.new("object must be provided") if object.nil?
705
-
706
- headers = {
707
- }
708
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_object_metadata")
709
- headers.merge!(sdk_headers)
710
-
711
- params = {
712
- "version" => @version
713
- }
714
-
715
- method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
716
-
717
- response = request(
718
- method: "GET",
719
- url: method_url,
720
- headers: headers,
721
- params: params,
722
- accept_json: true
723
- )
724
- response
725
- end
726
-
727
- ##
728
- # @!method delete_object(collection_id:, object:)
729
- # Delete an object.
730
- # Delete one object from a collection. A successful request deletes the training
731
- # data from all images that use the object.
732
- # @param collection_id [String] The identifier of the collection.
733
- # @param object [String] The name of the object.
734
- # @return [nil]
735
- def delete_object(collection_id:, object:)
736
- raise ArgumentError.new("version must be provided") if version.nil?
737
-
738
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
739
-
740
- raise ArgumentError.new("object must be provided") if object.nil?
741
-
742
- headers = {
743
- }
744
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "delete_object")
745
- headers.merge!(sdk_headers)
746
-
747
- params = {
748
- "version" => @version
749
- }
750
-
751
- method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
752
-
753
- request(
754
- method: "DELETE",
755
- url: method_url,
756
- headers: headers,
757
- params: params,
758
- accept_json: true
759
- )
760
- nil
761
- end
762
- #########################
763
- # Training
764
- #########################
765
-
766
- ##
767
- # @!method train(collection_id:)
768
- # Train a collection.
769
- # Start training on images in a collection. The collection must have enough training
770
- # data and untrained data (the **training_status.objects.data_changed** is `true`).
771
- # If training is in progress, the request queues the next training job.
772
- # @param collection_id [String] The identifier of the collection.
773
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
774
- def train(collection_id:)
775
- raise ArgumentError.new("version must be provided") if version.nil?
776
-
777
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
778
-
779
- headers = {
780
- }
781
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "train")
782
- headers.merge!(sdk_headers)
783
-
784
- params = {
785
- "version" => @version
786
- }
787
-
788
- method_url = "/v4/collections/%s/train" % [ERB::Util.url_encode(collection_id)]
789
-
790
- response = request(
791
- method: "POST",
792
- url: method_url,
793
- headers: headers,
794
- params: params,
795
- accept_json: true
796
- )
797
- response
798
- end
799
-
800
- ##
801
- # @!method add_image_training_data(collection_id:, image_id:, objects: nil)
802
- # Add training data to an image.
803
- # Add, update, or delete training data for an image. Encode the object name in UTF-8
804
- # if it contains non-ASCII characters. The service assumes UTF-8 encoding if it
805
- # encounters non-ASCII characters.
806
- #
807
- # Elements in the request replace the existing elements.
808
- #
809
- # - To update the training data, provide both the unchanged and the new or changed
810
- # values.
811
- #
812
- # - To delete the training data, provide an empty value for the training data.
813
- # @param collection_id [String] The identifier of the collection.
814
- # @param image_id [String] The identifier of the image.
815
- # @param objects [Array[TrainingDataObject]] Training data for specific objects.
816
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
817
- def add_image_training_data(collection_id:, image_id:, objects: nil)
818
- raise ArgumentError.new("version must be provided") if version.nil?
819
-
820
- raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
821
-
822
- raise ArgumentError.new("image_id must be provided") if image_id.nil?
823
-
824
- headers = {
825
- }
826
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "add_image_training_data")
827
- headers.merge!(sdk_headers)
828
-
829
- params = {
830
- "version" => @version
831
- }
832
-
833
- data = {
834
- "objects" => objects
835
- }
836
-
837
- method_url = "/v4/collections/%s/images/%s/training_data" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(image_id)]
838
-
839
- response = request(
840
- method: "POST",
841
- url: method_url,
842
- headers: headers,
843
- params: params,
844
- json: data,
845
- accept_json: true
846
- )
847
- response
848
- end
849
-
850
- ##
851
- # @!method get_training_usage(start_time: nil, end_time: nil)
852
- # Get training usage.
853
- # Information about the completed training events. You can use this information to
854
- # determine how close you are to the training limits for the month.
855
- # @param start_time [Time] The earliest day to include training events. Specify dates in YYYY-MM-DD format.
856
- # If empty or not specified, the earliest training event is included.
857
- # @param end_time [Time] The most recent day to include training events. Specify dates in YYYY-MM-DD
858
- # format. All events for the day are included. If empty or not specified, the
859
- # current day is used. Specify the same value as `start_time` to request events for
860
- # a single day.
861
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
862
- def get_training_usage(start_time: nil, end_time: nil)
863
- raise ArgumentError.new("version must be provided") if version.nil?
864
-
865
- headers = {
866
- }
867
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_training_usage")
868
- headers.merge!(sdk_headers)
869
-
870
- params = {
871
- "version" => @version,
872
- "start_time" => start_time,
873
- "end_time" => end_time
874
- }
875
-
876
- method_url = "/v4/training_usage"
877
-
878
- response = request(
879
- method: "GET",
880
- url: method_url,
881
- headers: headers,
882
- params: params,
883
- accept_json: true
884
- )
885
- response
886
- end
887
- #########################
888
- # User data
889
- #########################
890
-
891
- ##
892
- # @!method delete_user_data(customer_id:)
893
- # Delete labeled data.
894
- # Deletes all data associated with a specified customer ID. The method has no effect
895
- # if no data is associated with the customer ID.
896
- #
897
- # You associate a customer ID with data by passing the `X-Watson-Metadata` header
898
- # with a request that passes data. For more information about personal data and
899
- # customer IDs, see [Information
900
- # security](https://cloud.ibm.com/docs/visual-recognition?topic=visual-recognition-information-security).
901
- # @param customer_id [String] The customer ID for which all data is to be deleted.
902
- # @return [nil]
903
- def delete_user_data(customer_id:)
904
- raise ArgumentError.new("version must be provided") if version.nil?
905
-
906
- raise ArgumentError.new("customer_id must be provided") if customer_id.nil?
907
-
908
- headers = {
909
- }
910
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "delete_user_data")
911
- headers.merge!(sdk_headers)
912
-
913
- params = {
914
- "version" => @version,
915
- "customer_id" => customer_id
916
- }
917
-
918
- method_url = "/v4/user_data"
919
-
920
- request(
921
- method: "DELETE",
922
- url: method_url,
923
- headers: headers,
924
- params: params,
925
- accept_json: true
926
- )
927
- nil
928
- end
929
- end
930
- end