stealth 1.1.5 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -11
  3. data/CHANGELOG.md +77 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +53 -49
  6. data/LICENSE +4 -17
  7. data/README.md +9 -17
  8. data/VERSION +1 -1
  9. data/lib/stealth/base.rb +72 -21
  10. data/lib/stealth/cli.rb +1 -2
  11. data/lib/stealth/commands/console.rb +1 -1
  12. data/lib/stealth/configuration.rb +6 -3
  13. data/lib/stealth/controller/callbacks.rb +1 -1
  14. data/lib/stealth/controller/catch_all.rb +27 -4
  15. data/lib/stealth/controller/controller.rb +168 -49
  16. data/lib/stealth/controller/dev_jumps.rb +41 -0
  17. data/lib/stealth/controller/dynamic_delay.rb +4 -6
  18. data/lib/stealth/controller/interrupt_detect.rb +100 -0
  19. data/lib/stealth/controller/messages.rb +283 -0
  20. data/lib/stealth/controller/nlp.rb +50 -0
  21. data/lib/stealth/controller/replies.rb +183 -40
  22. data/lib/stealth/controller/unrecognized_message.rb +62 -0
  23. data/lib/stealth/{flow/core_ext.rb → core_ext/numeric.rb} +0 -1
  24. data/lib/stealth/core_ext/string.rb +18 -0
  25. data/lib/stealth/core_ext.rb +5 -0
  26. data/lib/stealth/dispatcher.rb +21 -0
  27. data/lib/stealth/errors.rb +12 -0
  28. data/lib/stealth/flow/base.rb +1 -2
  29. data/lib/stealth/flow/specification.rb +3 -2
  30. data/lib/stealth/flow/state.rb +3 -3
  31. data/lib/stealth/generators/builder/Gemfile +4 -3
  32. data/lib/stealth/generators/builder/bot/controllers/bot_controller.rb +42 -0
  33. data/lib/stealth/generators/builder/bot/controllers/catch_alls_controller.rb +2 -0
  34. data/lib/stealth/generators/builder/bot/controllers/goodbyes_controller.rb +2 -0
  35. data/lib/stealth/generators/builder/bot/controllers/hellos_controller.rb +2 -0
  36. data/lib/stealth/generators/builder/bot/controllers/interrupts_controller.rb +9 -0
  37. data/lib/stealth/generators/builder/bot/controllers/unrecognized_messages_controller.rb +9 -0
  38. data/lib/stealth/generators/builder/config/flow_map.rb +8 -0
  39. data/lib/stealth/generators/builder/config/initializers/autoload.rb +8 -0
  40. data/lib/stealth/generators/builder/config/initializers/inflections.rb +16 -0
  41. data/lib/stealth/generators/builder/config/puma.rb +15 -0
  42. data/lib/stealth/helpers/redis.rb +40 -0
  43. data/lib/stealth/lock.rb +83 -0
  44. data/lib/stealth/logger.rb +27 -18
  45. data/lib/stealth/nlp/client.rb +22 -0
  46. data/lib/stealth/nlp/result.rb +57 -0
  47. data/lib/stealth/reloader.rb +90 -0
  48. data/lib/stealth/reply.rb +17 -0
  49. data/lib/stealth/scheduled_reply.rb +3 -3
  50. data/lib/stealth/server.rb +8 -3
  51. data/lib/stealth/service_message.rb +3 -2
  52. data/lib/stealth/service_reply.rb +5 -1
  53. data/lib/stealth/services/base_reply_handler.rb +10 -2
  54. data/lib/stealth/session.rb +106 -53
  55. data/spec/configuration_spec.rb +42 -2
  56. data/spec/controller/callbacks_spec.rb +23 -28
  57. data/spec/controller/catch_all_spec.rb +87 -29
  58. data/spec/controller/controller_spec.rb +444 -43
  59. data/spec/controller/dynamic_delay_spec.rb +16 -18
  60. data/spec/controller/helpers_spec.rb +1 -2
  61. data/spec/controller/interrupt_detect_spec.rb +171 -0
  62. data/spec/controller/messages_spec.rb +744 -0
  63. data/spec/controller/nlp_spec.rb +93 -0
  64. data/spec/controller/replies_spec.rb +446 -11
  65. data/spec/controller/unrecognized_message_spec.rb +168 -0
  66. data/spec/dispatcher_spec.rb +79 -0
  67. data/spec/flow/flow_spec.rb +1 -2
  68. data/spec/flow/state_spec.rb +14 -3
  69. data/spec/helpers/redis_spec.rb +77 -0
  70. data/spec/lock_spec.rb +100 -0
  71. data/spec/nlp/client_spec.rb +23 -0
  72. data/spec/nlp/result_spec.rb +57 -0
  73. data/spec/replies/messages/say_msgs_without_breaks.yml +4 -0
  74. data/spec/replies/messages/say_randomize_speech.yml +10 -0
  75. data/spec/replies/messages/say_randomize_text.yml +10 -0
  76. data/spec/replies/messages/sub1/sub2/say_nested.yml +10 -0
  77. data/spec/reply_spec.rb +61 -0
  78. data/spec/scheduled_reply_spec.rb +23 -0
  79. data/spec/service_reply_spec.rb +1 -2
  80. data/spec/session_spec.rb +251 -12
  81. data/spec/spec_helper.rb +21 -0
  82. data/spec/support/controllers/vaders_controller.rb +24 -0
  83. data/spec/support/nlp_clients/dialogflow.rb +9 -0
  84. data/spec/support/nlp_clients/luis.rb +9 -0
  85. data/spec/support/nlp_results/luis_result.rb +163 -0
  86. data/spec/version_spec.rb +1 -2
  87. data/stealth.gemspec +6 -6
  88. metadata +83 -38
  89. data/docs/00-introduction.md +0 -37
  90. data/docs/01-getting-started.md +0 -21
  91. data/docs/02-local-development.md +0 -40
  92. data/docs/03-basics.md +0 -171
  93. data/docs/04-sessions.md +0 -29
  94. data/docs/05-controllers.md +0 -179
  95. data/docs/06-models.md +0 -39
  96. data/docs/07-replies.md +0 -114
  97. data/docs/08-catchalls.md +0 -49
  98. data/docs/09-messaging-integrations.md +0 -80
  99. data/docs/10-nlp-integrations.md +0 -13
  100. data/docs/11-analytics.md +0 -13
  101. data/docs/12-commands.md +0 -62
  102. data/docs/13-deployment.md +0 -50
  103. data/lib/stealth/generators/builder/config/initializers/.keep +0 -0
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'spec_helper'
5
4
 
6
5
  describe "Stealth::ServiceReply" do
7
6
 
data/spec/session_spec.rb CHANGED
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'spec_helper'
5
4
 
6
5
  class FlowMap
7
6
  include Stealth::Flow
@@ -19,20 +18,20 @@ class FlowMap
19
18
  end
20
19
 
21
20
  describe "Stealth::Session" do
22
- let(:user_id) { '0xDEADBEEF' }
21
+ let(:id) { '0xDEADBEEF' }
23
22
 
24
23
  it "should raise an error if $redis is not set" do
25
24
  $redis = nil
26
25
 
27
26
  expect {
28
- Stealth::Session.new(user_id: user_id)
27
+ Stealth::Session.new(id: id)
29
28
  }.to raise_error(Stealth::Errors::RedisNotConfigured)
30
29
 
31
30
  $redis = MockRedis.new
32
31
  end
33
32
 
34
33
  describe "without a session" do
35
- let(:session) { Stealth::Session.new(user_id: user_id) }
34
+ let(:session) { Stealth::Session.new(id: id) }
36
35
 
37
36
  it "should have nil flow and state" do
38
37
  expect(session.flow).to be_nil
@@ -52,8 +51,8 @@ describe "Stealth::Session" do
52
51
 
53
52
  describe "with a session" do
54
53
  let(:session) do
55
- session = Stealth::Session.new(user_id: user_id)
56
- session.set(flow: 'marco', state: 'polo')
54
+ session = Stealth::Session.new(id: id)
55
+ session.set_session(new_flow: 'marco', new_state: 'polo')
57
56
  session
58
57
  end
59
58
 
@@ -81,33 +80,71 @@ describe "Stealth::Session" do
81
80
  end
82
81
 
83
82
  describe "incrementing and decrementing" do
84
- let(:session) { Stealth::Session.new(user_id: user_id) }
83
+ let(:session) { Stealth::Session.new(id: id) }
85
84
 
86
85
  it "should increment the state" do
87
- session.set(flow: 'new_todo', state: 'get_due_date')
86
+ session.set_session(new_flow: 'new_todo', new_state: 'get_due_date')
88
87
  new_session = session + 1.state
89
88
  expect(new_session.state_string).to eq('created')
90
89
  end
91
90
 
92
91
  it "should decrement the state" do
93
- session.set(flow: 'new_todo', state: 'error')
92
+ session.set_session(new_flow: 'new_todo', new_state: 'error')
94
93
  new_session = session - 2.states
95
94
  expect(new_session.state_string).to eq('get_due_date')
96
95
  end
97
96
 
98
97
  it "should return the first state if the decrement is out of bounds" do
99
- session.set(flow: 'new_todo', state: 'get_due_date')
98
+ session.set_session(new_flow: 'new_todo', new_state: 'get_due_date')
100
99
  new_session = session - 5.states
101
100
  expect(new_session.state_string).to eq('new')
102
101
  end
103
102
 
104
103
  it "should return the last state if the increment is out of bounds" do
105
- session.set(flow: 'new_todo', state: 'created')
104
+ session.set_session(new_flow: 'new_todo', new_state: 'created')
106
105
  new_session = session + 5.states
107
106
  expect(new_session.state_string).to eq('error')
108
107
  end
109
108
  end
110
109
 
110
+ describe "==" do
111
+ let(:session) {
112
+ _session = Stealth::Session.new(id: id, type: :primary)
113
+ _session.set_session(new_flow: 'hello', new_state: 'say_hola')
114
+ _session
115
+ }
116
+
117
+ it "should return false if the session ids do not" do
118
+ other_session = Stealth::Session.new(id: 'xyz123', type: :primary)
119
+ other_session.set_session(new_flow: 'hello', new_state: 'say_hola')
120
+ expect(session == other_session).to be false
121
+ end
122
+
123
+ it "should return false if the states do not" do
124
+ other_session = Stealth::Session.new(id: id, type: :primary)
125
+ other_session.set_session(new_flow: 'hello', new_state: 'say_hola2')
126
+ expect(session == other_session).to be false
127
+ end
128
+
129
+ it "should return false if flows do not match" do
130
+ other_session = Stealth::Session.new(id: id, type: :primary)
131
+ other_session.set_session(new_flow: 'hello2', new_state: 'say_hola')
132
+ expect(session == other_session).to be false
133
+ end
134
+
135
+ it 'should return false if the session type does not match' do
136
+ other_session = Stealth::Session.new(id: id, type: :back_to)
137
+ other_session.set_session(new_flow: 'hello', new_state: 'say_hola')
138
+ expect(session == other_session).to be false
139
+ end
140
+
141
+ it 'should return true if the session id, flow, state, and session types match' do
142
+ other_session = Stealth::Session.new(id: id, type: :primary)
143
+ other_session.set_session(new_flow: 'hello', new_state: 'say_hola')
144
+ expect(session == other_session).to be true
145
+ end
146
+ end
147
+
111
148
  describe "self.is_a_session_string?" do
112
149
  it "should return false for state strings" do
113
150
  session_string = 'say_hello'
@@ -124,4 +161,206 @@ describe "Stealth::Session" do
124
161
  expect(Stealth::Session.is_a_session_string?(session_string)).to be true
125
162
  end
126
163
  end
164
+
165
+ describe "self.canonical_session_slug" do
166
+ it "should generate a canonical session slug given a flow and state as symbols" do
167
+ expect(
168
+ Stealth::Session.canonical_session_slug(flow: :hello, state: :say_hello)
169
+ ).to eq 'hello->say_hello'
170
+ end
171
+
172
+ it "should generate a canonical session slug given a flow and state as strings" do
173
+ expect(
174
+ Stealth::Session.canonical_session_slug(flow: 'hello', state: 'say_hello')
175
+ ).to eq 'hello->say_hello'
176
+ end
177
+ end
178
+
179
+ describe "self.flow_and_state_from_session_slug" do
180
+ it "should return the flow and string as a hash with symbolized keys" do
181
+ slug = 'hello->say_hello'
182
+ expect(
183
+ Stealth::Session.flow_and_state_from_session_slug(slug: slug)
184
+ ).to eq({ flow: 'hello', state: 'say_hello' })
185
+ end
186
+
187
+ it "should not raise if slug is nil" do
188
+ slug = nil
189
+ expect(
190
+ Stealth::Session.flow_and_state_from_session_slug(slug: slug)
191
+ ).to eq({ flow: nil, state: nil })
192
+ end
193
+ end
194
+
195
+ describe "setting sessions" do
196
+ let(:session) { Stealth::Session.new(id: id) }
197
+ let(:previous_session) { Stealth::Session.new(id: id, type: :previous) }
198
+ let(:back_to_session) { Stealth::Session.new(id: id, type: :back_to) }
199
+
200
+ before(:each) do
201
+ $redis.del(id)
202
+ $redis.del([id, 'previous'].join('-'))
203
+ $redis.del([id, 'back_to'].join('-'))
204
+ end
205
+
206
+ it "should store the new session" do
207
+ session.set_session(new_flow: 'marco', new_state: 'polo')
208
+ expect($redis.get(id)).to eq 'marco->polo'
209
+ end
210
+
211
+ it "should store the current_session to previous_session" do
212
+ $redis.set(id, 'new_todo->new')
213
+ $redis.set([id, 'previous'].join('-'), 'new_todo->error')
214
+ session.set_session(new_flow: 'marco', new_state: 'polo')
215
+ expect(previous_session.get_session).to eq 'new_todo->new'
216
+ end
217
+
218
+ it "should not update previous_session if it matches current_session" do
219
+ $redis.set(id, 'marco->polo')
220
+ $redis.set([id, 'previous'].join('-'), 'new_todo->new')
221
+ session.set_session(new_flow: 'marco', new_state: 'polo')
222
+ expect(previous_session.get_session).to eq 'new_todo->new'
223
+ end
224
+
225
+ it "should set an expiration for current_session if session_ttl is specified" do
226
+ Stealth.config.session_ttl = 500
227
+ session.set_session(new_flow: 'marco', new_state: 'polo')
228
+ expect($redis.ttl(id)).to be > 0
229
+ Stealth.config.session_ttl = 0
230
+ end
231
+
232
+ it "should set an expiration for previous_session if session_ttl is specified" do
233
+ Stealth.config.session_ttl = 500
234
+ $redis.set(id, 'new_todo->new')
235
+ session.set_session(new_flow: 'marco', new_state: 'polo')
236
+ expect($redis.ttl([id, 'previous'].join('-'))).to be > 0
237
+ Stealth.config.session_ttl = 0
238
+ end
239
+
240
+ it "should NOT set an expiration if session_ttl is not specified" do
241
+ Stealth.config.session_ttl = 0
242
+ session.set_session(new_flow: 'new_todo', new_state: 'get_due_date')
243
+ expect($redis.ttl(id)).to eq -1 # Does not expire
244
+ end
245
+
246
+ it "should set the session for back_to" do
247
+ back_to_session.set_session(new_flow: 'marco', new_state: 'polo')
248
+ expect($redis.get([id, 'back_to'].join('-'))).to eq 'marco->polo'
249
+ end
250
+
251
+ it "should set an expiration for back_to if session_ttl is specified" do
252
+ Stealth.config.session_ttl = 500
253
+ back_to_session.set_session(new_flow: 'marco', new_state: 'polo')
254
+ expect($redis.ttl([id, 'back_to'].join('-'))).to be > 0
255
+ Stealth.config.session_ttl = 0
256
+ end
257
+ end
258
+
259
+ describe "getting sessions" do
260
+ let(:session) { Stealth::Session.new(id: id) }
261
+ let(:previous_session) { Stealth::Session.new(id: id, type: :previous) }
262
+ let(:back_to_session) { Stealth::Session.new(id: id, type: :back_to) }
263
+
264
+ before(:each) do
265
+ $redis.del(id)
266
+ $redis.del([id, 'previous'].join('-'))
267
+ $redis.del([id, 'back_to'].join('-'))
268
+ end
269
+
270
+ it "should return the stored current_session" do
271
+ session.set_session(new_flow: 'marco', new_state: 'polo')
272
+ expect(session.get_session).to eq 'marco->polo'
273
+ end
274
+
275
+ it "should return the stored previous_session if previous is requested" do
276
+ $redis.set(id, 'new_todo->new')
277
+ session.set_session(new_flow: 'marco', new_state: 'polo')
278
+ expect(previous_session.get_session).to eq 'new_todo->new'
279
+ end
280
+
281
+ it "should update the expiration of current_session if session_ttl is set" do
282
+ Stealth.config.session_ttl = 50
283
+ session.set_session(new_flow: 'marco', new_state: 'polo')
284
+ expect($redis.ttl(id)).to be_between(0, 50).inclusive
285
+
286
+ Stealth.config.session_ttl = 500
287
+ session.session = nil # reset memoization
288
+ session.get_session
289
+ expect($redis.ttl(id)).to be > 100
290
+
291
+ Stealth.config.session_ttl = 0
292
+ end
293
+
294
+ it "should return the stored back_to_session" do
295
+ back_to_session.set_session(new_flow: 'marco', new_state: 'polo')
296
+ expect(back_to_session.get_session).to eq 'marco->polo'
297
+ end
298
+
299
+ it "should update the expiration of back_to_session if session_ttl is set" do
300
+ Stealth.config.session_ttl = 50
301
+ back_to_session.set_session(new_flow: 'marco', new_state: 'polo')
302
+ expect($redis.ttl([id, 'back_to'].join('-'))).to be_between(0, 50).inclusive
303
+
304
+ Stealth.config.session_ttl = 500
305
+ back_to_session.session = nil # reset memoization
306
+ back_to_session.get_session
307
+ expect($redis.ttl([id, 'back_to'].join('-'))).to be > 100
308
+
309
+ Stealth.config.session_ttl = 0
310
+ end
311
+ end
312
+
313
+ describe "clearing sessions" do
314
+ let(:session) { Stealth::Session.new(id: id) }
315
+ let(:previous_session) { Stealth::Session.new(id: id, type: :previous) }
316
+ let(:back_to_session) { Stealth::Session.new(id: id, type: :back_to) }
317
+
318
+ before(:each) do
319
+ session.send(:persist_key, key: session.session_key, value: '1')
320
+ previous_session.send(:persist_key, key: previous_session.session_key, value: '1')
321
+ back_to_session.send(:persist_key, key: back_to_session.session_key, value: '1')
322
+ end
323
+
324
+ it "should remove a default session from Redis" do
325
+ expect($redis.get(session.session_key)).to eq '1'
326
+ session.clear_session
327
+ expect($redis.get(session.session_key)).to be_nil
328
+ end
329
+
330
+ it "should remove a previous session from Redis" do
331
+ expect($redis.get(previous_session.session_key)).to eq '1'
332
+ previous_session.clear_session
333
+ expect($redis.get(previous_session.session_key)).to be_nil
334
+ end
335
+
336
+ it "should remove a back_to session from Redis" do
337
+ expect($redis.get(back_to_session.session_key)).to eq '1'
338
+ back_to_session.clear_session
339
+ expect($redis.get(back_to_session.session_key)).to be_nil
340
+ end
341
+ end
342
+
343
+ describe "self.slugify" do
344
+ it "should return a session slug given a flow and state" do
345
+ expect(Stealth::Session.slugify(flow: 'hello', state: 'world')).to eq 'hello->world'
346
+ end
347
+
348
+ it "should raise an ArgumentError if flow is blank" do
349
+ expect {
350
+ Stealth::Session.slugify(flow: '', state: 'world')
351
+ }.to raise_error(ArgumentError)
352
+ end
353
+
354
+ it "should raise an ArgumentError if state is blank" do
355
+ expect {
356
+ Stealth::Session.slugify(flow: 'hello', state: nil)
357
+ }.to raise_error(ArgumentError)
358
+ end
359
+
360
+ it "should raise an ArgumentError if flow and state are blank" do
361
+ expect {
362
+ Stealth::Session.slugify(flow: nil, state: nil)
363
+ }.to raise_error(ArgumentError)
364
+ end
365
+ end
127
366
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  require 'rspec'
7
7
 
8
8
  require 'stealth'
9
+ require 'sidekiq/testing'
9
10
  require 'mock_redis'
10
11
 
11
12
  # Requires supporting files with custom matchers and macros, etc,
@@ -13,7 +14,27 @@ require 'mock_redis'
13
14
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
15
 
15
16
  $redis = MockRedis.new
17
+ $services_yml = File.read(File.join(File.dirname(__FILE__), 'support', 'services.yml'))
16
18
 
17
19
  RSpec.configure do |config|
18
20
  ENV['STEALTH_ENV'] = 'test'
21
+
22
+ config.before(:each) do |example|
23
+ Sidekiq::Testing.fake!
24
+
25
+ Stealth.load_services_config!($services_yml)
26
+ end
27
+
28
+ config.expect_with :rspec do |expectations|
29
+ # This option will default to `true` in RSpec 4. It makes the `description`
30
+ # and `failure_message` of custom matchers include text for helper methods
31
+ # defined using `chain`, e.g.:
32
+ # be_bigger_than(2).and_smaller_than(4).description
33
+ # # => "be bigger than 2 and smaller than 4"
34
+ # ...rather than:
35
+ # # => "be bigger than 2"
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+
38
+ expectations.on_potential_false_positives = :nothing
39
+ end
19
40
  end
@@ -0,0 +1,24 @@
1
+ class VadersController < Stealth::Controller
2
+ def my_action
3
+ raise "oops"
4
+ end
5
+
6
+ def my_action2
7
+
8
+ end
9
+
10
+ def my_action3
11
+ do_nothing
12
+ end
13
+
14
+ def action_with_unrecognized_msg
15
+ handle_message(
16
+ 'hello' => proc { puts "Hello world!" },
17
+ 'bye' => proc { puts "Goodbye world!" }
18
+ )
19
+ end
20
+
21
+ def action_with_unrecognized_match
22
+ match = get_match(['hello', 'bye'])
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module Stealth
2
+ module Nlp
3
+ module Dialogflow
4
+ class Client < Stealth::Nlp::Client
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Stealth
2
+ module Nlp
3
+ module Luis
4
+ class Client < Stealth::Nlp::Client
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,163 @@
1
+ module TestNlpResult
2
+ class Luis < Stealth::Nlp::Result
3
+
4
+ ENTITY_MAP = {
5
+ 'money' => :currency, 'number' => :number, 'email' => :email,
6
+ 'percentage' => :percentage, 'Calendar.Duration' => :duration,
7
+ 'geographyV2' => :geo, 'age' => :age, 'phonenumber' => :phone,
8
+ 'ordinalV2' => :ordinal, 'url' => :url, 'dimension' => :dimension,
9
+ 'temperature' => :temp, 'keyPhrase' => :key_phrase, 'name' => :name,
10
+ 'datetimeV2' => :datetime
11
+ }
12
+
13
+ attr_reader :result, :intent
14
+
15
+ def initialize(intent:, entity: :single_number_entity)
16
+ @result = test_responses[entity]
17
+ @intent = intent
18
+ end
19
+
20
+ def parsed_result
21
+ @result
22
+ end
23
+
24
+ def intent_score
25
+ rand
26
+ end
27
+
28
+ def raw_entities
29
+ @result.dig('prediction', 'entities')
30
+ end
31
+
32
+ def entities
33
+ return {} if raw_entities.blank?
34
+ _entities = {}
35
+
36
+ raw_entities.each do |type, values|
37
+ if ENTITY_MAP[type]
38
+ _entities[ENTITY_MAP[type]] = values
39
+ else
40
+ # A custom entity
41
+ _entities[type.to_sym] = values
42
+ end
43
+ end
44
+
45
+ _entities
46
+ end
47
+
48
+ def sentiment
49
+ %i(positive neutral negative).sample
50
+ end
51
+
52
+ def sentiment_score
53
+ rand
54
+ end
55
+
56
+ def present?
57
+ parsed_result.present?
58
+ end
59
+
60
+ private
61
+
62
+ def test_responses
63
+ {
64
+ single_number_entity: {
65
+ "query" => "My score was 78",
66
+ "prediction" => {
67
+ "topIntent" => "None",
68
+ "intents" => {
69
+ "None" => {
70
+ "score" => 0.170594558
71
+ }
72
+ },
73
+ "entities" => {
74
+ "keyPhrase" => [
75
+ "score"
76
+ ],
77
+ "number" => [
78
+ 78
79
+ ]
80
+ },
81
+ "sentiment" => {
82
+ "label" => "neutral",
83
+ "score" => 0.5
84
+ }
85
+ }
86
+ },
87
+
88
+ double_number_entity: {
89
+ "query" => "Their scores were 89 and 97, respectively",
90
+ "prediction" => {
91
+ "topIntent" => "None",
92
+ "intents" => {
93
+ "None" => {
94
+ "score" => 0.5280223
95
+ }
96
+ },
97
+ "entities" => {
98
+ "keyPhrase" => [
99
+ "scores"
100
+ ],
101
+ "number" => [
102
+ 89,
103
+ 97
104
+ ]
105
+ },
106
+ "sentiment" => {
107
+ "label" => "negative",
108
+ "score" => 0.309174955
109
+ }
110
+ }
111
+ },
112
+
113
+ triple_number_entity: {
114
+ "query" => "Their scores were 89, 65, and 97, respectively",
115
+ "prediction" => {
116
+ "topIntent" => "None",
117
+ "intents" => {
118
+ "None" => {
119
+ "score" => 0.6703843
120
+ }
121
+ },
122
+ "entities" => {
123
+ "keyPhrase" => [
124
+ "scores"
125
+ ],
126
+ "number" => [
127
+ 89,
128
+ 65,
129
+ 97
130
+ ]
131
+ },
132
+ "sentiment" => {
133
+ "label" => "negative",
134
+ "score" => 0.309174955
135
+ }
136
+ }
137
+ },
138
+
139
+ custom_entity: {
140
+ "query" => "call me right away",
141
+ "prediction" => {
142
+ "topIntent" => "now",
143
+ "intents" => {
144
+ "now" => {
145
+ "score" => 0.781227
146
+ }
147
+ },
148
+ "entities" => {
149
+ "asap" => [
150
+ ["right away"]
151
+ ]
152
+ },
153
+ "sentiment" => {
154
+ "label" => "neutral",
155
+ "score" => 0.5
156
+ }
157
+ }
158
+ }
159
+ }
160
+ end
161
+
162
+ end
163
+ end
data/spec/version_spec.rb CHANGED
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'spec_helper'
5
4
 
6
5
  describe "Stealth::Version" do
7
6
 
data/stealth.gemspec CHANGED
@@ -13,16 +13,16 @@ Gem::Specification.new do |s|
13
13
  s.email = 'mauricio@edge14.com'
14
14
 
15
15
  s.add_dependency 'sinatra', '~> 2.0'
16
- s.add_dependency 'puma', '~> 3.10'
17
- s.add_dependency 'thor', '~> 0.20'
16
+ s.add_dependency 'puma', '>= 4.2', '< 6.0'
17
+ s.add_dependency 'thor', '~> 1.0'
18
18
  s.add_dependency 'multi_json', '~> 1.12'
19
- s.add_dependency 'sidekiq', '~> 5.0'
20
- s.add_dependency 'activesupport', '~> 5.2'
19
+ s.add_dependency 'sidekiq', '~> 6.0'
20
+ s.add_dependency 'activesupport', '~> 6.0'
21
21
 
22
- s.add_development_dependency 'rspec', '~> 3.6'
22
+ s.add_development_dependency 'rspec', '~> 3.9'
23
23
  s.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
24
24
  s.add_development_dependency 'rack-test', '~> 1.1'
25
- s.add_development_dependency 'mock_redis', '~> 0.17'
25
+ s.add_development_dependency 'mock_redis', '~> 0.22'
26
26
 
27
27
  s.files = `git ls-files`.split("\n")
28
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")