ibm_watson 1.6.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -4
- data/lib/ibm_watson/assistant_v1.rb +277 -81
- data/lib/ibm_watson/assistant_v2.rb +100 -22
- data/lib/ibm_watson/compare_comply_v1.rb +44 -23
- data/lib/ibm_watson/discovery_v1.rb +132 -14
- data/lib/ibm_watson/discovery_v2.rb +234 -18
- data/lib/ibm_watson/language_translator_v3.rb +59 -27
- data/lib/ibm_watson/natural_language_classifier_v1.rb +3 -2
- data/lib/ibm_watson/natural_language_understanding_v1.rb +705 -14
- data/lib/ibm_watson/personality_insights_v3.rb +29 -18
- data/lib/ibm_watson/speech_to_text_v1.rb +278 -121
- data/lib/ibm_watson/text_to_speech_v1.rb +689 -130
- data/lib/ibm_watson/tone_analyzer_v3.rb +11 -13
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +32 -16
- data/lib/ibm_watson/visual_recognition_v4.rb +67 -23
- data/test/integration/test_assistant_v1.rb +9 -0
- data/test/integration/test_assistant_v2.rb +9 -0
- data/test/integration/test_discovery_v2.rb +29 -0
- data/test/integration/test_natural_language_understanding_v1.rb +134 -1
- data/test/integration/test_text_to_speech_v1.rb +60 -3
- data/test/unit/test_assistant_v1.rb +52 -1
- data/test/unit/test_assistant_v2.rb +51 -0
- data/test/unit/test_discovery_v2.rb +30 -1
- data/test/unit/test_natural_language_understanding_v1.rb +231 -0
- data/test/unit/test_text_to_speech_v1.rb +152 -7
- metadata +12 -11
@@ -13,7 +13,9 @@
|
|
13
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
|
-
|
16
|
+
#
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
|
18
|
+
#
|
17
19
|
# IBM Watson™ Language Translator translates text from one language to another.
|
18
20
|
# The service offers multiple IBM-provided translation models that you can customize based
|
19
21
|
# on your unique terminology and language. Use Language Translator to take news from
|
@@ -26,7 +28,6 @@ require "json"
|
|
26
28
|
require "ibm_cloud_sdk_core"
|
27
29
|
require_relative "./common.rb"
|
28
30
|
|
29
|
-
# Module for the Watson APIs
|
30
31
|
module IBMWatson
|
31
32
|
##
|
32
33
|
# The Language Translator V3 service.
|
@@ -34,21 +35,14 @@ module IBMWatson
|
|
34
35
|
include Concurrent::Async
|
35
36
|
DEFAULT_SERVICE_NAME = "language_translator"
|
36
37
|
DEFAULT_SERVICE_URL = "https://api.us-south.language-translator.watson.cloud.ibm.com"
|
38
|
+
attr_accessor :version
|
37
39
|
##
|
38
40
|
# @!method initialize(args)
|
39
41
|
# Construct a new client for the Language Translator service.
|
40
42
|
#
|
41
43
|
# @param args [Hash] The args to initialize with
|
42
|
-
# @option args version [String]
|
43
|
-
#
|
44
|
-
# incompatible way, a new minor version of the API is released.
|
45
|
-
# The service uses the API version for the date you specify, or
|
46
|
-
# the most recent version before that date. Note that you should
|
47
|
-
# not programmatically specify the current date at runtime, in
|
48
|
-
# case the API has been updated since your application's release.
|
49
|
-
# Instead, specify a version date that is compatible with your
|
50
|
-
# application, and don't change it until your application is
|
51
|
-
# ready for a later version.
|
44
|
+
# @option args version [String] Release date of the version of the API you want to use. Specify dates in
|
45
|
+
# YYYY-MM-DD format. The current version is `2018-05-01`.
|
52
46
|
# @option args service_url [String] The base service URL to use when contacting the service.
|
53
47
|
# The base service_url may differ between IBM Cloud regions.
|
54
48
|
# @option args authenticator [Object] The Authenticator instance to be configured for this service.
|
@@ -57,10 +51,10 @@ module IBMWatson
|
|
57
51
|
def initialize(args = {})
|
58
52
|
@__async_initialized__ = false
|
59
53
|
defaults = {}
|
60
|
-
defaults[:version] = nil
|
61
54
|
defaults[:service_url] = DEFAULT_SERVICE_URL
|
62
55
|
defaults[:service_name] = DEFAULT_SERVICE_NAME
|
63
56
|
defaults[:authenticator] = nil
|
57
|
+
defaults[:version] = nil
|
64
58
|
user_service_url = args[:service_url] unless args[:service_url].nil?
|
65
59
|
args = defaults.merge(args)
|
66
60
|
@version = args[:version]
|
@@ -78,11 +72,16 @@ module IBMWatson
|
|
78
72
|
##
|
79
73
|
# @!method list_languages
|
80
74
|
# List supported languages.
|
81
|
-
# Lists all supported languages. The method returns an array of
|
82
|
-
# with information about each language. Languages are listed in
|
83
|
-
# by language code (for example, `af`, `ar`).
|
75
|
+
# Lists all supported languages for translation. The method returns an array of
|
76
|
+
# supported languages with information about each language. Languages are listed in
|
77
|
+
# alphabetical order by language code (for example, `af`, `ar`). In addition to
|
78
|
+
# basic information about each language, the response indicates whether the language
|
79
|
+
# is `supported_as_source` for translation and `supported_as_target` for
|
80
|
+
# translation. It also lists whether the language is `identifiable`.
|
84
81
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
85
82
|
def list_languages
|
83
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
84
|
+
|
86
85
|
headers = {
|
87
86
|
}
|
88
87
|
sdk_headers = Common.new.get_sdk_headers("language_translator", "V3", "list_languages")
|
@@ -116,8 +115,12 @@ module IBMWatson
|
|
116
115
|
# service attempt to detect the language from the input text. If you omit the source
|
117
116
|
# language, the request must contain sufficient input text for the service to
|
118
117
|
# identify the source language.
|
119
|
-
#
|
120
|
-
#
|
118
|
+
#
|
119
|
+
# You can translate a maximum of 50 KB (51,200 bytes) of text with a single request.
|
120
|
+
# All input text must be encoded in UTF-8 format.
|
121
|
+
# @param text [Array[String]] Input text in UTF-8 encoding. Submit a maximum of 50 KB (51,200 bytes) of text
|
122
|
+
# with a single request. Multiple elements result in multiple translations in the
|
123
|
+
# response.
|
121
124
|
# @param model_id [String] The model to use for translation. For example, `en-de` selects the IBM-provided
|
122
125
|
# base model for English-to-German translation. A model ID overrides the `source`
|
123
126
|
# and `target` parameters and is required if you use a custom model. If no model ID
|
@@ -129,6 +132,8 @@ module IBMWatson
|
|
129
132
|
# model ID is not specified.
|
130
133
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
131
134
|
def translate(text:, model_id: nil, source: nil, target: nil)
|
135
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
136
|
+
|
132
137
|
raise ArgumentError.new("text must be provided") if text.nil?
|
133
138
|
|
134
139
|
headers = {
|
@@ -170,6 +175,8 @@ module IBMWatson
|
|
170
175
|
# example, `en` for English or `es` for Spanish) and name of each language.
|
171
176
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
172
177
|
def list_identifiable_languages
|
178
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
179
|
+
|
173
180
|
headers = {
|
174
181
|
}
|
175
182
|
sdk_headers = Common.new.get_sdk_headers("language_translator", "V3", "list_identifiable_languages")
|
@@ -198,6 +205,8 @@ module IBMWatson
|
|
198
205
|
# @param text [String] Input text in UTF-8 format.
|
199
206
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
200
207
|
def identify(text:)
|
208
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
209
|
+
|
201
210
|
raise ArgumentError.new("text must be provided") if text.nil?
|
202
211
|
|
203
212
|
headers = {
|
@@ -241,6 +250,8 @@ module IBMWatson
|
|
241
250
|
# model, per language pair.
|
242
251
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
243
252
|
def list_models(source: nil, target: nil, default: nil)
|
253
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
254
|
+
|
244
255
|
headers = {
|
245
256
|
}
|
246
257
|
sdk_headers = Common.new.get_sdk_headers("language_translator", "V3", "list_models")
|
@@ -302,9 +313,13 @@ module IBMWatson
|
|
302
313
|
# * **XLIFF** (`.xliff`) - XML Localization Interchange File Format (XLIFF) is an
|
303
314
|
# XML specification for the exchange of translation memories.
|
304
315
|
# * **CSV** (`.csv`) - Comma-separated values (CSV) file with two columns for
|
305
|
-
# aligned sentences and phrases. The first row
|
316
|
+
# aligned sentences and phrases. The first row must have two language codes. The
|
317
|
+
# first column is for the source language code, and the second column is for the
|
318
|
+
# target language code.
|
306
319
|
# * **TSV** (`.tsv` or `.tab`) - Tab-separated values (TSV) file with two columns
|
307
|
-
# for aligned sentences and phrases. The first row
|
320
|
+
# for aligned sentences and phrases. The first row must have two language codes. The
|
321
|
+
# first column is for the source language code, and the second column is for the
|
322
|
+
# target language code.
|
308
323
|
# * **JSON** (`.json`) - Custom JSON format for specifying aligned sentences and
|
309
324
|
# phrases.
|
310
325
|
# * **Microsoft Excel** (`.xls` or `.xlsx`) - Excel file with the first two columns
|
@@ -365,6 +380,8 @@ module IBMWatson
|
|
365
380
|
# length of the name is 32 characters.
|
366
381
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
367
382
|
def create_model(base_model_id:, forced_glossary: nil, parallel_corpus: nil, name: nil)
|
383
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
384
|
+
|
368
385
|
raise ArgumentError.new("base_model_id must be provided") if base_model_id.nil?
|
369
386
|
|
370
387
|
headers = {
|
@@ -414,6 +431,8 @@ module IBMWatson
|
|
414
431
|
# @param model_id [String] Model ID of the model to delete.
|
415
432
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
416
433
|
def delete_model(model_id:)
|
434
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
435
|
+
|
417
436
|
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
418
437
|
|
419
438
|
headers = {
|
@@ -446,6 +465,8 @@ module IBMWatson
|
|
446
465
|
# @param model_id [String] Model ID of the model to get.
|
447
466
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
448
467
|
def get_model(model_id:)
|
468
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
469
|
+
|
449
470
|
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
450
471
|
|
451
472
|
headers = {
|
@@ -478,6 +499,8 @@ module IBMWatson
|
|
478
499
|
# Lists documents that have been submitted for translation.
|
479
500
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
480
501
|
def list_documents
|
502
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
503
|
+
|
481
504
|
headers = {
|
482
505
|
}
|
483
506
|
sdk_headers = Common.new.get_sdk_headers("language_translator", "V3", "list_documents")
|
@@ -504,13 +527,14 @@ module IBMWatson
|
|
504
527
|
# Translate document.
|
505
528
|
# Submit a document for translation. You can submit the document contents in the
|
506
529
|
# `file` parameter, or you can reference a previously submitted document by document
|
507
|
-
# ID.
|
508
|
-
#
|
509
|
-
#
|
510
|
-
#
|
511
|
-
#
|
512
|
-
#
|
513
|
-
#
|
530
|
+
# ID. The maximum file size for document translation is
|
531
|
+
# * 20 MB for service instances on the Standard, Advanced, and Premium plans
|
532
|
+
# * 2 MB for service instances on the Lite plan.
|
533
|
+
# @param file [File] The contents of the source file to translate. The maximum file size for document
|
534
|
+
# translation is 20 MB for service instances on the Standard, Advanced, and Premium
|
535
|
+
# plans, and 2 MB for service instances on the Lite plan. For more information, see
|
536
|
+
# [Supported file formats
|
537
|
+
# (Beta)](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats).
|
514
538
|
# @param filename [String] The filename for file.
|
515
539
|
# @param file_content_type [String] The content type of file.
|
516
540
|
# @param model_id [String] The model to use for translation. For example, `en-de` selects the IBM-provided
|
@@ -526,6 +550,8 @@ module IBMWatson
|
|
526
550
|
# the `document_id` of the document.
|
527
551
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
528
552
|
def translate_document(file:, filename: nil, file_content_type: nil, model_id: nil, source: nil, target: nil, document_id: nil)
|
553
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
554
|
+
|
529
555
|
raise ArgumentError.new("file must be provided") if file.nil?
|
530
556
|
|
531
557
|
headers = {
|
@@ -573,6 +599,8 @@ module IBMWatson
|
|
573
599
|
# @param document_id [String] The document ID of the document.
|
574
600
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
575
601
|
def get_document_status(document_id:)
|
602
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
603
|
+
|
576
604
|
raise ArgumentError.new("document_id must be provided") if document_id.nil?
|
577
605
|
|
578
606
|
headers = {
|
@@ -603,6 +631,8 @@ module IBMWatson
|
|
603
631
|
# @param document_id [String] Document ID of the document to delete.
|
604
632
|
# @return [nil]
|
605
633
|
def delete_document(document_id:)
|
634
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
635
|
+
|
606
636
|
raise ArgumentError.new("document_id must be provided") if document_id.nil?
|
607
637
|
|
608
638
|
headers = {
|
@@ -646,6 +676,8 @@ module IBMWatson
|
|
646
676
|
# example, 'text/html;charset=utf-8'.
|
647
677
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
648
678
|
def get_translated_document(document_id:, accept: nil)
|
679
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
680
|
+
|
649
681
|
raise ArgumentError.new("document_id must be provided") if document_id.nil?
|
650
682
|
|
651
683
|
headers = {
|
@@ -13,7 +13,9 @@
|
|
13
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
|
-
|
16
|
+
#
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
|
18
|
+
#
|
17
19
|
# IBM Watson™ Natural Language Classifier uses machine learning algorithms to
|
18
20
|
# return the top matching predefined classes for short text input. You create and train a
|
19
21
|
# classifier to connect predefined classes to example texts so that the service can apply
|
@@ -25,7 +27,6 @@ require "json"
|
|
25
27
|
require "ibm_cloud_sdk_core"
|
26
28
|
require_relative "./common.rb"
|
27
29
|
|
28
|
-
# Module for the Watson APIs
|
29
30
|
module IBMWatson
|
30
31
|
##
|
31
32
|
# The Natural Language Classifier V1 service.
|
@@ -13,7 +13,9 @@
|
|
13
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
|
-
|
16
|
+
#
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
|
18
|
+
#
|
17
19
|
# Analyze various features of text content at scale. Provide text, raw HTML, or a public
|
18
20
|
# URL and IBM Watson Natural Language Understanding will give you results for the features
|
19
21
|
# you request. The service cleans HTML content before analysis by default, so the results
|
@@ -30,7 +32,6 @@ require "json"
|
|
30
32
|
require "ibm_cloud_sdk_core"
|
31
33
|
require_relative "./common.rb"
|
32
34
|
|
33
|
-
# Module for the Watson APIs
|
34
35
|
module IBMWatson
|
35
36
|
##
|
36
37
|
# The Natural Language Understanding V1 service.
|
@@ -38,21 +39,14 @@ module IBMWatson
|
|
38
39
|
include Concurrent::Async
|
39
40
|
DEFAULT_SERVICE_NAME = "natural_language_understanding"
|
40
41
|
DEFAULT_SERVICE_URL = "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
42
|
+
attr_accessor :version
|
41
43
|
##
|
42
44
|
# @!method initialize(args)
|
43
45
|
# Construct a new client for the Natural Language Understanding service.
|
44
46
|
#
|
45
47
|
# @param args [Hash] The args to initialize with
|
46
|
-
# @option args version [String]
|
47
|
-
#
|
48
|
-
# incompatible way, a new minor version of the API is released.
|
49
|
-
# The service uses the API version for the date you specify, or
|
50
|
-
# the most recent version before that date. Note that you should
|
51
|
-
# not programmatically specify the current date at runtime, in
|
52
|
-
# case the API has been updated since your application's release.
|
53
|
-
# Instead, specify a version date that is compatible with your
|
54
|
-
# application, and don't change it until your application is
|
55
|
-
# ready for a later version.
|
48
|
+
# @option args version [String] Release date of the API version you want to use. Specify dates in YYYY-MM-DD
|
49
|
+
# format. The current version is `2021-03-25`.
|
56
50
|
# @option args service_url [String] The base service URL to use when contacting the service.
|
57
51
|
# The base service_url may differ between IBM Cloud regions.
|
58
52
|
# @option args authenticator [Object] The Authenticator instance to be configured for this service.
|
@@ -61,10 +55,10 @@ module IBMWatson
|
|
61
55
|
def initialize(args = {})
|
62
56
|
@__async_initialized__ = false
|
63
57
|
defaults = {}
|
64
|
-
defaults[:version] = nil
|
65
58
|
defaults[:service_url] = DEFAULT_SERVICE_URL
|
66
59
|
defaults[:service_name] = DEFAULT_SERVICE_NAME
|
67
60
|
defaults[:authenticator] = nil
|
61
|
+
defaults[:version] = nil
|
68
62
|
user_service_url = args[:service_url] unless args[:service_url].nil?
|
69
63
|
args = defaults.merge(args)
|
70
64
|
@version = args[:version]
|
@@ -84,6 +78,7 @@ module IBMWatson
|
|
84
78
|
# Analyze text.
|
85
79
|
# Analyzes text, HTML, or a public webpage for the following features:
|
86
80
|
# - Categories
|
81
|
+
# - Classifications
|
87
82
|
# - Concepts
|
88
83
|
# - Emotion
|
89
84
|
# - Entities
|
@@ -92,7 +87,8 @@ module IBMWatson
|
|
92
87
|
# - Relations
|
93
88
|
# - Semantic roles
|
94
89
|
# - Sentiment
|
95
|
-
# - Syntax
|
90
|
+
# - Syntax
|
91
|
+
# - Summarization (Experimental)
|
96
92
|
#
|
97
93
|
# If a language for the input text is not specified with the `language` parameter,
|
98
94
|
# the service [automatically detects the
|
@@ -121,6 +117,8 @@ module IBMWatson
|
|
121
117
|
# @param limit_text_characters [Fixnum] Sets the maximum number of characters that are processed by the service.
|
122
118
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
123
119
|
def analyze(features:, text: nil, html: nil, url: nil, clean: nil, xpath: nil, fallback_to_raw: nil, return_analyzed_text: nil, language: nil, limit_text_characters: nil)
|
120
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
121
|
+
|
124
122
|
raise ArgumentError.new("features must be provided") if features.nil?
|
125
123
|
|
126
124
|
headers = {
|
@@ -169,6 +167,8 @@ module IBMWatson
|
|
169
167
|
# that are deployed to your Natural Language Understanding service.
|
170
168
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
171
169
|
def list_models
|
170
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
171
|
+
|
172
172
|
headers = {
|
173
173
|
}
|
174
174
|
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_models")
|
@@ -197,6 +197,8 @@ module IBMWatson
|
|
197
197
|
# @param model_id [String] Model ID of the model to delete.
|
198
198
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
199
199
|
def delete_model(model_id:)
|
200
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
201
|
+
|
200
202
|
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
201
203
|
|
202
204
|
headers = {
|
@@ -210,6 +212,695 @@ module IBMWatson
|
|
210
212
|
|
211
213
|
method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)]
|
212
214
|
|
215
|
+
response = request(
|
216
|
+
method: "DELETE",
|
217
|
+
url: method_url,
|
218
|
+
headers: headers,
|
219
|
+
params: params,
|
220
|
+
accept_json: true
|
221
|
+
)
|
222
|
+
response
|
223
|
+
end
|
224
|
+
#########################
|
225
|
+
# Manage sentiment models
|
226
|
+
#########################
|
227
|
+
|
228
|
+
##
|
229
|
+
# @!method create_sentiment_model(language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
230
|
+
# Create sentiment model.
|
231
|
+
# (Beta) Creates a custom sentiment model by uploading training data and associated
|
232
|
+
# metadata. The model begins the training and deploying process and is ready to use
|
233
|
+
# when the `status` is `available`.
|
234
|
+
# @param language [String] The 2-letter language code of this model.
|
235
|
+
# @param training_data [File] Training data in CSV format. For more information, see [Sentiment training data
|
236
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-custom-sentiment#sentiment-training-data-requirements).
|
237
|
+
# @param name [String] An optional name for the model.
|
238
|
+
# @param description [String] An optional description of the model.
|
239
|
+
# @param model_version [String] An optional version string.
|
240
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
241
|
+
# Language Understanding.
|
242
|
+
# @param version_description [String] The description of the version.
|
243
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
244
|
+
def create_sentiment_model(language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
245
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
246
|
+
|
247
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
248
|
+
|
249
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
250
|
+
|
251
|
+
headers = {
|
252
|
+
}
|
253
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_sentiment_model")
|
254
|
+
headers.merge!(sdk_headers)
|
255
|
+
|
256
|
+
params = {
|
257
|
+
"version" => @version
|
258
|
+
}
|
259
|
+
|
260
|
+
form_data = {}
|
261
|
+
|
262
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
263
|
+
|
264
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
265
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
266
|
+
end
|
267
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: "text/csv", filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
268
|
+
|
269
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
270
|
+
|
271
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
272
|
+
|
273
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
274
|
+
|
275
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
276
|
+
|
277
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
278
|
+
|
279
|
+
method_url = "/v1/models/sentiment"
|
280
|
+
|
281
|
+
response = request(
|
282
|
+
method: "POST",
|
283
|
+
url: method_url,
|
284
|
+
headers: headers,
|
285
|
+
params: params,
|
286
|
+
form: form_data,
|
287
|
+
accept_json: true
|
288
|
+
)
|
289
|
+
response
|
290
|
+
end
|
291
|
+
|
292
|
+
##
|
293
|
+
# @!method list_sentiment_models
|
294
|
+
# List sentiment models.
|
295
|
+
# (Beta) Returns all custom sentiment models associated with this service instance.
|
296
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
297
|
+
def list_sentiment_models
|
298
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
299
|
+
|
300
|
+
headers = {
|
301
|
+
}
|
302
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_sentiment_models")
|
303
|
+
headers.merge!(sdk_headers)
|
304
|
+
|
305
|
+
params = {
|
306
|
+
"version" => @version
|
307
|
+
}
|
308
|
+
|
309
|
+
method_url = "/v1/models/sentiment"
|
310
|
+
|
311
|
+
response = request(
|
312
|
+
method: "GET",
|
313
|
+
url: method_url,
|
314
|
+
headers: headers,
|
315
|
+
params: params,
|
316
|
+
accept_json: true
|
317
|
+
)
|
318
|
+
response
|
319
|
+
end
|
320
|
+
|
321
|
+
##
|
322
|
+
# @!method get_sentiment_model(model_id:)
|
323
|
+
# Get sentiment model details.
|
324
|
+
# (Beta) Returns the status of the sentiment model with the given model ID.
|
325
|
+
# @param model_id [String] ID of the model.
|
326
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
327
|
+
def get_sentiment_model(model_id:)
|
328
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
329
|
+
|
330
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
331
|
+
|
332
|
+
headers = {
|
333
|
+
}
|
334
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_sentiment_model")
|
335
|
+
headers.merge!(sdk_headers)
|
336
|
+
|
337
|
+
params = {
|
338
|
+
"version" => @version
|
339
|
+
}
|
340
|
+
|
341
|
+
method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]
|
342
|
+
|
343
|
+
response = request(
|
344
|
+
method: "GET",
|
345
|
+
url: method_url,
|
346
|
+
headers: headers,
|
347
|
+
params: params,
|
348
|
+
accept_json: true
|
349
|
+
)
|
350
|
+
response
|
351
|
+
end
|
352
|
+
|
353
|
+
##
|
354
|
+
# @!method update_sentiment_model(model_id:, language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
355
|
+
# Update sentiment model.
|
356
|
+
# (Beta) Overwrites the training data associated with this custom sentiment model
|
357
|
+
# and retrains the model. The new model replaces the current deployment.
|
358
|
+
# @param model_id [String] ID of the model.
|
359
|
+
# @param language [String] The 2-letter language code of this model.
|
360
|
+
# @param training_data [File] Training data in CSV format. For more information, see [Sentiment training data
|
361
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-custom-sentiment#sentiment-training-data-requirements).
|
362
|
+
# @param name [String] An optional name for the model.
|
363
|
+
# @param description [String] An optional description of the model.
|
364
|
+
# @param model_version [String] An optional version string.
|
365
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
366
|
+
# Language Understanding.
|
367
|
+
# @param version_description [String] The description of the version.
|
368
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
369
|
+
def update_sentiment_model(model_id:, language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
370
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
371
|
+
|
372
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
373
|
+
|
374
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
375
|
+
|
376
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
377
|
+
|
378
|
+
headers = {
|
379
|
+
}
|
380
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_sentiment_model")
|
381
|
+
headers.merge!(sdk_headers)
|
382
|
+
|
383
|
+
params = {
|
384
|
+
"version" => @version
|
385
|
+
}
|
386
|
+
|
387
|
+
form_data = {}
|
388
|
+
|
389
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
390
|
+
|
391
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
392
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
393
|
+
end
|
394
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: "text/csv", filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
395
|
+
|
396
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
397
|
+
|
398
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
399
|
+
|
400
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
401
|
+
|
402
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
403
|
+
|
404
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
405
|
+
|
406
|
+
method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]
|
407
|
+
|
408
|
+
response = request(
|
409
|
+
method: "PUT",
|
410
|
+
url: method_url,
|
411
|
+
headers: headers,
|
412
|
+
params: params,
|
413
|
+
form: form_data,
|
414
|
+
accept_json: true
|
415
|
+
)
|
416
|
+
response
|
417
|
+
end
|
418
|
+
|
419
|
+
##
|
420
|
+
# @!method delete_sentiment_model(model_id:)
|
421
|
+
# Delete sentiment model.
|
422
|
+
# (Beta) Un-deploys the custom sentiment model with the given model ID and deletes
|
423
|
+
# all associated customer data, including any training data or binary artifacts.
|
424
|
+
# @param model_id [String] ID of the model.
|
425
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
426
|
+
def delete_sentiment_model(model_id:)
|
427
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
428
|
+
|
429
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
430
|
+
|
431
|
+
headers = {
|
432
|
+
}
|
433
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_sentiment_model")
|
434
|
+
headers.merge!(sdk_headers)
|
435
|
+
|
436
|
+
params = {
|
437
|
+
"version" => @version
|
438
|
+
}
|
439
|
+
|
440
|
+
method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]
|
441
|
+
|
442
|
+
response = request(
|
443
|
+
method: "DELETE",
|
444
|
+
url: method_url,
|
445
|
+
headers: headers,
|
446
|
+
params: params,
|
447
|
+
accept_json: true
|
448
|
+
)
|
449
|
+
response
|
450
|
+
end
|
451
|
+
#########################
|
452
|
+
# Manage categories models
|
453
|
+
#########################
|
454
|
+
|
455
|
+
##
|
456
|
+
# @!method create_categories_model(language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
457
|
+
# Create categories model.
|
458
|
+
# (Beta) Creates a custom categories model by uploading training data and associated
|
459
|
+
# metadata. The model begins the training and deploying process and is ready to use
|
460
|
+
# when the `status` is `available`.
|
461
|
+
# @param language [String] The 2-letter language code of this model.
|
462
|
+
# @param training_data [File] Training data in JSON format. For more information, see [Categories training data
|
463
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-categories##categories-training-data-requirements).
|
464
|
+
# @param training_data_content_type [String] The content type of training_data.
|
465
|
+
# @param name [String] An optional name for the model.
|
466
|
+
# @param description [String] An optional description of the model.
|
467
|
+
# @param model_version [String] An optional version string.
|
468
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
469
|
+
# Language Understanding.
|
470
|
+
# @param version_description [String] The description of the version.
|
471
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
472
|
+
def create_categories_model(language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
473
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
474
|
+
|
475
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
476
|
+
|
477
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
478
|
+
|
479
|
+
headers = {
|
480
|
+
}
|
481
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_categories_model")
|
482
|
+
headers.merge!(sdk_headers)
|
483
|
+
|
484
|
+
params = {
|
485
|
+
"version" => @version
|
486
|
+
}
|
487
|
+
|
488
|
+
form_data = {}
|
489
|
+
|
490
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
491
|
+
|
492
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
493
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
494
|
+
end
|
495
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: training_data_content_type.nil? ? "application/octet-stream" : training_data_content_type, filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
496
|
+
|
497
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
498
|
+
|
499
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
500
|
+
|
501
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
502
|
+
|
503
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
504
|
+
|
505
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
506
|
+
|
507
|
+
method_url = "/v1/models/categories"
|
508
|
+
|
509
|
+
response = request(
|
510
|
+
method: "POST",
|
511
|
+
url: method_url,
|
512
|
+
headers: headers,
|
513
|
+
params: params,
|
514
|
+
form: form_data,
|
515
|
+
accept_json: true
|
516
|
+
)
|
517
|
+
response
|
518
|
+
end
|
519
|
+
|
520
|
+
##
|
521
|
+
# @!method list_categories_models
|
522
|
+
# List categories models.
|
523
|
+
# (Beta) Returns all custom categories models associated with this service instance.
|
524
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
525
|
+
def list_categories_models
|
526
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
527
|
+
|
528
|
+
headers = {
|
529
|
+
}
|
530
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_categories_models")
|
531
|
+
headers.merge!(sdk_headers)
|
532
|
+
|
533
|
+
params = {
|
534
|
+
"version" => @version
|
535
|
+
}
|
536
|
+
|
537
|
+
method_url = "/v1/models/categories"
|
538
|
+
|
539
|
+
response = request(
|
540
|
+
method: "GET",
|
541
|
+
url: method_url,
|
542
|
+
headers: headers,
|
543
|
+
params: params,
|
544
|
+
accept_json: true
|
545
|
+
)
|
546
|
+
response
|
547
|
+
end
|
548
|
+
|
549
|
+
##
|
550
|
+
# @!method get_categories_model(model_id:)
|
551
|
+
# Get categories model details.
|
552
|
+
# (Beta) Returns the status of the categories model with the given model ID.
|
553
|
+
# @param model_id [String] ID of the model.
|
554
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
555
|
+
def get_categories_model(model_id:)
|
556
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
557
|
+
|
558
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
559
|
+
|
560
|
+
headers = {
|
561
|
+
}
|
562
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_categories_model")
|
563
|
+
headers.merge!(sdk_headers)
|
564
|
+
|
565
|
+
params = {
|
566
|
+
"version" => @version
|
567
|
+
}
|
568
|
+
|
569
|
+
method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]
|
570
|
+
|
571
|
+
response = request(
|
572
|
+
method: "GET",
|
573
|
+
url: method_url,
|
574
|
+
headers: headers,
|
575
|
+
params: params,
|
576
|
+
accept_json: true
|
577
|
+
)
|
578
|
+
response
|
579
|
+
end
|
580
|
+
|
581
|
+
##
|
582
|
+
# @!method update_categories_model(model_id:, language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
583
|
+
# Update categories model.
|
584
|
+
# (Beta) Overwrites the training data associated with this custom categories model
|
585
|
+
# and retrains the model. The new model replaces the current deployment.
|
586
|
+
# @param model_id [String] ID of the model.
|
587
|
+
# @param language [String] The 2-letter language code of this model.
|
588
|
+
# @param training_data [File] Training data in JSON format. For more information, see [Categories training data
|
589
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-categories##categories-training-data-requirements).
|
590
|
+
# @param training_data_content_type [String] The content type of training_data.
|
591
|
+
# @param name [String] An optional name for the model.
|
592
|
+
# @param description [String] An optional description of the model.
|
593
|
+
# @param model_version [String] An optional version string.
|
594
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
595
|
+
# Language Understanding.
|
596
|
+
# @param version_description [String] The description of the version.
|
597
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
598
|
+
def update_categories_model(model_id:, language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
599
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
600
|
+
|
601
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
602
|
+
|
603
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
604
|
+
|
605
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
606
|
+
|
607
|
+
headers = {
|
608
|
+
}
|
609
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_categories_model")
|
610
|
+
headers.merge!(sdk_headers)
|
611
|
+
|
612
|
+
params = {
|
613
|
+
"version" => @version
|
614
|
+
}
|
615
|
+
|
616
|
+
form_data = {}
|
617
|
+
|
618
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
619
|
+
|
620
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
621
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
622
|
+
end
|
623
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: training_data_content_type.nil? ? "application/octet-stream" : training_data_content_type, filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
624
|
+
|
625
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
626
|
+
|
627
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
628
|
+
|
629
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
630
|
+
|
631
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
632
|
+
|
633
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
634
|
+
|
635
|
+
method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]
|
636
|
+
|
637
|
+
response = request(
|
638
|
+
method: "PUT",
|
639
|
+
url: method_url,
|
640
|
+
headers: headers,
|
641
|
+
params: params,
|
642
|
+
form: form_data,
|
643
|
+
accept_json: true
|
644
|
+
)
|
645
|
+
response
|
646
|
+
end
|
647
|
+
|
648
|
+
##
|
649
|
+
# @!method delete_categories_model(model_id:)
|
650
|
+
# Delete categories model.
|
651
|
+
# (Beta) Un-deploys the custom categories model with the given model ID and deletes
|
652
|
+
# all associated customer data, including any training data or binary artifacts.
|
653
|
+
# @param model_id [String] ID of the model.
|
654
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
655
|
+
def delete_categories_model(model_id:)
|
656
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
657
|
+
|
658
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
659
|
+
|
660
|
+
headers = {
|
661
|
+
}
|
662
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_categories_model")
|
663
|
+
headers.merge!(sdk_headers)
|
664
|
+
|
665
|
+
params = {
|
666
|
+
"version" => @version
|
667
|
+
}
|
668
|
+
|
669
|
+
method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]
|
670
|
+
|
671
|
+
response = request(
|
672
|
+
method: "DELETE",
|
673
|
+
url: method_url,
|
674
|
+
headers: headers,
|
675
|
+
params: params,
|
676
|
+
accept_json: true
|
677
|
+
)
|
678
|
+
response
|
679
|
+
end
|
680
|
+
#########################
|
681
|
+
# Manage classifications models
|
682
|
+
#########################
|
683
|
+
|
684
|
+
##
|
685
|
+
# @!method create_classifications_model(language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
686
|
+
# Create classifications model.
|
687
|
+
# (Beta) Creates a custom classifications model by uploading training data and
|
688
|
+
# associated metadata. The model begins the training and deploying process and is
|
689
|
+
# ready to use when the `status` is `available`.
|
690
|
+
# @param language [String] The 2-letter language code of this model.
|
691
|
+
# @param training_data [File] Training data in JSON format. For more information, see [Classifications training
|
692
|
+
# data
|
693
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-classifications#classification-training-data-requirements).
|
694
|
+
# @param training_data_content_type [String] The content type of training_data.
|
695
|
+
# @param name [String] An optional name for the model.
|
696
|
+
# @param description [String] An optional description of the model.
|
697
|
+
# @param model_version [String] An optional version string.
|
698
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
699
|
+
# Language Understanding.
|
700
|
+
# @param version_description [String] The description of the version.
|
701
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
702
|
+
def create_classifications_model(language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
703
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
704
|
+
|
705
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
706
|
+
|
707
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
708
|
+
|
709
|
+
headers = {
|
710
|
+
}
|
711
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_classifications_model")
|
712
|
+
headers.merge!(sdk_headers)
|
713
|
+
|
714
|
+
params = {
|
715
|
+
"version" => @version
|
716
|
+
}
|
717
|
+
|
718
|
+
form_data = {}
|
719
|
+
|
720
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
721
|
+
|
722
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
723
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
724
|
+
end
|
725
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: training_data_content_type.nil? ? "application/octet-stream" : training_data_content_type, filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
726
|
+
|
727
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
728
|
+
|
729
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
730
|
+
|
731
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
732
|
+
|
733
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
734
|
+
|
735
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
736
|
+
|
737
|
+
method_url = "/v1/models/classifications"
|
738
|
+
|
739
|
+
response = request(
|
740
|
+
method: "POST",
|
741
|
+
url: method_url,
|
742
|
+
headers: headers,
|
743
|
+
params: params,
|
744
|
+
form: form_data,
|
745
|
+
accept_json: true
|
746
|
+
)
|
747
|
+
response
|
748
|
+
end
|
749
|
+
|
750
|
+
##
|
751
|
+
# @!method list_classifications_models
|
752
|
+
# List classifications models.
|
753
|
+
# (Beta) Returns all custom classifications models associated with this service
|
754
|
+
# instance.
|
755
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
756
|
+
def list_classifications_models
|
757
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
758
|
+
|
759
|
+
headers = {
|
760
|
+
}
|
761
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_classifications_models")
|
762
|
+
headers.merge!(sdk_headers)
|
763
|
+
|
764
|
+
params = {
|
765
|
+
"version" => @version
|
766
|
+
}
|
767
|
+
|
768
|
+
method_url = "/v1/models/classifications"
|
769
|
+
|
770
|
+
response = request(
|
771
|
+
method: "GET",
|
772
|
+
url: method_url,
|
773
|
+
headers: headers,
|
774
|
+
params: params,
|
775
|
+
accept_json: true
|
776
|
+
)
|
777
|
+
response
|
778
|
+
end
|
779
|
+
|
780
|
+
##
|
781
|
+
# @!method get_classifications_model(model_id:)
|
782
|
+
# Get classifications model details.
|
783
|
+
# (Beta) Returns the status of the classifications model with the given model ID.
|
784
|
+
# @param model_id [String] ID of the model.
|
785
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
786
|
+
def get_classifications_model(model_id:)
|
787
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
788
|
+
|
789
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
790
|
+
|
791
|
+
headers = {
|
792
|
+
}
|
793
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_classifications_model")
|
794
|
+
headers.merge!(sdk_headers)
|
795
|
+
|
796
|
+
params = {
|
797
|
+
"version" => @version
|
798
|
+
}
|
799
|
+
|
800
|
+
method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]
|
801
|
+
|
802
|
+
response = request(
|
803
|
+
method: "GET",
|
804
|
+
url: method_url,
|
805
|
+
headers: headers,
|
806
|
+
params: params,
|
807
|
+
accept_json: true
|
808
|
+
)
|
809
|
+
response
|
810
|
+
end
|
811
|
+
|
812
|
+
##
|
813
|
+
# @!method update_classifications_model(model_id:, language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
814
|
+
# Update classifications model.
|
815
|
+
# (Beta) Overwrites the training data associated with this custom classifications
|
816
|
+
# model and retrains the model. The new model replaces the current deployment.
|
817
|
+
# @param model_id [String] ID of the model.
|
818
|
+
# @param language [String] The 2-letter language code of this model.
|
819
|
+
# @param training_data [File] Training data in JSON format. For more information, see [Classifications training
|
820
|
+
# data
|
821
|
+
# requirements](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-classifications#classification-training-data-requirements).
|
822
|
+
# @param training_data_content_type [String] The content type of training_data.
|
823
|
+
# @param name [String] An optional name for the model.
|
824
|
+
# @param description [String] An optional description of the model.
|
825
|
+
# @param model_version [String] An optional version string.
|
826
|
+
# @param workspace_id [String] ID of the Watson Knowledge Studio workspace that deployed this model to Natural
|
827
|
+
# Language Understanding.
|
828
|
+
# @param version_description [String] The description of the version.
|
829
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
830
|
+
def update_classifications_model(model_id:, language:, training_data:, training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
|
831
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
832
|
+
|
833
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
834
|
+
|
835
|
+
raise ArgumentError.new("language must be provided") if language.nil?
|
836
|
+
|
837
|
+
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
838
|
+
|
839
|
+
headers = {
|
840
|
+
}
|
841
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_classifications_model")
|
842
|
+
headers.merge!(sdk_headers)
|
843
|
+
|
844
|
+
params = {
|
845
|
+
"version" => @version
|
846
|
+
}
|
847
|
+
|
848
|
+
form_data = {}
|
849
|
+
|
850
|
+
form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")
|
851
|
+
|
852
|
+
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
853
|
+
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
854
|
+
end
|
855
|
+
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: training_data_content_type.nil? ? "application/octet-stream" : training_data_content_type, filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
856
|
+
|
857
|
+
form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?
|
858
|
+
|
859
|
+
form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?
|
860
|
+
|
861
|
+
form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?
|
862
|
+
|
863
|
+
form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?
|
864
|
+
|
865
|
+
form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?
|
866
|
+
|
867
|
+
method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]
|
868
|
+
|
869
|
+
response = request(
|
870
|
+
method: "PUT",
|
871
|
+
url: method_url,
|
872
|
+
headers: headers,
|
873
|
+
params: params,
|
874
|
+
form: form_data,
|
875
|
+
accept_json: true
|
876
|
+
)
|
877
|
+
response
|
878
|
+
end
|
879
|
+
|
880
|
+
##
|
881
|
+
# @!method delete_classifications_model(model_id:)
|
882
|
+
# Delete classifications model.
|
883
|
+
# (Beta) Un-deploys the custom classifications model with the given model ID and
|
884
|
+
# deletes all associated customer data, including any training data or binary
|
885
|
+
# artifacts.
|
886
|
+
# @param model_id [String] ID of the model.
|
887
|
+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
888
|
+
def delete_classifications_model(model_id:)
|
889
|
+
raise ArgumentError.new("version must be provided") if version.nil?
|
890
|
+
|
891
|
+
raise ArgumentError.new("model_id must be provided") if model_id.nil?
|
892
|
+
|
893
|
+
headers = {
|
894
|
+
}
|
895
|
+
sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_classifications_model")
|
896
|
+
headers.merge!(sdk_headers)
|
897
|
+
|
898
|
+
params = {
|
899
|
+
"version" => @version
|
900
|
+
}
|
901
|
+
|
902
|
+
method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]
|
903
|
+
|
213
904
|
response = request(
|
214
905
|
method: "DELETE",
|
215
906
|
url: method_url,
|