Class: IBMWatson::NaturalLanguageUnderstandingV1

Inherits:
IBMCloudSdkCore::BaseService
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/ibm_watson/natural_language_understanding_v1.rb

Overview

The Natural Language Understanding V1 service.

Constant Summary collapse

DEFAULT_SERVICE_NAME =
"natural_language_understanding"
DEFAULT_SERVICE_URL =
"https://api.us-south.natural-language-understanding.watson.cloud.ibm.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ NaturalLanguageUnderstandingV1

Construct a new client for the Natural Language Understanding service.

Parameters:

  • args (Hash)

    The args to initialize with

Options Hash (args):

  • version (String)

    Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is ‘2021-08-01`.

  • service_url (String)

    The base service URL to use when contacting the service. The base service_url may differ between IBM Cloud regions.

  • authenticator (Object)

    The Authenticator instance to be configured for this service.

  • service_name (String)

    The name of the service to configure. Will be used as the key to load any external configuration, if applicable.

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 55

def initialize(args = {})
  @__async_initialized__ = false
  defaults = {}
  defaults[:service_url] = DEFAULT_SERVICE_URL
  defaults[:service_name] = DEFAULT_SERVICE_NAME
  defaults[:authenticator] = nil
  defaults[:version] = nil
  user_service_url = args[:service_url] unless args[:service_url].nil?
  args = defaults.merge(args)
  @version = args[:version]
  raise ArgumentError.new("version must be provided") if @version.nil?

  args[:authenticator] = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: args[:service_name]) if args[:authenticator].nil?
  super
  @service_url = user_service_url unless user_service_url.nil?
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.



42
43
44
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 42

def version
  @version
end

Instance Method Details

#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) ⇒ IBMCloudSdkCore::DetailedResponse

Analyze text. Analyzes text, HTML, or a public webpage for the following features:

- Categories
- Classifications
- Concepts
- Emotion
- Entities
- Keywords
- Metadata
- Relations
- Semantic roles
- Sentiment
- Syntax
- Summarization (Experimental)

If a language for the input text is not specified with the `language` parameter,
the service [automatically detects the
language](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-detectable-languages).

Parameters:

  • features (Features) (defaults to: )

    Specific features to analyze the document for.

  • text (String) (defaults to: nil)

    The plain text to analyze. One of the ‘text`, `html`, or `url` parameters is required.

  • html (String) (defaults to: nil)

    The HTML file to analyze. One of the ‘text`, `html`, or `url` parameters is required.

  • url (String) (defaults to: nil)

    The webpage to analyze. One of the ‘text`, `html`, or `url` parameters is required.

  • clean (Boolean) (defaults to: nil)

    Set this to ‘false` to disable webpage cleaning. For more information about webpage cleaning, see [Analyzing webpages](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-analyzing-webpages).

  • xpath (String) (defaults to: nil)

    An [XPath query](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-analyzing-webpages#xpath) to perform on ‘html` or `url` input. Results of the query will be appended to the cleaned webpage text before it is analyzed. To analyze only the results of the XPath query, set the `clean` parameter to `false`.

  • fallback_to_raw (Boolean) (defaults to: nil)

    Whether to use raw HTML content if text cleaning fails.

  • return_analyzed_text (Boolean) (defaults to: nil)

    Whether or not to return the analyzed text.

  • language (String) (defaults to: nil)

    ISO 639-1 code that specifies the language of your text. This overrides automatic language detection. Language support differs depending on the features you include in your analysis. For more information, see [Language support](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-language-support).

  • limit_text_characters (Fixnum) (defaults to: nil)

    Sets the maximum number of characters that are processed by the service.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 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)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("features must be provided") if features.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "analyze")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  data = {
    "features" => features,
    "text" => text,
    "html" => html,
    "url" => url,
    "clean" => clean,
    "xpath" => xpath,
    "fallback_to_raw" => fallback_to_raw,
    "return_analyzed_text" => return_analyzed_text,
    "language" => language,
    "limit_text_characters" => limit_text_characters
  }

  method_url = "/v1/analyze"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    json: data,
    accept_json: true
  )
  response
end

#create_categories_model(language: , training_data: , training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Create categories model. (Beta) Creates a custom categories model by uploading training data and associated

metadata. The model begins the training and deploying process and is ready to use
when the `status` is `available`.

Parameters:

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in JSON format. For more information, see [Categories training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-categories##categories-training-data-requirements).

  • training_data_content_type (String) (defaults to: nil)

    The content type of training_data.

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 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)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_categories_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  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)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/categories"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end

#create_classifications_model(language: , training_data: , training_data_content_type: nil, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Create classifications model. Creates a custom classifications model by uploading training data and associated

metadata. The model begins the training and deploying process and is ready to use
when the `status` is `available`.

Parameters:

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in JSON format. For more information, see [Classifications training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-classifications#classification-training-data-requirements).

  • training_data_content_type (String) (defaults to: nil)

    The content type of training_data.

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 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)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_classifications_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  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)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/classifications"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end

#create_sentiment_model(language: , training_data: , name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Create sentiment model. (Beta) Creates a custom sentiment model by uploading training data and associated

metadata. The model begins the training and deploying process and is ready to use
when the `status` is `available`.

Parameters:

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in CSV format. For more information, see [Sentiment training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-custom-sentiment#sentiment-training-data-requirements).

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 244

def create_sentiment_model(language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "create_sentiment_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: "text/csv", filename: training_data.respond_to?(:path) ? training_data.path : nil)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/sentiment"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end

#delete_categories_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Delete categories model. (Beta) Un-deploys the custom categories model with the given model ID and deletes

all associated customer data, including any training data or binary artifacts.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 655

def delete_categories_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_categories_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#delete_classifications_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Delete classifications model. Un-deploys the custom classifications model with the given model ID and deletes

all associated customer data, including any training data or binary artifacts.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 886

def delete_classifications_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_classifications_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#delete_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Delete model. Deletes a custom model.

Parameters:

  • model_id (String) (defaults to: )

    Model ID of the model to delete.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 199

def delete_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#delete_sentiment_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Delete sentiment model. (Beta) Un-deploys the custom sentiment model with the given model ID and deletes

all associated customer data, including any training data or binary artifacts.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 426

def delete_sentiment_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "delete_sentiment_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#get_categories_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Get categories model details. (Beta) Returns the status of the categories model with the given model ID.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 555

def get_categories_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_categories_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#get_classifications_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Get classifications model details. Returns the status of the classifications model with the given model ID.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 785

def get_classifications_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_classifications_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#get_sentiment_model(model_id: ) ⇒ IBMCloudSdkCore::DetailedResponse

Get sentiment model details. (Beta) Returns the status of the sentiment model with the given model ID.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 327

def get_sentiment_model(model_id:)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "get_sentiment_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#list_categories_modelsIBMCloudSdkCore::DetailedResponse

List categories models. (Beta) Returns all custom categories models associated with this service instance.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 525

def list_categories_models
  raise ArgumentError.new("version must be provided") if version.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_categories_models")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/categories"

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#list_classifications_modelsIBMCloudSdkCore::DetailedResponse

List classifications models. Returns all custom classifications models associated with this service instance.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 755

def list_classifications_models
  raise ArgumentError.new("version must be provided") if version.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_classifications_models")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/classifications"

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#list_modelsIBMCloudSdkCore::DetailedResponse

List models. Lists Watson Knowledge Studio [custom entities and relations

models](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-customizing)
that are deployed to your Natural Language Understanding service.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 169

def list_models
  raise ArgumentError.new("version must be provided") if version.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_models")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models"

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#list_sentiment_modelsIBMCloudSdkCore::DetailedResponse

List sentiment models. (Beta) Returns all custom sentiment models associated with this service instance.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 297

def list_sentiment_models
  raise ArgumentError.new("version must be provided") if version.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "list_sentiment_models")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  method_url = "/v1/models/sentiment"

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#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) ⇒ IBMCloudSdkCore::DetailedResponse

Update categories model. (Beta) Overwrites the training data associated with this custom categories model

and retrains the model. The new model replaces the current deployment.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in JSON format. For more information, see [Categories training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-categories##categories-training-data-requirements).

  • training_data_content_type (String) (defaults to: nil)

    The content type of training_data.

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 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)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_categories_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  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)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/categories/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "PUT",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end

#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) ⇒ IBMCloudSdkCore::DetailedResponse

Update classifications model. Overwrites the training data associated with this custom classifications model and

retrains the model. The new model replaces the current deployment.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in JSON format. For more information, see [Classifications training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-classifications#classification-training-data-requirements).

  • training_data_content_type (String) (defaults to: nil)

    The content type of training_data.

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 829

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)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_classifications_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  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)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/classifications/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "PUT",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end

#update_sentiment_model(model_id: , language: , training_data: , name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Update sentiment model. (Beta) Overwrites the training data associated with this custom sentiment model

and retrains the model. The new model replaces the current deployment.

Parameters:

  • model_id (String) (defaults to: )

    ID of the model.

  • language (String) (defaults to: )

    The 2-letter language code of this model.

  • training_data (File) (defaults to: )

    Training data in CSV format. For more information, see [Sentiment training data requirements](cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-custom-sentiment#sentiment-training-data-requirements).

  • name (String) (defaults to: nil)

    An optional name for the model.

  • description (String) (defaults to: nil)

    An optional description of the model.

  • model_version (String) (defaults to: nil)

    An optional version string.

  • workspace_id (String) (defaults to: nil)

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

  • version_description (String) (defaults to: nil)

    The description of the version.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/ibm_watson/natural_language_understanding_v1.rb', line 369

def update_sentiment_model(model_id:, language:, training_data:, name: nil, description: nil, model_version: nil, workspace_id: nil, version_description: nil)
  raise ArgumentError.new("version must be provided") if version.nil?

  raise ArgumentError.new("model_id must be provided") if model_id.nil?

  raise ArgumentError.new("language must be provided") if language.nil?

  raise ArgumentError.new("training_data must be provided") if training_data.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("natural-language-understanding", "V1", "update_sentiment_model")
  headers.merge!(sdk_headers)

  params = {
    "version" => @version
  }

  form_data = {}

  form_data[:language] = HTTP::FormData::Part.new(language.to_s, content_type: "text/plain")

  unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
    training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
  end
  form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: "text/csv", filename: training_data.respond_to?(:path) ? training_data.path : nil)

  form_data[:name] = HTTP::FormData::Part.new(name.to_s, content_type: "text/plain") unless name.nil?

  form_data[:description] = HTTP::FormData::Part.new(description.to_s, content_type: "text/plain") unless description.nil?

  form_data[:model_version] = HTTP::FormData::Part.new(model_version.to_s, content_type: "text/plain") unless model_version.nil?

  form_data[:workspace_id] = HTTP::FormData::Part.new(workspace_id.to_s, content_type: "text/plain") unless workspace_id.nil?

  form_data[:version_description] = HTTP::FormData::Part.new(version_description.to_s, content_type: "text/plain") unless version_description.nil?

  method_url = "/v1/models/sentiment/%s" % [ERB::Util.url_encode(model_id)]

  response = request(
    method: "PUT",
    url: method_url,
    headers: headers,
    params: params,
    form: form_data,
    accept_json: true
  )
  response
end