ibm_watson 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +258 -0
  3. data/bin/console +14 -0
  4. data/bin/setup +8 -0
  5. data/lib/ibm_watson.rb +16 -0
  6. data/lib/ibm_watson/assistant_v1.rb +1997 -0
  7. data/lib/ibm_watson/detailed_response.rb +21 -0
  8. data/lib/ibm_watson/discovery_v1.rb +2039 -0
  9. data/lib/ibm_watson/iam_token_manager.rb +166 -0
  10. data/lib/ibm_watson/language_translator_v3.rb +411 -0
  11. data/lib/ibm_watson/natural_language_classifier_v1.rb +309 -0
  12. data/lib/ibm_watson/natural_language_understanding_v1.rb +297 -0
  13. data/lib/ibm_watson/personality_insights_v3.rb +260 -0
  14. data/lib/ibm_watson/speech_to_text_v1.rb +2153 -0
  15. data/lib/ibm_watson/text_to_speech_v1.rb +716 -0
  16. data/lib/ibm_watson/tone_analyzer_v3.rb +287 -0
  17. data/lib/ibm_watson/version.rb +3 -0
  18. data/lib/ibm_watson/visual_recognition_v3.rb +579 -0
  19. data/lib/ibm_watson/watson_api_exception.rb +41 -0
  20. data/lib/ibm_watson/watson_service.rb +180 -0
  21. data/lib/ibm_watson/websocket/recognize_callback.rb +32 -0
  22. data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +162 -0
  23. data/rakefile +45 -0
  24. data/test/integration/test_assistant_v1.rb +645 -0
  25. data/test/integration/test_discovery_v1.rb +200 -0
  26. data/test/integration/test_iam_assistant_v1.rb +707 -0
  27. data/test/integration/test_language_translator_v3.rb +81 -0
  28. data/test/integration/test_natural_language_classifier_v1.rb +69 -0
  29. data/test/integration/test_natural_language_understanding_v1.rb +98 -0
  30. data/test/integration/test_personality_insights_v3.rb +95 -0
  31. data/test/integration/test_speech_to_text_v1.rb +187 -0
  32. data/test/integration/test_text_to_speech_v1.rb +81 -0
  33. data/test/integration/test_tone_analyzer_v3.rb +72 -0
  34. data/test/integration/test_visual_recognition_v3.rb +64 -0
  35. data/test/test_helper.rb +22 -0
  36. data/test/unit/test_assistant_v1.rb +1598 -0
  37. data/test/unit/test_discovery_v1.rb +1144 -0
  38. data/test/unit/test_iam_token_manager.rb +165 -0
  39. data/test/unit/test_language_translator_v3.rb +461 -0
  40. data/test/unit/test_natural_language_classifier_v1.rb +187 -0
  41. data/test/unit/test_natural_language_understanding_v1.rb +132 -0
  42. data/test/unit/test_personality_insights_v3.rb +172 -0
  43. data/test/unit/test_speech_to_text_v1.rb +755 -0
  44. data/test/unit/test_text_to_speech_v1.rb +336 -0
  45. data/test/unit/test_tone_analyzer_v3.rb +200 -0
  46. data/test/unit/test_vcap_using_personality_insights.rb +150 -0
  47. data/test/unit/test_visual_recognition_v3.rb +345 -0
  48. metadata +302 -0
@@ -0,0 +1,309 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 IBM All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # IBM Watson™ Natural Language Classifier uses machine learning algorithms to
18
+ # return the top matching predefined classes for short text input. You create and train a
19
+ # classifier to connect predefined classes to example texts so that the service can apply
20
+ # those classes to new inputs.
21
+
22
+ require "concurrent"
23
+ require "erb"
24
+ require "json"
25
+ require_relative "./detailed_response"
26
+
27
+ require_relative "./watson_service"
28
+
29
+ module IBMWatson
30
+ ##
31
+ # The Natural Language Classifier V1 service.
32
+ class NaturalLanguageClassifierV1
33
+ include Concurrent::Async
34
+ ##
35
+ # @!method initialize(args)
36
+ # Construct a new client for the Natural Language Classifier service.
37
+ #
38
+ # @param args [Hash] The args to initialize with
39
+ # @option args url [String] The base url to use when contacting the service (e.g.
40
+ # "https://gateway.watsonplatform.net/natural-language-classifier/api").
41
+ # The base url may differ between Bluemix regions.
42
+ # @option args username [String] The username used to authenticate with the service.
43
+ # Username and password credentials are only required to run your
44
+ # application locally or outside of Bluemix. When running on
45
+ # Bluemix, the credentials will be automatically loaded from the
46
+ # `VCAP_SERVICES` environment variable.
47
+ # @option args password [String] The password used to authenticate with the service.
48
+ # Username and password credentials are only required to run your
49
+ # application locally or outside of Bluemix. When running on
50
+ # Bluemix, the credentials will be automatically loaded from the
51
+ # `VCAP_SERVICES` environment variable.
52
+ # @option args iam_api_key [String] An API key that can be used to request IAM tokens. If
53
+ # this API key is provided, the SDK will manage the token and handle the
54
+ # refreshing.
55
+ # @option args iam_access_token [String] An IAM access token is fully managed by the application.
56
+ # Responsibility falls on the application to refresh the token, either before
57
+ # it expires or reactively upon receiving a 401 from the service as any requests
58
+ # made with an expired token will fail.
59
+ # @option args iam_url [String] An optional URL for the IAM service API. Defaults to
60
+ # 'https://iam.ng.bluemix.net/identity/token'.
61
+ def initialize(args = {})
62
+ @__async_initialized__ = false
63
+ super()
64
+ defaults = {}
65
+ defaults[:url] = "https://gateway.watsonplatform.net/natural-language-classifier/api"
66
+ defaults[:username] = nil
67
+ defaults[:password] = nil
68
+ defaults[:iam_api_key] = nil
69
+ defaults[:iam_access_token] = nil
70
+ defaults[:iam_url] = nil
71
+ args = defaults.merge(args)
72
+ @watson_service = WatsonService.new(
73
+ vcap_services_name: "natural_language_classifier",
74
+ url: args[:url],
75
+ username: args[:username],
76
+ password: args[:password],
77
+ iam_api_key: args[:iam_api_key],
78
+ iam_access_token: args[:iam_access_token],
79
+ iam_url: args[:iam_url],
80
+ use_vcap_services: true
81
+ )
82
+ end
83
+
84
+ # :nocov:
85
+ def add_default_headers(headers: {})
86
+ @watson_service.add_default_headers(headers: headers)
87
+ end
88
+
89
+ def _iam_access_token(iam_access_token:)
90
+ @watson_service._iam_access_token(iam_access_token: iam_access_token)
91
+ end
92
+
93
+ def _iam_api_key(iam_api_key:)
94
+ @watson_service._iam_api_key(iam_api_key: iam_api_key)
95
+ end
96
+
97
+ # @return [DetailedResponse]
98
+ def request(args)
99
+ @watson_service.request(args)
100
+ end
101
+
102
+ # @note Chainable
103
+ # @param headers [Hash] Custom headers to be sent with the request
104
+ # @return [self]
105
+ def headers(headers)
106
+ @watson_service.headers(headers)
107
+ self
108
+ end
109
+
110
+ def password=(password)
111
+ @watson_service.password = password
112
+ end
113
+
114
+ def password
115
+ @watson_service.password
116
+ end
117
+
118
+ def username=(username)
119
+ @watson_service.username = username
120
+ end
121
+
122
+ def username
123
+ @watson_service.username
124
+ end
125
+
126
+ def url=(url)
127
+ @watson_service.url = url
128
+ end
129
+
130
+ def url
131
+ @watson_service.url
132
+ end
133
+ # :nocov:
134
+ #########################
135
+ # Classify text
136
+ #########################
137
+
138
+ ##
139
+ # @!method classify(classifier_id:, text:)
140
+ # Classify a phrase.
141
+ # Returns label information for the input. The status must be `Available` before you
142
+ # can use the classifier to classify text.
143
+ # @param classifier_id [String] Classifier ID to use.
144
+ # @param text [String] The submitted phrase.
145
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
146
+ def classify(classifier_id:, text:)
147
+ raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
148
+ raise ArgumentError("text must be provided") if text.nil?
149
+ headers = {
150
+ }
151
+ data = {
152
+ "text" => text
153
+ }
154
+ method_url = "/v1/classifiers/%s/classify" % [ERB::Util.url_encode(classifier_id)]
155
+ response = request(
156
+ method: "POST",
157
+ url: method_url,
158
+ headers: headers,
159
+ json: data,
160
+ accept_json: true
161
+ )
162
+ response
163
+ end
164
+
165
+ ##
166
+ # @!method classify_collection(classifier_id:, collection:)
167
+ # Classify multiple phrases.
168
+ # Returns label information for multiple phrases. The status must be `Available`
169
+ # before you can use the classifier to classify text.
170
+ #
171
+ # Note that classifying Japanese texts is a beta feature.
172
+ # @param classifier_id [String] Classifier ID to use.
173
+ # @param collection [Array[ClassifyInput]] The submitted phrases.
174
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
175
+ def classify_collection(classifier_id:, collection:)
176
+ raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
177
+ raise ArgumentError("collection must be provided") if collection.nil?
178
+ headers = {
179
+ }
180
+ data = {
181
+ "collection" => collection
182
+ }
183
+ method_url = "/v1/classifiers/%s/classify_collection" % [ERB::Util.url_encode(classifier_id)]
184
+ response = request(
185
+ method: "POST",
186
+ url: method_url,
187
+ headers: headers,
188
+ json: data,
189
+ accept_json: true
190
+ )
191
+ response
192
+ end
193
+ #########################
194
+ # Manage classifiers
195
+ #########################
196
+
197
+ ##
198
+ # @!method create_classifier(metadata:, training_data:, metadata_filename: nil, training_data_filename: nil)
199
+ # Create classifier.
200
+ # Sends data to create and train a classifier and returns information about the new
201
+ # classifier.
202
+ # @param metadata [File] Metadata in JSON format. The metadata identifies the language of the data, and an
203
+ # optional name to identify the classifier. Specify the language with the 2-letter
204
+ # primary language code as assigned in ISO standard 639.
205
+ #
206
+ # Supported languages are English (`en`), Arabic (`ar`), French (`fr`), German,
207
+ # (`de`), Italian (`it`), Japanese (`ja`), Korean (`ko`), Brazilian Portuguese
208
+ # (`pt`), and Spanish (`es`).
209
+ # @param training_data [File] Training data in CSV format. Each text value must have at least one class. The
210
+ # data can include up to 20,000 records. For details, see [Data
211
+ # preparation](https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html).
212
+ # @param metadata_filename [String] The filename for training_metadata.
213
+ # @param training_data_filename [String] The filename for training_data.
214
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
215
+ def create_classifier(metadata:, training_data:, metadata_filename: nil, training_data_filename: nil)
216
+ raise ArgumentError("metadata must be provided") if metadata.nil?
217
+ raise ArgumentError("training_data must be provided") if training_data.nil?
218
+ headers = {
219
+ }
220
+ mime_type = "application/json"
221
+ unless metadata.instance_of?(StringIO) || metadata.instance_of?(File)
222
+ metadata = metadata.respond_to?(:to_json) ? StringIO.new(metadata.to_json) : StringIO.new(metadata)
223
+ end
224
+ if metadata_filename
225
+ metadata = metadata.instance_of?(StringIO) ? HTTP::FormData::File.new(metadata, content_type: mime_type, filename: metadata_filename) : HTTP::FormData::File.new(metadata.path, content_type: mime_type, filename: metadata_filename)
226
+ else
227
+ metadata = metadata.instance_of?(StringIO) ? HTTP::FormData::File.new(metadata, content_type: mime_type) : HTTP::FormData::File.new(metadata.path, content_type: mime_type)
228
+ end
229
+ mime_type = "text/csv"
230
+ unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
231
+ training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
232
+ end
233
+ if training_data_filename
234
+ training_data = training_data.instance_of?(StringIO) ? HTTP::FormData::File.new(training_data, content_type: mime_type, filename: training_data_filename) : HTTP::FormData::File.new(training_data.path, content_type: mime_type, filename: training_data_filename)
235
+ else
236
+ training_data = training_data.instance_of?(StringIO) ? HTTP::FormData::File.new(training_data, content_type: mime_type) : HTTP::FormData::File.new(training_data.path, content_type: mime_type)
237
+ end
238
+ method_url = "/v1/classifiers"
239
+ response = request(
240
+ method: "POST",
241
+ url: method_url,
242
+ headers: headers,
243
+ form: {
244
+ training_metadata: metadata,
245
+ training_data: training_data
246
+ },
247
+ accept_json: true
248
+ )
249
+ response
250
+ end
251
+
252
+ ##
253
+ # @!method list_classifiers
254
+ # List classifiers.
255
+ # Returns an empty array if no classifiers are available.
256
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
257
+ def list_classifiers
258
+ headers = {
259
+ }
260
+ method_url = "/v1/classifiers"
261
+ response = request(
262
+ method: "GET",
263
+ url: method_url,
264
+ headers: headers,
265
+ accept_json: true
266
+ )
267
+ response
268
+ end
269
+
270
+ ##
271
+ # @!method get_classifier(classifier_id:)
272
+ # Get information about a classifier.
273
+ # Returns status and other information about a classifier.
274
+ # @param classifier_id [String] Classifier ID to query.
275
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
276
+ def get_classifier(classifier_id:)
277
+ raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
278
+ headers = {
279
+ }
280
+ method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
281
+ response = request(
282
+ method: "GET",
283
+ url: method_url,
284
+ headers: headers,
285
+ accept_json: true
286
+ )
287
+ response
288
+ end
289
+
290
+ ##
291
+ # @!method delete_classifier(classifier_id:)
292
+ # Delete classifier.
293
+ # @param classifier_id [String] Classifier ID to delete.
294
+ # @return [nil]
295
+ def delete_classifier(classifier_id:)
296
+ raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
297
+ headers = {
298
+ }
299
+ method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
300
+ request(
301
+ method: "DELETE",
302
+ url: method_url,
303
+ headers: headers,
304
+ accept_json: true
305
+ )
306
+ nil
307
+ end
308
+ end
309
+ end
@@ -0,0 +1,297 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 IBM All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Analyze various features of text content at scale. Provide text, raw HTML, or a public
18
+ # URL, and IBM Watson Natural Language Understanding will give you results for the
19
+ # features you request. The service cleans HTML content before analysis by default, so the
20
+ # results can ignore most advertisements and other unwanted content.
21
+ #
22
+ # You can create <a target="_blank"
23
+ # href="https://www.ibm.com/watson/developercloud/doc/natural-language-understanding/customizing.html">custom
24
+ # models</a> with Watson Knowledge Studio that can be used to detect custom entities and
25
+ # relations in Natural Language Understanding.
26
+
27
+ require "concurrent"
28
+ require "erb"
29
+ require "json"
30
+ require_relative "./detailed_response"
31
+
32
+ require_relative "./watson_service"
33
+
34
+ module IBMWatson
35
+ ##
36
+ # The Natural Language Understanding V1 service.
37
+ class NaturalLanguageUnderstandingV1
38
+ include Concurrent::Async
39
+ ##
40
+ # @!method initialize(args)
41
+ # Construct a new client for the Natural Language Understanding service.
42
+ #
43
+ # @param args [Hash] The args to initialize with
44
+ # @option args version [String] The API version date to use with the service, in
45
+ # "YYYY-MM-DD" format. Whenever the API is changed in a backwards
46
+ # incompatible way, a new minor version of the API is released.
47
+ # The service uses the API version for the date you specify, or
48
+ # the most recent version before that date. Note that you should
49
+ # not programmatically specify the current date at runtime, in
50
+ # case the API has been updated since your application's release.
51
+ # Instead, specify a version date that is compatible with your
52
+ # application, and don't change it until your application is
53
+ # ready for a later version.
54
+ # @option args url [String] The base url to use when contacting the service (e.g.
55
+ # "https://gateway.watsonplatform.net/natural-language-understanding/api").
56
+ # The base url may differ between Bluemix regions.
57
+ # @option args username [String] The username used to authenticate with the service.
58
+ # Username and password credentials are only required to run your
59
+ # application locally or outside of Bluemix. When running on
60
+ # Bluemix, the credentials will be automatically loaded from the
61
+ # `VCAP_SERVICES` environment variable.
62
+ # @option args password [String] The password used to authenticate with the service.
63
+ # Username and password credentials are only required to run your
64
+ # application locally or outside of Bluemix. When running on
65
+ # Bluemix, the credentials will be automatically loaded from the
66
+ # `VCAP_SERVICES` environment variable.
67
+ # @option args iam_api_key [String] An API key that can be used to request IAM tokens. If
68
+ # this API key is provided, the SDK will manage the token and handle the
69
+ # refreshing.
70
+ # @option args iam_access_token [String] An IAM access token is fully managed by the application.
71
+ # Responsibility falls on the application to refresh the token, either before
72
+ # it expires or reactively upon receiving a 401 from the service as any requests
73
+ # made with an expired token will fail.
74
+ # @option args iam_url [String] An optional URL for the IAM service API. Defaults to
75
+ # 'https://iam.ng.bluemix.net/identity/token'.
76
+ def initialize(args = {})
77
+ @__async_initialized__ = false
78
+ super()
79
+ defaults = {}
80
+ defaults[:version] = nil
81
+ defaults[:url] = "https://gateway.watsonplatform.net/natural-language-understanding/api"
82
+ defaults[:username] = nil
83
+ defaults[:password] = nil
84
+ defaults[:iam_api_key] = nil
85
+ defaults[:iam_access_token] = nil
86
+ defaults[:iam_url] = nil
87
+ args = defaults.merge(args)
88
+ @watson_service = WatsonService.new(
89
+ vcap_services_name: "natural-language-understanding",
90
+ url: args[:url],
91
+ username: args[:username],
92
+ password: args[:password],
93
+ iam_api_key: args[:iam_api_key],
94
+ iam_access_token: args[:iam_access_token],
95
+ iam_url: args[:iam_url],
96
+ use_vcap_services: true
97
+ )
98
+ @version = args[:version]
99
+ end
100
+
101
+ # :nocov:
102
+ def add_default_headers(headers: {})
103
+ @watson_service.add_default_headers(headers: headers)
104
+ end
105
+
106
+ def _iam_access_token(iam_access_token:)
107
+ @watson_service._iam_access_token(iam_access_token: iam_access_token)
108
+ end
109
+
110
+ def _iam_api_key(iam_api_key:)
111
+ @watson_service._iam_api_key(iam_api_key: iam_api_key)
112
+ end
113
+
114
+ # @return [DetailedResponse]
115
+ def request(args)
116
+ @watson_service.request(args)
117
+ end
118
+
119
+ # @note Chainable
120
+ # @param headers [Hash] Custom headers to be sent with the request
121
+ # @return [self]
122
+ def headers(headers)
123
+ @watson_service.headers(headers)
124
+ self
125
+ end
126
+
127
+ def password=(password)
128
+ @watson_service.password = password
129
+ end
130
+
131
+ def password
132
+ @watson_service.password
133
+ end
134
+
135
+ def username=(username)
136
+ @watson_service.username = username
137
+ end
138
+
139
+ def username
140
+ @watson_service.username
141
+ end
142
+
143
+ def url=(url)
144
+ @watson_service.url = url
145
+ end
146
+
147
+ def url
148
+ @watson_service.url
149
+ end
150
+ # :nocov:
151
+ #########################
152
+ # Analyze
153
+ #########################
154
+
155
+ ##
156
+ # @!method 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)
157
+ # Analyze text, HTML, or a public webpage.
158
+ # Analyzes text, HTML, or a public webpage with one or more text analysis features.
159
+ #
160
+ # ### Concepts
161
+ # Identify general concepts that are referenced or alluded to in your content.
162
+ # Concepts that are detected typically have an associated link to a DBpedia
163
+ # resource.
164
+ #
165
+ # ### Emotion
166
+ # Detect anger, disgust, fear, joy, or sadness that is conveyed by your content.
167
+ # Emotion information can be returned for detected entities, keywords, or
168
+ # user-specified target phrases found in the text.
169
+ #
170
+ # ### Entities
171
+ # Detect important people, places, geopolitical entities and other types of entities
172
+ # in your content. Entity detection recognizes consecutive coreferences of each
173
+ # entity. For example, analysis of the following text would count \"Barack Obama\"
174
+ # and \"He\" as the same entity:
175
+ #
176
+ # \"Barack Obama was the 44th President of the United States. He took office in
177
+ # January 2009.\"
178
+ #
179
+ # ### Keywords
180
+ # Determine the most important keywords in your content. Keyword phrases are
181
+ # organized by relevance in the results.
182
+ #
183
+ # ### Metadata
184
+ # Get author information, publication date, and the title of your text/HTML content.
185
+ #
186
+ # ### Relations
187
+ # Recognize when two entities are related, and identify the type of relation. For
188
+ # example, you can identify an \"awardedTo\" relation between an award and its
189
+ # recipient.
190
+ #
191
+ # ### Semantic Roles
192
+ # Parse sentences into subject-action-object form, and identify entities and
193
+ # keywords that are subjects or objects of an action.
194
+ #
195
+ # ### Sentiment
196
+ # Determine whether your content conveys postive or negative sentiment. Sentiment
197
+ # information can be returned for detected entities, keywords, or user-specified
198
+ # target phrases found in the text.
199
+ #
200
+ # ### Categories
201
+ # Categorize your content into a hierarchical 5-level taxonomy. For example,
202
+ # \"Leonardo DiCaprio won an Oscar\" returns \"/art and entertainment/movies and
203
+ # tv/movies\" as the most confident classification.
204
+ # @param features [Features] Specific features to analyze the document for.
205
+ # @param text [String] The plain text to analyze.
206
+ # @param html [String] The HTML file to analyze.
207
+ # @param url [String] The web page to analyze.
208
+ # @param clean [Boolean] Remove website elements, such as links, ads, etc.
209
+ # @param xpath [String] XPath query for targeting nodes in HTML.
210
+ # @param fallback_to_raw [Boolean] Whether to use raw HTML content if text cleaning fails.
211
+ # @param return_analyzed_text [Boolean] Whether or not to return the analyzed text.
212
+ # @param language [String] ISO 639-1 code indicating the language to use in the analysis.
213
+ # @param limit_text_characters [Fixnum] Sets the maximum number of characters that are processed by the service.
214
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
215
+ 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)
216
+ raise ArgumentError("features must be provided") if features.nil?
217
+ headers = {
218
+ }
219
+ params = {
220
+ "version" => @version
221
+ }
222
+ data = {
223
+ "features" => features,
224
+ "text" => text,
225
+ "html" => html,
226
+ "url" => url,
227
+ "clean" => clean,
228
+ "xpath" => xpath,
229
+ "fallback_to_raw" => fallback_to_raw,
230
+ "return_analyzed_text" => return_analyzed_text,
231
+ "language" => language,
232
+ "limit_text_characters" => limit_text_characters
233
+ }
234
+ method_url = "/v1/analyze"
235
+ response = request(
236
+ method: "POST",
237
+ url: method_url,
238
+ headers: headers,
239
+ params: params,
240
+ json: data,
241
+ accept_json: true
242
+ )
243
+ response
244
+ end
245
+ #########################
246
+ # Manage models
247
+ #########################
248
+
249
+ ##
250
+ # @!method list_models
251
+ # List models.
252
+ # Lists available models for Relations and Entities features, including Watson
253
+ # Knowledge Studio custom models that you have created and linked to your Natural
254
+ # Language Understanding service.
255
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
256
+ def list_models
257
+ headers = {
258
+ }
259
+ params = {
260
+ "version" => @version
261
+ }
262
+ method_url = "/v1/models"
263
+ response = request(
264
+ method: "GET",
265
+ url: method_url,
266
+ headers: headers,
267
+ params: params,
268
+ accept_json: true
269
+ )
270
+ response
271
+ end
272
+
273
+ ##
274
+ # @!method delete_model(model_id:)
275
+ # Delete model.
276
+ # Deletes a custom model.
277
+ # @param model_id [String] model_id of the model to delete.
278
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
279
+ def delete_model(model_id:)
280
+ raise ArgumentError("model_id must be provided") if model_id.nil?
281
+ headers = {
282
+ }
283
+ params = {
284
+ "version" => @version
285
+ }
286
+ method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)]
287
+ response = request(
288
+ method: "DELETE",
289
+ url: method_url,
290
+ headers: headers,
291
+ params: params,
292
+ accept_json: true
293
+ )
294
+ response
295
+ end
296
+ end
297
+ end