ibm_watson 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ibm_watson.rb +1 -0
- data/lib/ibm_watson/assistant_v1.rb +282 -123
- data/lib/ibm_watson/assistant_v2.rb +16 -6
- data/lib/ibm_watson/compare_comply_v1.rb +653 -0
- data/lib/ibm_watson/discovery_v1.rb +322 -138
- data/lib/ibm_watson/language_translator_v3.rb +41 -30
- data/lib/ibm_watson/natural_language_classifier_v1.rb +32 -25
- data/lib/ibm_watson/natural_language_understanding_v1.rb +38 -17
- data/lib/ibm_watson/personality_insights_v3.rb +54 -36
- data/lib/ibm_watson/speech_to_text_v1.rb +247 -161
- data/lib/ibm_watson/text_to_speech_v1.rb +149 -41
- data/lib/ibm_watson/tone_analyzer_v3.rb +15 -9
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +113 -90
- data/test/integration/test_compare_comply_v1.rb +112 -0
- data/test/integration/test_personality_insights_v3.rb +3 -0
- data/test/integration/test_visual_recognition_v3.rb +1 -1
- data/test/unit/test_compare_comply_v1.rb +289 -0
- data/test/unit/test_personality_insights_v3.rb +4 -0
- data/test/unit/test_vcap_using_personality_insights.rb +3 -0
- data/test/unit/test_visual_recognition_v3.rb +6 -6
- metadata +5 -2
@@ -20,6 +20,7 @@ if !ENV["PERSONALITY_INSIGHTS_USERNAME"].nil? && !ENV["PERSONALITY_INSIGHTS_PASS
|
|
20
20
|
}
|
21
21
|
)
|
22
22
|
service_response = service.profile(
|
23
|
+
accept: "application/json",
|
23
24
|
content: personality_text,
|
24
25
|
content_type: "text/plain;charset=utf-8"
|
25
26
|
)
|
@@ -40,6 +41,7 @@ if !ENV["PERSONALITY_INSIGHTS_USERNAME"].nil? && !ENV["PERSONALITY_INSIGHTS_PASS
|
|
40
41
|
}
|
41
42
|
)
|
42
43
|
service_response = service.profile(
|
44
|
+
accept: "application/json",
|
43
45
|
content: personality_text,
|
44
46
|
content_type: "application/json",
|
45
47
|
raw_scores: true,
|
@@ -86,6 +88,7 @@ if !ENV["PERSONALITY_INSIGHTS_USERNAME"].nil? && !ENV["PERSONALITY_INSIGHTS_PASS
|
|
86
88
|
}
|
87
89
|
)
|
88
90
|
service_response = service.profile(
|
91
|
+
accept: "application/json",
|
89
92
|
content: personality_text,
|
90
93
|
content_type: "text/plain;charset=utf-8",
|
91
94
|
content_language: "es",
|
@@ -47,7 +47,7 @@ if !ENV["VISUAL_RECOGNITION_IAM_APIKEY"].nil? && !ENV["VISUAL_RECOGNITION_IAM_UR
|
|
47
47
|
trucks = File.open(Dir.getwd + "/resources/trucks.zip")
|
48
48
|
classifier = @service.create_classifier(
|
49
49
|
name: "CarsVsTrucks",
|
50
|
-
|
50
|
+
positive_examples: { cars: cars },
|
51
51
|
negative_examples: trucks
|
52
52
|
).result
|
53
53
|
refute(classifier.nil?)
|
@@ -0,0 +1,289 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require("json")
|
4
|
+
require_relative("./../test_helper.rb")
|
5
|
+
require("webmock/minitest")
|
6
|
+
SimpleCov.command_name "test:unit"
|
7
|
+
|
8
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
9
|
+
|
10
|
+
# Unit tests for the Watson Assistant V1 Service
|
11
|
+
class CompareComplyV1 < Minitest::Test
|
12
|
+
def test_convert_to_html
|
13
|
+
# service.set_default_headers("x-watson-learning-opt-out" => true)
|
14
|
+
service = IBMWatson::CompareComplyV1.new(
|
15
|
+
iam_apikey: "apikey",
|
16
|
+
iam_access_token: "token"
|
17
|
+
)
|
18
|
+
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
19
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/html_conversion").with do |req|
|
20
|
+
# Test the headers.
|
21
|
+
assert_equal(req.headers["Accept"], "application/json")
|
22
|
+
assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
|
23
|
+
end
|
24
|
+
service.convert_to_html(
|
25
|
+
file: file
|
26
|
+
)
|
27
|
+
service.convert_to_html(
|
28
|
+
file: "dummy",
|
29
|
+
filename: "file"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_classify_elements
|
34
|
+
# service.set_default_headers("x-watson-learning-opt-out" => true)
|
35
|
+
service = IBMWatson::CompareComplyV1.new(
|
36
|
+
iam_apikey: "apikey",
|
37
|
+
iam_access_token: "token"
|
38
|
+
)
|
39
|
+
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
40
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/element_classification").with do |req|
|
41
|
+
assert_equal(req.headers["Accept"], "application/json")
|
42
|
+
assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
|
43
|
+
assert_match(/Content-Disposition: form-data/, req.body)
|
44
|
+
end
|
45
|
+
service.classify_elements(
|
46
|
+
file: file
|
47
|
+
)
|
48
|
+
service.classify_elements(
|
49
|
+
file: "dummy",
|
50
|
+
filename: "file"
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_extract_tables
|
55
|
+
# service.set_default_headers("x-watson-learning-opt-out" => true)
|
56
|
+
service = IBMWatson::CompareComplyV1.new(
|
57
|
+
iam_apikey: "apikey",
|
58
|
+
iam_access_token: "token"
|
59
|
+
)
|
60
|
+
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
61
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/tables").with do |req|
|
62
|
+
assert_equal(req.headers["Accept"], "application/json")
|
63
|
+
assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
|
64
|
+
assert_match(/Content-Disposition: form-data/, req.body)
|
65
|
+
end
|
66
|
+
service.extract_tables(
|
67
|
+
file: file
|
68
|
+
)
|
69
|
+
service.extract_tables(
|
70
|
+
file: "dummy",
|
71
|
+
filename: "file"
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_compare_documents
|
76
|
+
# service.set_default_headers("x-watson-learning-opt-out" => true)
|
77
|
+
service = IBMWatson::CompareComplyV1.new(
|
78
|
+
iam_apikey: "apikey",
|
79
|
+
iam_access_token: "token"
|
80
|
+
)
|
81
|
+
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
82
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/comparison").with do |req|
|
83
|
+
assert_equal(req.headers["Accept"], "application/json")
|
84
|
+
assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
|
85
|
+
assert_match(/Content-Disposition: form-data/, req.body)
|
86
|
+
end
|
87
|
+
service.compare_documents(
|
88
|
+
file_1: file,
|
89
|
+
file_2: file
|
90
|
+
)
|
91
|
+
service.compare_documents(
|
92
|
+
file_1: "dummy data",
|
93
|
+
file_1_filename: "file1",
|
94
|
+
file_2: "dummy data",
|
95
|
+
file_2_filename: "file1"
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_list_feedback
|
100
|
+
service = IBMWatson::CompareComplyV1.new(
|
101
|
+
iam_apikey: "apikey",
|
102
|
+
iam_access_token: "token"
|
103
|
+
)
|
104
|
+
message_response = {
|
105
|
+
"feedback" => [
|
106
|
+
{
|
107
|
+
"feedback_id" => "another_one",
|
108
|
+
"text" => "we the best music"
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}
|
112
|
+
headers = {
|
113
|
+
"Content-Type" => "application/json"
|
114
|
+
}
|
115
|
+
stub_request(:get, "https://gateway.watsonplatform.net/compare-comply/api/v1/feedback")
|
116
|
+
.with(
|
117
|
+
headers: {
|
118
|
+
"Accept" => "application/json",
|
119
|
+
"Authorization" => "Bearer token",
|
120
|
+
"Host" => "gateway.watsonplatform.net"
|
121
|
+
}
|
122
|
+
).to_return(status: 200, body: message_response.to_json, headers: headers)
|
123
|
+
|
124
|
+
service_response = service.list_feedback
|
125
|
+
assert_equal(message_response, service_response.result)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_add_feedback
|
129
|
+
service = IBMWatson::CompareComplyV1.new(
|
130
|
+
iam_apikey: "apikey",
|
131
|
+
iam_access_token: "token"
|
132
|
+
)
|
133
|
+
message_response = {
|
134
|
+
"feedback_id" => "another_one"
|
135
|
+
}
|
136
|
+
headers = {
|
137
|
+
"Content-Type" => "application/json"
|
138
|
+
}
|
139
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/feedback")
|
140
|
+
.with(
|
141
|
+
headers: {
|
142
|
+
"Accept" => "application/json",
|
143
|
+
"Authorization" => "Bearer token",
|
144
|
+
"Host" => "gateway.watsonplatform.net"
|
145
|
+
}
|
146
|
+
).to_return(status: 200, body: message_response.to_json, headers: headers)
|
147
|
+
|
148
|
+
service_response = service.add_feedback(
|
149
|
+
feedback_data: "we the best music"
|
150
|
+
)
|
151
|
+
assert_equal(message_response, service_response.result)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_get_feedback
|
155
|
+
service = IBMWatson::CompareComplyV1.new(
|
156
|
+
iam_apikey: "apikey",
|
157
|
+
iam_access_token: "token"
|
158
|
+
)
|
159
|
+
message_response = {
|
160
|
+
"feedback_id" => "messi"
|
161
|
+
}
|
162
|
+
headers = {
|
163
|
+
"Content-Type" => "application/json"
|
164
|
+
}
|
165
|
+
stub_request(:get, "https://gateway.watsonplatform.net/compare-comply/api/v1/feedback/messi")
|
166
|
+
.with(
|
167
|
+
headers: {
|
168
|
+
"Accept" => "application/json",
|
169
|
+
"Authorization" => "Bearer token",
|
170
|
+
"Host" => "gateway.watsonplatform.net"
|
171
|
+
}
|
172
|
+
).to_return(status: 200, body: message_response.to_json, headers: headers)
|
173
|
+
|
174
|
+
service_response = service.get_feedback(
|
175
|
+
feedback_id: "messi"
|
176
|
+
)
|
177
|
+
assert_equal(message_response, service_response.result)
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_delete_feedback
|
181
|
+
service = IBMWatson::CompareComplyV1.new(
|
182
|
+
iam_apikey: "apikey",
|
183
|
+
iam_access_token: "token"
|
184
|
+
)
|
185
|
+
message_response = "200"
|
186
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/compare-comply/api/v1/feedback/messi")
|
187
|
+
.with(
|
188
|
+
headers: {
|
189
|
+
"Accept" => "application/json",
|
190
|
+
"Authorization" => "Bearer token",
|
191
|
+
"Host" => "gateway.watsonplatform.net"
|
192
|
+
}
|
193
|
+
).to_return(status: 200, body: message_response, headers: {})
|
194
|
+
|
195
|
+
service_response = service.delete_feedback(
|
196
|
+
feedback_id: "messi"
|
197
|
+
)
|
198
|
+
assert_equal(message_response, service_response.result)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_create_batch
|
202
|
+
service = IBMWatson::CompareComplyV1.new(
|
203
|
+
iam_apikey: "apikey",
|
204
|
+
iam_access_token: "token"
|
205
|
+
)
|
206
|
+
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/batches?function=tables")
|
207
|
+
.with do |req|
|
208
|
+
assert_equal req.headers["Accept"], "application/json"
|
209
|
+
assert_match %r{\Amultipart/form-data}, req.headers["Content-Type"]
|
210
|
+
end
|
211
|
+
|
212
|
+
service.create_batch(
|
213
|
+
function: "tables",
|
214
|
+
input_credentials_file: { key: "ip" },
|
215
|
+
input_bucket_location: "us",
|
216
|
+
input_bucket_name: "bucket",
|
217
|
+
output_credentials_file: { key: "op" },
|
218
|
+
output_bucket_location: "you",
|
219
|
+
output_bucket_name: "obucket"
|
220
|
+
)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_list_batches
|
224
|
+
service = IBMWatson::CompareComplyV1.new(
|
225
|
+
iam_apikey: "apikey",
|
226
|
+
iam_access_token: "token"
|
227
|
+
)
|
228
|
+
message_response = {
|
229
|
+
"batches" => []
|
230
|
+
}
|
231
|
+
headers = {
|
232
|
+
"Content-Type" => "application/json"
|
233
|
+
}
|
234
|
+
stub_request(:get, "https://gateway.watsonplatform.net/compare-comply/api/v1/batches")
|
235
|
+
.with(
|
236
|
+
headers: {
|
237
|
+
"Accept" => "application/json",
|
238
|
+
"Authorization" => "Bearer token",
|
239
|
+
"Host" => "gateway.watsonplatform.net"
|
240
|
+
}
|
241
|
+
).to_return(status: 200, body: message_response.to_json, headers: headers)
|
242
|
+
|
243
|
+
service_response = service.list_batches
|
244
|
+
assert_equal(message_response, service_response.result)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_get_batch
|
248
|
+
service = IBMWatson::CompareComplyV1.new(
|
249
|
+
iam_apikey: "apikey",
|
250
|
+
iam_access_token: "token"
|
251
|
+
)
|
252
|
+
message_response = "200"
|
253
|
+
stub_request(:get, "https://gateway.watsonplatform.net/compare-comply/api/v1/batches/mo")
|
254
|
+
.with(
|
255
|
+
headers: {
|
256
|
+
"Accept" => "application/json",
|
257
|
+
"Authorization" => "Bearer token",
|
258
|
+
"Host" => "gateway.watsonplatform.net"
|
259
|
+
}
|
260
|
+
).to_return(status: 200, body: message_response, headers: {})
|
261
|
+
|
262
|
+
service_response = service.get_batch(
|
263
|
+
batch_id: "mo"
|
264
|
+
)
|
265
|
+
assert_equal(message_response, service_response.result)
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_update_batch
|
269
|
+
service = IBMWatson::CompareComplyV1.new(
|
270
|
+
iam_apikey: "apikey",
|
271
|
+
iam_access_token: "token"
|
272
|
+
)
|
273
|
+
message_response = "200"
|
274
|
+
stub_request(:put, "https://gateway.watsonplatform.net/compare-comply/api/v1/batches/mo?action=goal")
|
275
|
+
.with(
|
276
|
+
headers: {
|
277
|
+
"Accept" => "application/json",
|
278
|
+
"Authorization" => "Bearer token",
|
279
|
+
"Host" => "gateway.watsonplatform.net"
|
280
|
+
}
|
281
|
+
).to_return(status: 200, body: message_response, headers: {})
|
282
|
+
|
283
|
+
service_response = service.update_batch(
|
284
|
+
batch_id: "mo",
|
285
|
+
action: "goal"
|
286
|
+
)
|
287
|
+
assert_equal(message_response, service_response.result)
|
288
|
+
end
|
289
|
+
end
|
@@ -31,6 +31,7 @@ class PersonalityInsightsV3Test < Minitest::Test
|
|
31
31
|
password: "password"
|
32
32
|
)
|
33
33
|
service_response = service.profile(
|
34
|
+
accept: "application/json",
|
34
35
|
content: personality_text,
|
35
36
|
content_type: "text/plain;charset=utf-8"
|
36
37
|
)
|
@@ -52,6 +53,7 @@ class PersonalityInsightsV3Test < Minitest::Test
|
|
52
53
|
}
|
53
54
|
).to_return(status: 200, body: { "profile" => "response" }.to_json, headers: headers)
|
54
55
|
service_response = service.profile(
|
56
|
+
accept: "application/json",
|
55
57
|
content: { "personality" => "text" },
|
56
58
|
content_type: "application/json"
|
57
59
|
)
|
@@ -81,6 +83,7 @@ class PersonalityInsightsV3Test < Minitest::Test
|
|
81
83
|
password: "password"
|
82
84
|
)
|
83
85
|
service_response = service.profile(
|
86
|
+
accept: "application/json",
|
84
87
|
content: personality_text,
|
85
88
|
content_type: "application/json",
|
86
89
|
raw_scores: true,
|
@@ -157,6 +160,7 @@ class PersonalityInsightsV3Test < Minitest::Test
|
|
157
160
|
password: "password"
|
158
161
|
)
|
159
162
|
service_response = service.profile(
|
163
|
+
accept: "application/json",
|
160
164
|
content: personality_text,
|
161
165
|
content_type: "text/plain;charset=utf-8",
|
162
166
|
content_language: "es",
|
@@ -31,6 +31,7 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
|
|
31
31
|
version: "2017-10-13"
|
32
32
|
)
|
33
33
|
service_response = service.profile(
|
34
|
+
accept: "application/json",
|
34
35
|
content: personality_text,
|
35
36
|
content_type: "text/plain;charset=utf-8"
|
36
37
|
)
|
@@ -63,6 +64,7 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
|
|
63
64
|
version: "2017-10-13"
|
64
65
|
)
|
65
66
|
service_response = service.profile(
|
67
|
+
accept: "application/json",
|
66
68
|
content: personality_text,
|
67
69
|
content_type: "application/json",
|
68
70
|
raw_scores: true,
|
@@ -135,6 +137,7 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
|
|
135
137
|
version: "2017-10-13"
|
136
138
|
)
|
137
139
|
service_response = service.profile(
|
140
|
+
accept: "application/json",
|
138
141
|
content: personality_text,
|
139
142
|
content_type: "text/plain;charset=utf-8",
|
140
143
|
content_language: "es",
|
@@ -116,15 +116,15 @@ class VisualRecognitionV3Test < Minitest::Test
|
|
116
116
|
).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
|
117
117
|
service_response = service.create_classifier(
|
118
118
|
name: "Cars vs Trucks",
|
119
|
-
|
119
|
+
positive_examples: { cars: cars },
|
120
120
|
negative_examples: trucks
|
121
121
|
)
|
122
122
|
assert_equal(response, service_response.result)
|
123
123
|
|
124
124
|
service_response = service.create_classifier(
|
125
125
|
name: "Cars vs Trucks",
|
126
|
-
|
127
|
-
|
126
|
+
positive_examples: { cars: "cars" },
|
127
|
+
positive_examples_filename: { cars: "cars" },
|
128
128
|
negative_examples: "trucks",
|
129
129
|
negative_examples_filename: "trucks"
|
130
130
|
)
|
@@ -158,15 +158,15 @@ class VisualRecognitionV3Test < Minitest::Test
|
|
158
158
|
).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
|
159
159
|
service_response = service.update_classifier(
|
160
160
|
classifier_id: "bogusid",
|
161
|
-
|
161
|
+
positive_examples: { example: "positive examples classname" },
|
162
162
|
negative_examples: "negative examples"
|
163
163
|
)
|
164
164
|
assert_equal(response, service_response.result)
|
165
165
|
|
166
166
|
service_response = service.update_classifier(
|
167
167
|
classifier_id: "bogusid",
|
168
|
-
|
169
|
-
|
168
|
+
positive_examples: { example: "positive examples classname" },
|
169
|
+
positive_examples_filename: { example: "positive_filename" },
|
170
170
|
negative_examples: "negative examples",
|
171
171
|
negative_examples_filename: "negative_filename"
|
172
172
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_watson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Nussbaum
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- lib/ibm_watson.rb
|
247
247
|
- lib/ibm_watson/assistant_v1.rb
|
248
248
|
- lib/ibm_watson/assistant_v2.rb
|
249
|
+
- lib/ibm_watson/compare_comply_v1.rb
|
249
250
|
- lib/ibm_watson/detailed_response.rb
|
250
251
|
- lib/ibm_watson/discovery_v1.rb
|
251
252
|
- lib/ibm_watson/iam_token_manager.rb
|
@@ -266,6 +267,7 @@ files:
|
|
266
267
|
- test/appveyor_status.rb
|
267
268
|
- test/integration/test_assistant_v1.rb
|
268
269
|
- test/integration/test_assistant_v2.rb
|
270
|
+
- test/integration/test_compare_comply_v1.rb
|
269
271
|
- test/integration/test_discovery_v1.rb
|
270
272
|
- test/integration/test_iam_assistant_v1.rb
|
271
273
|
- test/integration/test_language_translator_v3.rb
|
@@ -279,6 +281,7 @@ files:
|
|
279
281
|
- test/test_helper.rb
|
280
282
|
- test/unit/test_assistant_v1.rb
|
281
283
|
- test/unit/test_assistant_v2.rb
|
284
|
+
- test/unit/test_compare_comply_v1.rb
|
282
285
|
- test/unit/test_configure_http_client.rb
|
283
286
|
- test/unit/test_discovery_v1.rb
|
284
287
|
- test/unit/test_iam_token_manager.rb
|