charyf 0.1.1 → 0.2.5
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -105
- data/README.md +7 -1
- data/lib/charyf/engine/all.rb +3 -0
- data/lib/charyf/engine/context.rb +1 -53
- data/lib/charyf/engine/controller/controller.rb +6 -3
- data/lib/charyf/engine/controller/helpers.rb +7 -3
- data/lib/charyf/engine/controller/renderers.rb +2 -2
- data/lib/charyf/engine/dispatcher/base.rb +47 -40
- data/lib/charyf/engine/dispatcher/default.rb +8 -18
- data/lib/charyf/engine/intent/intent.rb +7 -42
- data/lib/charyf/engine/intent/processors/dummy.rb +0 -8
- data/lib/charyf/engine/intent/processors/helpers.rb +1 -11
- data/lib/charyf/engine/intent/processors/processor.rb +6 -32
- data/lib/charyf/engine/interface/interface.rb +25 -18
- data/lib/charyf/engine/interface/program.rb +15 -1
- data/lib/charyf/engine/request.rb +6 -18
- data/lib/charyf/engine/response.rb +7 -26
- data/lib/charyf/engine/routing/default.rb +58 -0
- data/lib/charyf/engine/routing/result.rb +25 -0
- data/lib/charyf/engine/routing/router.rb +33 -0
- data/lib/charyf/engine/session/processors/processor.rb +4 -15
- data/lib/charyf/engine/skill/skill.rb +0 -2
- data/lib/charyf/utils/all.rb +3 -2
- data/lib/charyf/utils/app_engine.rb +28 -0
- data/lib/charyf/utils/application/bootstrap.rb +21 -62
- data/lib/charyf/utils/application/configuration.rb +5 -5
- data/lib/charyf/utils/application.rb +15 -2
- data/lib/charyf/utils/command/actions.rb +10 -2
- data/lib/charyf/utils/commands/all.rb +1 -0
- data/lib/charyf/utils/commands/cli/cli_command.rb +12 -1
- data/lib/charyf/utils/commands/help/USAGE +2 -0
- data/lib/charyf/utils/commands/server/server_command.rb +31 -0
- data/lib/charyf/utils/generators/app/app_generator.rb +1 -0
- data/lib/charyf/utils/generators/app/templates/app/skill_controller.rb.tt +6 -1
- data/lib/charyf/utils/generators/app/templates/config/routes.rb.tt +6 -0
- data/lib/charyf/utils/generators/defaults.rb +11 -2
- data/lib/charyf/utils/generators/intents/intents_generator.rb +1 -1
- data/lib/charyf/utils/parser/parser.rb +6 -13
- data/lib/charyf/utils/pipeline.rb +28 -0
- data/lib/charyf/utils/storage/provider.rb +5 -13
- data/lib/charyf/utils/strategy/base_class.rb +50 -0
- data/lib/charyf/utils/strategy/owner_class.rb +23 -0
- data/lib/charyf/version.rb +2 -2
- data/todo.md +8 -3
- metadata +10 -4
- data/lib/charyf/engine/skill/routing.rb +0 -57
- data/lib/charyf/utils/strategy.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efad5ad87a312bfef51179279205bfe5b60585d5
|
4
|
+
data.tar.gz: ac9413d5cbf58b5bd492cd9e62b22d7045ca21d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05a975f29957417fad8da4b6d805bd93ce0f90fdeecc5af6ce462142461546f7b2dec294c35b5e84cd25c906bae7e6eb7d9ea2797d82f8eb1ea27f0b07e73db
|
7
|
+
data.tar.gz: 3bb190b57931d0b6bcd75a3f6c579e10d233450d41e10d6aeccc37b597a00aebec9b76d52a2d69e2232f2645c22e39022fd7458648f89d98406678007636754d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
charyf (0.
|
4
|
+
charyf (0.2.5)
|
5
5
|
charyf_sig (~> 1.1.2)
|
6
6
|
colorize (~> 0.8)
|
7
7
|
i18n (~> 0.9)
|
@@ -10,97 +10,17 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (5.1.4)
|
14
|
-
actionpack (= 5.1.4)
|
15
|
-
nio4r (~> 2.0)
|
16
|
-
websocket-driver (~> 0.6.1)
|
17
|
-
actionmailer (5.1.4)
|
18
|
-
actionpack (= 5.1.4)
|
19
|
-
actionview (= 5.1.4)
|
20
|
-
activejob (= 5.1.4)
|
21
|
-
mail (~> 2.5, >= 2.5.4)
|
22
|
-
rails-dom-testing (~> 2.0)
|
23
|
-
actionpack (5.1.4)
|
24
|
-
actionview (= 5.1.4)
|
25
|
-
activesupport (= 5.1.4)
|
26
|
-
rack (~> 2.0)
|
27
|
-
rack-test (>= 0.6.3)
|
28
|
-
rails-dom-testing (~> 2.0)
|
29
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
-
actionview (5.1.4)
|
31
|
-
activesupport (= 5.1.4)
|
32
|
-
builder (~> 3.1)
|
33
|
-
erubi (~> 1.4)
|
34
|
-
rails-dom-testing (~> 2.0)
|
35
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
36
|
-
activejob (5.1.4)
|
37
|
-
activesupport (= 5.1.4)
|
38
|
-
globalid (>= 0.3.6)
|
39
|
-
activemodel (5.1.4)
|
40
|
-
activesupport (= 5.1.4)
|
41
|
-
activerecord (5.1.4)
|
42
|
-
activemodel (= 5.1.4)
|
43
|
-
activesupport (= 5.1.4)
|
44
|
-
arel (~> 8.0)
|
45
|
-
activesupport (5.1.4)
|
46
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
47
|
-
i18n (~> 0.7)
|
48
|
-
minitest (~> 5.1)
|
49
|
-
tzinfo (~> 1.1)
|
50
|
-
arel (8.0.0)
|
51
|
-
builder (3.2.3)
|
52
13
|
charyf_sig (1.1.2)
|
53
14
|
coderay (1.1.2)
|
54
15
|
colorize (0.8.1)
|
55
16
|
concurrent-ruby (1.0.5)
|
56
|
-
crass (1.0.3)
|
57
17
|
diff-lcs (1.3)
|
58
|
-
|
59
|
-
globalid (0.4.1)
|
60
|
-
activesupport (>= 4.2.0)
|
61
|
-
i18n (0.9.1)
|
18
|
+
i18n (0.9.5)
|
62
19
|
concurrent-ruby (~> 1.0)
|
63
|
-
loofah (2.1.1)
|
64
|
-
crass (~> 1.0.2)
|
65
|
-
nokogiri (>= 1.5.9)
|
66
|
-
mail (2.7.0)
|
67
|
-
mini_mime (>= 0.1.1)
|
68
20
|
method_source (0.9.0)
|
69
|
-
mini_mime (1.0.0)
|
70
|
-
mini_portile2 (2.3.0)
|
71
|
-
minitest (5.10.3)
|
72
|
-
nio4r (2.2.0)
|
73
|
-
nokogiri (1.8.1)
|
74
|
-
mini_portile2 (~> 2.3.0)
|
75
21
|
pry (0.11.3)
|
76
22
|
coderay (~> 1.1.0)
|
77
23
|
method_source (~> 0.9.0)
|
78
|
-
rack (2.0.3)
|
79
|
-
rack-test (0.8.2)
|
80
|
-
rack (>= 1.0, < 3)
|
81
|
-
rails (5.1.4)
|
82
|
-
actioncable (= 5.1.4)
|
83
|
-
actionmailer (= 5.1.4)
|
84
|
-
actionpack (= 5.1.4)
|
85
|
-
actionview (= 5.1.4)
|
86
|
-
activejob (= 5.1.4)
|
87
|
-
activemodel (= 5.1.4)
|
88
|
-
activerecord (= 5.1.4)
|
89
|
-
activesupport (= 5.1.4)
|
90
|
-
bundler (>= 1.3.0)
|
91
|
-
railties (= 5.1.4)
|
92
|
-
sprockets-rails (>= 2.0.0)
|
93
|
-
rails-dom-testing (2.0.3)
|
94
|
-
activesupport (>= 4.2.0)
|
95
|
-
nokogiri (>= 1.6)
|
96
|
-
rails-html-sanitizer (1.0.3)
|
97
|
-
loofah (~> 2.0)
|
98
|
-
railties (5.1.4)
|
99
|
-
actionpack (= 5.1.4)
|
100
|
-
activesupport (= 5.1.4)
|
101
|
-
method_source
|
102
|
-
rake (>= 0.8.7)
|
103
|
-
thor (>= 0.18.1, < 2.0)
|
104
24
|
rake (10.5.0)
|
105
25
|
rspec (3.7.0)
|
106
26
|
rspec-core (~> 3.7.0)
|
@@ -114,29 +34,8 @@ GEM
|
|
114
34
|
rspec-mocks (3.7.0)
|
115
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
116
36
|
rspec-support (~> 3.7.0)
|
117
|
-
rspec-rails (3.7.2)
|
118
|
-
actionpack (>= 3.0)
|
119
|
-
activesupport (>= 3.0)
|
120
|
-
railties (>= 3.0)
|
121
|
-
rspec-core (~> 3.7.0)
|
122
|
-
rspec-expectations (~> 3.7.0)
|
123
|
-
rspec-mocks (~> 3.7.0)
|
124
|
-
rspec-support (~> 3.7.0)
|
125
37
|
rspec-support (3.7.0)
|
126
|
-
sprockets (3.7.1)
|
127
|
-
concurrent-ruby (~> 1.0)
|
128
|
-
rack (> 1, < 3)
|
129
|
-
sprockets-rails (3.2.1)
|
130
|
-
actionpack (>= 4.0)
|
131
|
-
activesupport (>= 4.0)
|
132
|
-
sprockets (>= 3.0.0)
|
133
38
|
thor (0.20.0)
|
134
|
-
thread_safe (0.3.6)
|
135
|
-
tzinfo (1.2.4)
|
136
|
-
thread_safe (~> 0.1)
|
137
|
-
websocket-driver (0.6.5)
|
138
|
-
websocket-extensions (>= 0.1.0)
|
139
|
-
websocket-extensions (0.1.3)
|
140
39
|
|
141
40
|
PLATFORMS
|
142
41
|
ruby
|
@@ -145,10 +44,8 @@ DEPENDENCIES
|
|
145
44
|
bundler (~> 1.15.4)
|
146
45
|
charyf!
|
147
46
|
pry (~> 0.10)
|
148
|
-
rails
|
149
47
|
rake (~> 10.0)
|
150
48
|
rspec (~> 3.0)
|
151
|
-
rspec-rails
|
152
49
|
|
153
50
|
BUNDLED WITH
|
154
51
|
1.15.4
|
data/README.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
[](https://badge.fury.io/rb/charyf)
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/Charyf/charyf-core)
|
4
|
+
[](https://codeclimate.com/github/Charyf/charyf-core/coverage)
|
5
|
+
[](https://codeclimate.com/github/Charyf/charyf-core)
|
6
|
+
|
1
7
|
# Charyf
|
2
8
|
|
3
9
|
Charyf (as **Cha**tbot **r**ub**y** **f**ramework) is a modular chatbot framework library.
|
@@ -15,4 +21,4 @@ For more information about using charyf, continue to [Getting Started](https://g
|
|
15
21
|
To read more about roadmap continue to [Roadmap](https://github.com/Charyf/charyf-core/wiki/Roadmap)
|
16
22
|
To report an issue follow steps in [Reporting an issue](https://github.com/Charyf/charyf-core/wiki/Reporting-an-issue)
|
17
23
|
|
18
|
-
Continue to [wiki](https://github.com/Charyf/charyf-core/wiki)
|
24
|
+
Continue to [wiki](https://github.com/Charyf/charyf-core/wiki)
|
data/lib/charyf/engine/all.rb
CHANGED
@@ -14,6 +14,9 @@ require_relative 'session/session'
|
|
14
14
|
require_relative 'session/processors/processor'
|
15
15
|
require_relative 'session/processors/default'
|
16
16
|
|
17
|
+
require_relative 'routing/router'
|
18
|
+
require_relative 'routing/default'
|
19
|
+
|
17
20
|
require_relative 'skill/skill'
|
18
21
|
|
19
22
|
require_relative 'charyf'
|
@@ -2,59 +2,7 @@ module Charyf
|
|
2
2
|
module Engine
|
3
3
|
class Context
|
4
4
|
|
5
|
-
|
6
|
-
def request=(request)
|
7
|
-
@_request = request
|
8
|
-
end
|
9
|
-
|
10
|
-
sig [], 'Charyf::Engine::Request',
|
11
|
-
def request
|
12
|
-
@_request
|
13
|
-
end
|
14
|
-
|
15
|
-
sig [['Charyf::Engine::Intent', 'NilClass']],['Charyf::Engine::Intent', 'NilClass'],
|
16
|
-
def intent=(intent)
|
17
|
-
@_intent = intent
|
18
|
-
end
|
19
|
-
|
20
|
-
sig [], ['Charyf::Engine::Intent', 'NilClass'],
|
21
|
-
def intent
|
22
|
-
@_intent
|
23
|
-
end
|
24
|
-
|
25
|
-
sig [['Charyf::Engine::Session', 'NilClass']],['Charyf::Engine::Session', 'NilClass'],
|
26
|
-
def session=(session)
|
27
|
-
@_session = session
|
28
|
-
end
|
29
|
-
|
30
|
-
sig [], ['Charyf::Engine::Session', 'NilClass'],
|
31
|
-
def session
|
32
|
-
@_session
|
33
|
-
end
|
34
|
-
|
35
|
-
def controller_name
|
36
|
-
session && session.action ?
|
37
|
-
session.controller :
|
38
|
-
intent.controller
|
39
|
-
end
|
40
|
-
|
41
|
-
def full_controller_name
|
42
|
-
session && session.action ?
|
43
|
-
session.full_controller_name :
|
44
|
-
intent.full_controller_name
|
45
|
-
end
|
46
|
-
|
47
|
-
def action_name
|
48
|
-
session && session.action ?
|
49
|
-
session.action :
|
50
|
-
intent.action
|
51
|
-
end
|
52
|
-
|
53
|
-
def skill_name
|
54
|
-
session && session.skill ?
|
55
|
-
session.skill :
|
56
|
-
intent.skill
|
57
|
-
end
|
5
|
+
attr_accessor :request, :intent, :alternative_intents, :session, :routing
|
58
6
|
|
59
7
|
end
|
60
8
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
require_relative '../../utils'
|
2
4
|
|
3
5
|
require_relative '../response'
|
@@ -34,7 +36,7 @@ module Charyf
|
|
34
36
|
)
|
35
37
|
|
36
38
|
if text.blank? && html.blank?
|
37
|
-
render ||=
|
39
|
+
render ||= action_name
|
38
40
|
ensure_responses_for(render)
|
39
41
|
end
|
40
42
|
|
@@ -43,8 +45,9 @@ module Charyf
|
|
43
45
|
html ||= render_html_response(render)
|
44
46
|
end
|
45
47
|
|
46
|
-
response = Charyf::Engine::Response.new(
|
47
|
-
|
48
|
+
response = Charyf::Engine::Response.new(conversation_id, SecureRandom.hex)
|
49
|
+
response.text = text
|
50
|
+
response.html = html
|
48
51
|
|
49
52
|
Charyf.logger.flow_response("[FLOW] Replying on request [#{request.inspect}]" +
|
50
53
|
" with [#{response.inspect}]"
|
@@ -10,15 +10,19 @@ module Charyf
|
|
10
10
|
end # End of ClassMethods
|
11
11
|
|
12
12
|
def controller_name
|
13
|
-
context.
|
13
|
+
context.routing.controller
|
14
14
|
end
|
15
15
|
|
16
16
|
def action_name
|
17
|
-
context.
|
17
|
+
context.routing.action
|
18
18
|
end
|
19
19
|
|
20
20
|
def skill_name
|
21
|
-
|
21
|
+
skill.skill_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def skill
|
25
|
+
context.routing.skill_class_name.nil? ? nil : context.routing.skill_class_name.constantize
|
22
26
|
end
|
23
27
|
|
24
28
|
def request
|
@@ -32,9 +32,9 @@ module Charyf
|
|
32
32
|
|
33
33
|
# TODO sig
|
34
34
|
def response_folder
|
35
|
-
return nil if
|
35
|
+
return nil if skill.nil?
|
36
36
|
|
37
|
-
return
|
37
|
+
return skill.skill_root.join('responses', controller_path)
|
38
38
|
end
|
39
39
|
|
40
40
|
def ensure_responses_for(action)
|
@@ -6,24 +6,39 @@ require_relative '../request'
|
|
6
6
|
module Charyf
|
7
7
|
module Engine
|
8
8
|
module Dispatcher
|
9
|
+
|
10
|
+
extend Charyf::Strategy::OwnerClass
|
11
|
+
|
9
12
|
class Base
|
10
13
|
|
11
|
-
include Charyf::Strategy
|
12
|
-
def self.base
|
13
|
-
Base
|
14
|
-
end
|
14
|
+
include Charyf::Strategy::BaseClass
|
15
15
|
|
16
|
-
sig ['Charyf::Engine::Request'], nil,
|
17
16
|
def dispatch(request)
|
18
|
-
|
17
|
+
status, response = dispatch_internal(request)
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
{
|
20
|
+
status: status,
|
21
|
+
response: response,
|
22
|
+
request: request
|
23
|
+
}
|
22
24
|
end
|
23
25
|
|
26
|
+
def dispatch_async(request)
|
27
|
+
Charyf::Pipeline.enqueue request
|
28
|
+
|
29
|
+
{
|
30
|
+
status: :ASYNC,
|
31
|
+
request: request,
|
32
|
+
response: nil
|
33
|
+
}
|
34
|
+
end
|
24
35
|
|
25
36
|
protected
|
26
37
|
|
38
|
+
def dispatch_internal(request)
|
39
|
+
raise Charyf::Utils::NotImplemented.new
|
40
|
+
end
|
41
|
+
|
27
42
|
def self.intent_processors
|
28
43
|
Charyf.application.intent_processors
|
29
44
|
end
|
@@ -32,6 +47,10 @@ module Charyf
|
|
32
47
|
Charyf.application.session_processor
|
33
48
|
end
|
34
49
|
|
50
|
+
def self.routes
|
51
|
+
Charyf.application.routes
|
52
|
+
end
|
53
|
+
|
35
54
|
def intent_processors
|
36
55
|
self.class.intent_processors
|
37
56
|
end
|
@@ -40,51 +59,48 @@ module Charyf
|
|
40
59
|
self.class.session_processor
|
41
60
|
end
|
42
61
|
|
62
|
+
def routes
|
63
|
+
self.class.routes
|
64
|
+
end
|
65
|
+
|
43
66
|
sig ['Charyf::Engine::Context'], nil,
|
44
67
|
def spawn_controller(context)
|
45
|
-
begin
|
46
|
-
prepare_context context
|
47
68
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
69
|
+
Charyf.logger.flow_request("[FLOW] Dispatching request [#{context.request.inspect}]" +
|
70
|
+
", detected intent: [#{context.intent.inspect}]" +
|
71
|
+
", session : [#{context.session.inspect}]"
|
72
|
+
)
|
52
73
|
|
53
|
-
|
74
|
+
controller = get_controller(context)
|
54
75
|
|
76
|
+
begin
|
55
77
|
handle_before_actions(controller)
|
56
|
-
controller.send(context
|
78
|
+
result = controller.send(get_action_name(context))
|
57
79
|
handle_after_actions(controller)
|
80
|
+
|
81
|
+
return :OK, result
|
58
82
|
rescue Exception => e
|
59
83
|
# Dispatch the error to all error handlers
|
60
84
|
Charyf.configuration.error_handlers.handle_exception(e)
|
61
|
-
|
62
85
|
# Catch any error that may occur inside the user controller
|
63
|
-
controller.send(:reply, text: 'There was a problem processing your request. Check the logs please.')
|
86
|
+
# controller.send(:reply, text: 'There was a problem processing your request. Check the logs please.')
|
87
|
+
|
88
|
+
return :NOK, e
|
64
89
|
end
|
65
90
|
|
66
91
|
end
|
67
92
|
|
68
93
|
private
|
69
94
|
|
70
|
-
def prepare_context(context)
|
71
|
-
context.intent ||= Charyf::Engine::Intent::UNKNOWN
|
72
|
-
|
73
|
-
context
|
74
|
-
end
|
75
|
-
|
76
95
|
def get_controller(context)
|
77
|
-
controller_name = context.
|
96
|
+
controller_name = context.routing.controller_class_name
|
78
97
|
|
79
|
-
Object.const_get(controller_name).new(context)
|
98
|
+
# Object.const_get(controller_name).new(context)
|
99
|
+
controller_name.constantize.new(context)
|
80
100
|
end
|
81
101
|
|
82
102
|
def get_action_name(context)
|
83
|
-
|
84
|
-
return context.session.action
|
85
|
-
end
|
86
|
-
|
87
|
-
context.intent.action
|
103
|
+
context.routing.action
|
88
104
|
end
|
89
105
|
|
90
106
|
def handle_before_actions(controller)
|
@@ -107,15 +123,6 @@ module Charyf
|
|
107
123
|
end
|
108
124
|
|
109
125
|
end # End of Base.class
|
110
|
-
|
111
|
-
def self.known
|
112
|
-
Base.known
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.list
|
116
|
-
Base.list
|
117
|
-
end
|
118
|
-
|
119
126
|
end
|
120
127
|
end
|
121
128
|
end
|
@@ -7,11 +7,7 @@ module Charyf
|
|
7
7
|
|
8
8
|
strategy_name :default
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def dispatch(request)
|
10
|
+
def dispatch_internal(request)
|
15
11
|
# Find if session exist for this request
|
16
12
|
|
17
13
|
context = Charyf::Engine::Context.new
|
@@ -22,13 +18,11 @@ module Charyf
|
|
22
18
|
|
23
19
|
# Get intents
|
24
20
|
intents = intent_processors.collect do |processor_klass|
|
25
|
-
processor = processor_klass.
|
21
|
+
processor = processor_klass.instance
|
26
22
|
|
27
23
|
processor.determine(
|
28
24
|
request
|
29
25
|
)
|
30
|
-
end.collect do |intent|
|
31
|
-
[intent, intent.alternatives].flatten
|
32
26
|
end.flatten.sort_by do |intent|
|
33
27
|
intent.confidence
|
34
28
|
end.reverse
|
@@ -38,19 +32,15 @@ module Charyf
|
|
38
32
|
|
39
33
|
# Return best match with alternatives
|
40
34
|
if best_match
|
41
|
-
context.intent = Charyf::Engine::Intent.new(
|
42
|
-
best_match.skill,
|
43
|
-
best_match.controller,
|
44
|
-
best_match.action,
|
45
|
-
best_match.confidence,
|
46
|
-
best_match.matches,
|
47
|
-
intents
|
48
|
-
)
|
49
|
-
|
50
35
|
context.intent = best_match
|
36
|
+
context.alternative_intents = intents
|
51
37
|
end
|
52
38
|
|
53
|
-
|
39
|
+
context.routing = routes.process(context)
|
40
|
+
|
41
|
+
# Freeze -> #TODO deep freeze
|
42
|
+
context.freeze
|
43
|
+
|
54
44
|
spawn_controller(context)
|
55
45
|
end
|
56
46
|
|
@@ -2,53 +2,18 @@ module Charyf
|
|
2
2
|
module Engine
|
3
3
|
class Intent
|
4
4
|
|
5
|
-
|
6
|
-
def initialize(skill, controller, action, confidence, matches = Hash.new, alternatives = [])
|
7
|
-
@_skill = skill.to_s
|
8
|
-
@_controller = controller.to_s
|
9
|
-
@_action = action.to_s.downcase
|
10
|
-
@_confidence = confidence
|
11
|
-
@_matches = matches
|
12
|
-
@_alternatives = alternatives
|
13
|
-
end
|
14
|
-
|
15
|
-
sig [], 'Hash',
|
16
|
-
def matches
|
17
|
-
@_matches
|
18
|
-
end
|
19
|
-
|
20
|
-
sig [], 'Numeric',
|
21
|
-
def confidence
|
22
|
-
@_confidence
|
23
|
-
end
|
24
|
-
|
25
|
-
sig [], ['Symbol', 'String'],
|
26
|
-
def full_controller_name
|
27
|
-
@_skill.blank? ? @_controller.camelize : @_skill.camelize + '::' + @_controller.camelize
|
28
|
-
end
|
29
|
-
|
30
|
-
sig [], ['Symbol', 'String'],
|
31
|
-
def controller
|
32
|
-
@_controller
|
33
|
-
end
|
5
|
+
attr_reader :name, :confidence, :entities
|
34
6
|
|
35
|
-
|
36
|
-
|
37
|
-
@
|
7
|
+
def initialize(name, confidence, entities = Hash.new)
|
8
|
+
@name = name
|
9
|
+
@confidence = confidence
|
10
|
+
@entities = entities || {}
|
38
11
|
end
|
39
12
|
|
40
|
-
|
41
|
-
|
42
|
-
@_alternatives
|
13
|
+
def self.unknown
|
14
|
+
Intent.new('charyf/unknown', 0)
|
43
15
|
end
|
44
16
|
|
45
|
-
sig [], ['String', 'Symbol'],
|
46
|
-
def skill
|
47
|
-
@_skill
|
48
|
-
end
|
49
|
-
|
50
|
-
UNKNOWN = Intent.new(nil, :Skill, :unknown, 0)
|
51
|
-
|
52
17
|
end
|
53
18
|
end
|
54
19
|
end
|
@@ -9,20 +9,10 @@ module Charyf
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
|
13
|
-
def scoped_name(skill_name, *args)
|
14
|
-
([skill_name.to_s] + args).join('_')
|
15
|
-
end
|
16
|
-
|
17
|
-
def unscope_name(skill_name, name)
|
18
|
-
name.start_with?(skill_name.to_s) ? name.sub("#{skill_name.to_s}_", '') : name
|
19
|
-
end
|
20
|
-
|
21
12
|
end # End of ClassMethods
|
22
13
|
|
23
|
-
sig [], 'Charyf::Engine::Intent',
|
24
14
|
def unknown
|
25
|
-
Charyf::Engine::Intent
|
15
|
+
Charyf::Engine::Intent.unknown
|
26
16
|
end
|
27
17
|
|
28
18
|
end
|
@@ -7,49 +7,23 @@ module Charyf
|
|
7
7
|
module Engine
|
8
8
|
class Intent
|
9
9
|
module Processor
|
10
|
+
|
11
|
+
extend Charyf::Strategy::OwnerClass
|
12
|
+
|
10
13
|
class Base
|
11
14
|
|
12
|
-
include Charyf::Strategy
|
15
|
+
include Charyf::Strategy::BaseClass
|
13
16
|
include Charyf::Engine::Intent::Processor::Helpers
|
14
17
|
|
15
|
-
def self.
|
16
|
-
|
18
|
+
def self.instance
|
19
|
+
@instance = self.new
|
17
20
|
end
|
18
21
|
|
19
|
-
sig ['Charyf::Engine::Request'], 'Charyf::Engine::Intent',
|
20
22
|
def determine(request)
|
21
23
|
raise Charyf::Utils::NotImplemented.new
|
22
24
|
end
|
23
25
|
|
24
|
-
#
|
25
|
-
# Load single block of intent definitions
|
26
|
-
#
|
27
|
-
sig_self ['Symbol', 'Proc'], nil,
|
28
|
-
def load(skill_name, block)
|
29
|
-
raise Charyf::Utils::NotImplemented.new
|
30
|
-
end
|
31
|
-
|
32
|
-
sig_self ['Symbol'], 'Charyf::Engine::Intent::Processor::Base',
|
33
|
-
def self.get_for(skill = nil)
|
34
|
-
raise Charyf::Utils::NotImplemented.new
|
35
|
-
end
|
36
|
-
|
37
|
-
sig_self [], 'Charyf::Engine::Intent::Processor::Base',
|
38
|
-
def self.get_global
|
39
|
-
get_for(nil)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def self.known
|
46
|
-
Base.known
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.list
|
50
|
-
Base.list
|
51
26
|
end
|
52
|
-
|
53
27
|
end
|
54
28
|
end
|
55
29
|
end
|