ibm_watson 2.0.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -29
- data/lib/ibm_watson/assistant_v1.rb +114 -79
- data/lib/ibm_watson/assistant_v2.rb +83 -59
- data/lib/ibm_watson/compare_comply_v1.rb +11 -4
- data/lib/ibm_watson/discovery_v1.rb +5 -12
- data/lib/ibm_watson/discovery_v2.rb +201 -110
- data/lib/ibm_watson/language_translator_v3.rb +1 -2
- data/lib/ibm_watson/natural_language_classifier_v1.rb +14 -6
- data/lib/ibm_watson/natural_language_understanding_v1.rb +690 -3
- data/lib/ibm_watson/personality_insights_v3.rb +13 -11
- data/lib/ibm_watson/speech_to_text_v1.rb +582 -333
- data/lib/ibm_watson/text_to_speech_v1.rb +617 -35
- data/lib/ibm_watson/tone_analyzer_v3.rb +1 -2
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +1 -2
- data/lib/ibm_watson/visual_recognition_v4.rb +11 -8
- data/test/integration/test_discovery_v2.rb +15 -0
- data/test/integration/test_natural_language_understanding_v1.rb +134 -1
- data/test/integration/test_text_to_speech_v1.rb +57 -0
- data/test/unit/test_discovery_v2.rb +29 -0
- data/test/unit/test_natural_language_understanding_v1.rb +231 -0
- data/test/unit/test_text_to_speech_v1.rb +145 -0
- metadata +3 -3
@@ -14,7 +14,7 @@
|
|
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.
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.38.0-07189efd-20210827-205025
|
18
18
|
#
|
19
19
|
# The IBM Watson™ Tone Analyzer service uses linguistic analysis to detect
|
20
20
|
# emotional and language tones in written text. The service can analyze tone at both the
|
@@ -34,7 +34,6 @@ require "json"
|
|
34
34
|
require "ibm_cloud_sdk_core"
|
35
35
|
require_relative "./common.rb"
|
36
36
|
|
37
|
-
# Module for the Watson APIs
|
38
37
|
module IBMWatson
|
39
38
|
##
|
40
39
|
# The Tone Analyzer V3 service.
|
data/lib/ibm_watson/version.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
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.
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.38.0-07189efd-20210827-205025
|
18
18
|
#
|
19
19
|
# IBM Watson™ Visual Recognition is discontinued. Existing instances are supported
|
20
20
|
# until 1 December 2021, but as of 7 January 2021, you can't create instances. Any
|
@@ -31,7 +31,6 @@ require "json"
|
|
31
31
|
require "ibm_cloud_sdk_core"
|
32
32
|
require_relative "./common.rb"
|
33
33
|
|
34
|
-
# Module for the Watson APIs
|
35
34
|
module IBMWatson
|
36
35
|
##
|
37
36
|
# The Visual Recognition V3 service.
|
@@ -14,7 +14,7 @@
|
|
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.
|
17
|
+
# IBM OpenAPI SDK Code Generator Version: 3.38.0-07189efd-20210827-205025
|
18
18
|
#
|
19
19
|
# IBM Watson™ Visual Recognition is discontinued. Existing instances are supported
|
20
20
|
# until 1 December 2021, but as of 7 January 2021, you can't create instances. Any
|
@@ -30,7 +30,6 @@ require "json"
|
|
30
30
|
require "ibm_cloud_sdk_core"
|
31
31
|
require_relative "./common.rb"
|
32
32
|
|
33
|
-
# Module for the Watson APIs
|
34
33
|
module IBMWatson
|
35
34
|
##
|
36
35
|
# The Visual Recognition V4 service.
|
@@ -159,7 +158,7 @@ module IBMWatson
|
|
159
158
|
#########################
|
160
159
|
|
161
160
|
##
|
162
|
-
# @!method create_collection(name: nil, description: nil)
|
161
|
+
# @!method create_collection(name: nil, description: nil, training_status: nil)
|
163
162
|
# Create a collection.
|
164
163
|
# Create a collection that can be used to store images.
|
165
164
|
#
|
@@ -171,8 +170,9 @@ module IBMWatson
|
|
171
170
|
# @param name [String] The name of the collection. The name can contain alphanumeric, underscore, hyphen,
|
172
171
|
# and dot characters. It cannot begin with the reserved prefix `sys-`.
|
173
172
|
# @param description [String] The description of the collection.
|
173
|
+
# @param training_status [TrainingStatus] Training status information for the collection.
|
174
174
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
175
|
-
def create_collection(name: nil, description: nil)
|
175
|
+
def create_collection(name: nil, description: nil, training_status: nil)
|
176
176
|
raise ArgumentError.new("version must be provided") if version.nil?
|
177
177
|
|
178
178
|
headers = {
|
@@ -186,7 +186,8 @@ module IBMWatson
|
|
186
186
|
|
187
187
|
data = {
|
188
188
|
"name" => name,
|
189
|
-
"description" => description
|
189
|
+
"description" => description,
|
190
|
+
"training_status" => training_status
|
190
191
|
}
|
191
192
|
|
192
193
|
method_url = "/v4/collections"
|
@@ -264,7 +265,7 @@ module IBMWatson
|
|
264
265
|
end
|
265
266
|
|
266
267
|
##
|
267
|
-
# @!method update_collection(collection_id:, name: nil, description: nil)
|
268
|
+
# @!method update_collection(collection_id:, name: nil, description: nil, training_status: nil)
|
268
269
|
# Update a collection.
|
269
270
|
# Update the name or description of a collection.
|
270
271
|
#
|
@@ -274,8 +275,9 @@ module IBMWatson
|
|
274
275
|
# @param name [String] The name of the collection. The name can contain alphanumeric, underscore, hyphen,
|
275
276
|
# and dot characters. It cannot begin with the reserved prefix `sys-`.
|
276
277
|
# @param description [String] The description of the collection.
|
278
|
+
# @param training_status [TrainingStatus] Training status information for the collection.
|
277
279
|
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
278
|
-
def update_collection(collection_id:, name: nil, description: nil)
|
280
|
+
def update_collection(collection_id:, name: nil, description: nil, training_status: nil)
|
279
281
|
raise ArgumentError.new("version must be provided") if version.nil?
|
280
282
|
|
281
283
|
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
|
@@ -291,7 +293,8 @@ module IBMWatson
|
|
291
293
|
|
292
294
|
data = {
|
293
295
|
"name" => name,
|
294
|
-
"description" => description
|
296
|
+
"description" => description,
|
297
|
+
"training_status" => training_status
|
295
298
|
}
|
296
299
|
|
297
300
|
method_url = "/v4/collections/%s" % [ERB::Util.url_encode(collection_id)]
|
@@ -120,6 +120,7 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
|
|
120
120
|
)
|
121
121
|
query_id = service_response.result["query_id"]
|
122
122
|
refute(service_response.nil?)
|
123
|
+
# puts JSON.pretty_generate(service_response.result)
|
123
124
|
|
124
125
|
service_response = service.get_training_query(
|
125
126
|
project_id: @project_id,
|
@@ -134,6 +135,12 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
|
|
134
135
|
examples: []
|
135
136
|
)
|
136
137
|
refute(service_response.nil?)
|
138
|
+
|
139
|
+
service_response = service.delete_training_query(
|
140
|
+
project_id: @project_id,
|
141
|
+
query_id: query_id
|
142
|
+
)
|
143
|
+
assert(service_response.nil?)
|
137
144
|
end
|
138
145
|
|
139
146
|
def test_create_get_update_delete_collection
|
@@ -238,6 +245,14 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
|
|
238
245
|
assert(service_response.nil?)
|
239
246
|
end
|
240
247
|
|
248
|
+
def test_query_collection_notices
|
249
|
+
service_response = service.query_collection_notices(
|
250
|
+
project_id: @project_id,
|
251
|
+
collection_id: @collection_id
|
252
|
+
)
|
253
|
+
refute(service_response.result.nil?)
|
254
|
+
end
|
255
|
+
|
241
256
|
def test_delete_user_data
|
242
257
|
skip "Covered with the unit test. No need to run it here"
|
243
258
|
|
@@ -86,7 +86,7 @@ if !ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"].nil? && !ENV["NATURAL_LANGUAGE_
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_list_models
|
89
|
-
skip
|
89
|
+
# skip
|
90
90
|
service.add_default_headers(
|
91
91
|
headers: {
|
92
92
|
"X-Watson-Learning-Opt-Out" => "1",
|
@@ -96,6 +96,139 @@ if !ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"].nil? && !ENV["NATURAL_LANGUAGE_
|
|
96
96
|
service_response = service.list_models
|
97
97
|
assert((200..299).cover?(service_response.status))
|
98
98
|
end
|
99
|
+
|
100
|
+
def test_check_orphands
|
101
|
+
skip "Use to help delete old models"
|
102
|
+
service.add_default_headers(
|
103
|
+
headers: {
|
104
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
105
|
+
"X-Watson-Test" => "1"
|
106
|
+
}
|
107
|
+
)
|
108
|
+
service_response = service.list_sentiment_models
|
109
|
+
puts JSON.pretty_generate(service_response.result)
|
110
|
+
service_response = service.list_categories_models
|
111
|
+
puts JSON.pretty_generate(service_response.result)
|
112
|
+
service_response = service.list_classifications_models
|
113
|
+
puts JSON.pretty_generate(service_response.result)
|
114
|
+
|
115
|
+
# service.delete_sentiment_model(model_id: "model_id1")
|
116
|
+
# service.delete_categories_model(model_id: "0122b971-94c9-4468-a98f-930f4ce28c32")
|
117
|
+
# service.delete_classifications_model(model_id: "0122b971-94c9-4468-a98f-930f4ce28c32")
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_sentiment_models
|
121
|
+
# skip "test_sentiment_models"
|
122
|
+
service.add_default_headers(
|
123
|
+
headers: {
|
124
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
125
|
+
"X-Watson-Test" => "1"
|
126
|
+
}
|
127
|
+
)
|
128
|
+
training_data = File.open(Dir.getwd + "/resources/nlu_sentiment_data.csv")
|
129
|
+
service_response = service.create_sentiment_model(
|
130
|
+
language: "en",
|
131
|
+
training_data: training_data
|
132
|
+
)
|
133
|
+
assert((200..299).cover?(service_response.status))
|
134
|
+
|
135
|
+
service_response = service.list_sentiment_models
|
136
|
+
model_id = service_response.result["models"][0]["model_id"]
|
137
|
+
assert((200..299).cover?(service_response.status))
|
138
|
+
|
139
|
+
service_response = service.get_sentiment_model(model_id: model_id)
|
140
|
+
assert((200..299).cover?(service_response.status))
|
141
|
+
|
142
|
+
service_response = service.update_sentiment_model(
|
143
|
+
model_id: model_id,
|
144
|
+
language: "en",
|
145
|
+
training_data: training_data
|
146
|
+
)
|
147
|
+
assert((200..299).cover?(service_response.status))
|
148
|
+
|
149
|
+
service_response = service.delete_sentiment_model(
|
150
|
+
model_id: model_id
|
151
|
+
)
|
152
|
+
assert((200..299).cover?(service_response.status))
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_categories_models
|
156
|
+
# skip "test_categories_models"
|
157
|
+
service.add_default_headers(
|
158
|
+
headers: {
|
159
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
160
|
+
"X-Watson-Test" => "1"
|
161
|
+
}
|
162
|
+
)
|
163
|
+
training_data = File.open(Dir.getwd + "/resources/nlu_categories_training.json")
|
164
|
+
service_response = service.create_categories_model(
|
165
|
+
language: "en",
|
166
|
+
training_data: training_data,
|
167
|
+
training_data_content_type: "application/json"
|
168
|
+
)
|
169
|
+
assert((200..299).cover?(service_response.status))
|
170
|
+
|
171
|
+
service_response = service.list_categories_models
|
172
|
+
model_id = service_response.result["models"][0]["model_id"]
|
173
|
+
assert((200..299).cover?(service_response.status))
|
174
|
+
# puts JSON.pretty_generate(service_response.result)
|
175
|
+
# puts JSON.pretty_generate(model_id)
|
176
|
+
|
177
|
+
service_response = service.get_categories_model(model_id: model_id)
|
178
|
+
assert((200..299).cover?(service_response.status))
|
179
|
+
|
180
|
+
service_response = service.update_categories_model(
|
181
|
+
model_id: model_id,
|
182
|
+
language: "en",
|
183
|
+
training_data: training_data,
|
184
|
+
training_data_content_type: "application/json"
|
185
|
+
)
|
186
|
+
assert((200..299).cover?(service_response.status))
|
187
|
+
|
188
|
+
service_response = service.delete_categories_model(
|
189
|
+
model_id: model_id
|
190
|
+
)
|
191
|
+
assert((200..299).cover?(service_response.status))
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_classifications_models
|
195
|
+
# skip "test_classifications_models"
|
196
|
+
service.add_default_headers(
|
197
|
+
headers: {
|
198
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
199
|
+
"X-Watson-Test" => "1"
|
200
|
+
}
|
201
|
+
)
|
202
|
+
training_data = File.open(Dir.getwd + "/resources/nlu_classifications_training.json")
|
203
|
+
service_response = service.create_classifications_model(
|
204
|
+
language: "en",
|
205
|
+
training_data: training_data,
|
206
|
+
training_data_content_type: "application/json"
|
207
|
+
)
|
208
|
+
assert((200..299).cover?(service_response.status))
|
209
|
+
|
210
|
+
service_response = service.list_classifications_models
|
211
|
+
model_id = service_response.result["models"][0]["model_id"]
|
212
|
+
assert((200..299).cover?(service_response.status))
|
213
|
+
# puts JSON.pretty_generate(service_response.result)
|
214
|
+
# puts JSON.pretty_generate(model_id)
|
215
|
+
|
216
|
+
service_response = service.get_classifications_model(model_id: model_id)
|
217
|
+
assert((200..299).cover?(service_response.status))
|
218
|
+
|
219
|
+
service_response = service.update_classifications_model(
|
220
|
+
model_id: model_id,
|
221
|
+
language: "en",
|
222
|
+
training_data: training_data,
|
223
|
+
training_data_content_type: "application/json"
|
224
|
+
)
|
225
|
+
assert((200..299).cover?(service_response.status))
|
226
|
+
|
227
|
+
service_response = service.delete_classifications_model(
|
228
|
+
model_id: model_id
|
229
|
+
)
|
230
|
+
assert((200..299).cover?(service_response.status))
|
231
|
+
end
|
99
232
|
end
|
100
233
|
else
|
101
234
|
class NaturalLanguageUnderstandingV1Test < Minitest::Test
|
@@ -83,6 +83,63 @@ if !ENV["TEXT_TO_SPEECH_APIKEY"].nil? && !ENV["TEXT_TO_SPEECH_URL"].nil?
|
|
83
83
|
customization_id: customization_id
|
84
84
|
)
|
85
85
|
end
|
86
|
+
|
87
|
+
def test_custom_prompts
|
88
|
+
customization_id = @service.create_custom_model(
|
89
|
+
name: "test_integration_customization",
|
90
|
+
description: "RUBY customization for tests"
|
91
|
+
).result["customization_id"]
|
92
|
+
|
93
|
+
prompt_metadata = { prompt_text: "Thank you and goodbye" }
|
94
|
+
prompt_json = JSON[prompt_metadata]
|
95
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
96
|
+
prompt = @service.add_custom_prompt(
|
97
|
+
customization_id: customization_id,
|
98
|
+
prompt_id: "rubyprompt_id",
|
99
|
+
metadata: prompt_json,
|
100
|
+
file: audio_file
|
101
|
+
).result["prompt"]
|
102
|
+
assert(prompt == "Thank you and goodbye")
|
103
|
+
|
104
|
+
prompts = @service.list_custom_prompts(customization_id: customization_id).result["prompts"]
|
105
|
+
refute(prompts.nil?)
|
106
|
+
|
107
|
+
prompt = @service.get_custom_prompt(
|
108
|
+
customization_id: customization_id,
|
109
|
+
prompt_id: "rubyprompt_id"
|
110
|
+
).result["prompt"]
|
111
|
+
assert(prompt == "Thank you and goodbye")
|
112
|
+
|
113
|
+
@service.delete_custom_prompt(
|
114
|
+
customization_id: customization_id,
|
115
|
+
prompt_id: "rubyprompt_id"
|
116
|
+
)
|
117
|
+
|
118
|
+
@service.delete_custom_model(
|
119
|
+
customization_id: customization_id
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_speaker_models
|
124
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
125
|
+
@service.create_speaker_model(
|
126
|
+
speaker_name: "RubyMike",
|
127
|
+
audio: audio_file
|
128
|
+
).result["speaker_model"]
|
129
|
+
|
130
|
+
speakers = @service.list_speaker_models.result["speakers"]
|
131
|
+
speaker_id = speakers[0]["speaker_id"]
|
132
|
+
# puts JSON.pretty_generate(speakers)
|
133
|
+
|
134
|
+
@service.get_speaker_model(
|
135
|
+
speaker_id: speaker_id
|
136
|
+
).result["models_speaker"]
|
137
|
+
|
138
|
+
# speaker_id = d3d03b69-4035-4420-928d-7ac2e0249829
|
139
|
+
@service.delete_speaker_model(
|
140
|
+
speaker_id: speaker_id
|
141
|
+
)
|
142
|
+
end
|
86
143
|
end
|
87
144
|
else
|
88
145
|
class TextToSpeechV1Test < Minitest::Test
|
@@ -467,4 +467,33 @@ class DiscoveryV2Test < Minitest::Test
|
|
467
467
|
)
|
468
468
|
assert_nil(service_response)
|
469
469
|
end
|
470
|
+
|
471
|
+
def test_delete_training_query
|
472
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
|
473
|
+
.with(
|
474
|
+
headers: {
|
475
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
476
|
+
}
|
477
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
478
|
+
service_response = service.delete_training_query(
|
479
|
+
project_id: "project",
|
480
|
+
query_id: "queryid"
|
481
|
+
)
|
482
|
+
assert_nil(service_response)
|
483
|
+
end
|
484
|
+
|
485
|
+
def test_query_collection_notices
|
486
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collection/notices?version=2018-03-05")
|
487
|
+
.with(
|
488
|
+
headers: {
|
489
|
+
"Accept" => "application/json",
|
490
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
491
|
+
}
|
492
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
493
|
+
service_response = service.query_collection_notices(
|
494
|
+
project_id: "project",
|
495
|
+
collection_id: "collection"
|
496
|
+
)
|
497
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
498
|
+
end
|
470
499
|
end
|
@@ -144,4 +144,235 @@ class NaturalLanguageUnderstandingV1Test < Minitest::Test
|
|
144
144
|
)
|
145
145
|
assert_equal({ "deleted" => model_id }, service_response.result)
|
146
146
|
end
|
147
|
+
|
148
|
+
def test_sentiment_models
|
149
|
+
authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
|
150
|
+
username: "username",
|
151
|
+
password: "password"
|
152
|
+
)
|
153
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
154
|
+
version: "2018-03-16",
|
155
|
+
authenticator: authenticator
|
156
|
+
)
|
157
|
+
|
158
|
+
stub_request(:post, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/sentiment?version=2018-03-16")
|
159
|
+
.with(
|
160
|
+
headers: {
|
161
|
+
"Accept" => "application/json",
|
162
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
163
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
164
|
+
}
|
165
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
166
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
167
|
+
service_response = service.create_sentiment_model(
|
168
|
+
language: "en",
|
169
|
+
training_data: training_data
|
170
|
+
)
|
171
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
172
|
+
|
173
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/sentiment?version=2018-03-16")
|
174
|
+
.with(
|
175
|
+
headers: {
|
176
|
+
"Accept" => "application/json",
|
177
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
178
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
179
|
+
}
|
180
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
181
|
+
service_response = service.list_sentiment_models
|
182
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
183
|
+
|
184
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/sentiment/model_id?version=2018-03-16")
|
185
|
+
.with(
|
186
|
+
headers: {
|
187
|
+
"Accept" => "application/json",
|
188
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
189
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
190
|
+
}
|
191
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
192
|
+
service_response = service.get_sentiment_model(model_id: "model_id")
|
193
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
194
|
+
|
195
|
+
stub_request(:put, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/sentiment/model_id?version=2018-03-16")
|
196
|
+
.with(
|
197
|
+
headers: {
|
198
|
+
"Accept" => "application/json",
|
199
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
200
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
201
|
+
}
|
202
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
203
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
204
|
+
service_response = service.update_sentiment_model(
|
205
|
+
model_id: "model_id",
|
206
|
+
language: "en",
|
207
|
+
training_data: training_data
|
208
|
+
)
|
209
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
210
|
+
|
211
|
+
stub_request(:delete, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/sentiment/model_id?version=2018-03-16")
|
212
|
+
.with(
|
213
|
+
headers: {
|
214
|
+
"Accept" => "application/json",
|
215
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
216
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
217
|
+
}
|
218
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
219
|
+
service_response = service.delete_sentiment_model(
|
220
|
+
model_id: "model_id"
|
221
|
+
)
|
222
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_categories_models
|
226
|
+
authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
|
227
|
+
username: "username",
|
228
|
+
password: "password"
|
229
|
+
)
|
230
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
231
|
+
version: "2018-03-16",
|
232
|
+
authenticator: authenticator
|
233
|
+
)
|
234
|
+
|
235
|
+
stub_request(:post, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/categories?version=2018-03-16")
|
236
|
+
.with(
|
237
|
+
headers: {
|
238
|
+
"Accept" => "application/json",
|
239
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
240
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
241
|
+
}
|
242
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
243
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
244
|
+
service_response = service.create_categories_model(
|
245
|
+
language: "en",
|
246
|
+
training_data: training_data
|
247
|
+
)
|
248
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
249
|
+
|
250
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/categories?version=2018-03-16")
|
251
|
+
.with(
|
252
|
+
headers: {
|
253
|
+
"Accept" => "application/json",
|
254
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
255
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
256
|
+
}
|
257
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
258
|
+
service_response = service.list_categories_models
|
259
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
260
|
+
|
261
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/categories/model_id?version=2018-03-16")
|
262
|
+
.with(
|
263
|
+
headers: {
|
264
|
+
"Accept" => "application/json",
|
265
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
266
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
267
|
+
}
|
268
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
269
|
+
service_response = service.get_categories_model(model_id: "model_id")
|
270
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
271
|
+
|
272
|
+
stub_request(:put, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/categories/model_id?version=2018-03-16")
|
273
|
+
.with(
|
274
|
+
headers: {
|
275
|
+
"Accept" => "application/json",
|
276
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
277
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
278
|
+
}
|
279
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
280
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
281
|
+
service_response = service.update_categories_model(
|
282
|
+
model_id: "model_id",
|
283
|
+
language: "en",
|
284
|
+
training_data: training_data
|
285
|
+
)
|
286
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
287
|
+
|
288
|
+
stub_request(:delete, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/categories/model_id?version=2018-03-16")
|
289
|
+
.with(
|
290
|
+
headers: {
|
291
|
+
"Accept" => "application/json",
|
292
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
293
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
294
|
+
}
|
295
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
296
|
+
service_response = service.delete_categories_model(
|
297
|
+
model_id: "model_id"
|
298
|
+
)
|
299
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_classifications_models
|
303
|
+
authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
|
304
|
+
username: "username",
|
305
|
+
password: "password"
|
306
|
+
)
|
307
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
308
|
+
version: "2018-03-16",
|
309
|
+
authenticator: authenticator
|
310
|
+
)
|
311
|
+
|
312
|
+
stub_request(:post, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/classifications?version=2018-03-16")
|
313
|
+
.with(
|
314
|
+
headers: {
|
315
|
+
"Accept" => "application/json",
|
316
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
317
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
318
|
+
}
|
319
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
320
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
321
|
+
service_response = service.create_classifications_model(
|
322
|
+
language: "en",
|
323
|
+
training_data: training_data
|
324
|
+
)
|
325
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
326
|
+
|
327
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/classifications?version=2018-03-16")
|
328
|
+
.with(
|
329
|
+
headers: {
|
330
|
+
"Accept" => "application/json",
|
331
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
332
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
333
|
+
}
|
334
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
335
|
+
service_response = service.list_classifications_models
|
336
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
337
|
+
|
338
|
+
stub_request(:get, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/classifications/model_id?version=2018-03-16")
|
339
|
+
.with(
|
340
|
+
headers: {
|
341
|
+
"Accept" => "application/json",
|
342
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
343
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
344
|
+
}
|
345
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
346
|
+
service_response = service.get_classifications_model(model_id: "model_id")
|
347
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
348
|
+
|
349
|
+
stub_request(:put, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/classifications/model_id?version=2018-03-16")
|
350
|
+
.with(
|
351
|
+
headers: {
|
352
|
+
"Accept" => "application/json",
|
353
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
354
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
355
|
+
}
|
356
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
357
|
+
training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
|
358
|
+
service_response = service.update_classifications_model(
|
359
|
+
model_id: "model_id",
|
360
|
+
language: "en",
|
361
|
+
training_data: training_data
|
362
|
+
)
|
363
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
364
|
+
|
365
|
+
stub_request(:delete, "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/v1/models/classifications/model_id?version=2018-03-16")
|
366
|
+
.with(
|
367
|
+
headers: {
|
368
|
+
"Accept" => "application/json",
|
369
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
370
|
+
"Host" => "api.us-south.natural-language-understanding.watson.cloud.ibm.com"
|
371
|
+
}
|
372
|
+
).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
|
373
|
+
service_response = service.delete_classifications_model(
|
374
|
+
model_id: "model_id"
|
375
|
+
)
|
376
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
377
|
+
end
|
147
378
|
end
|