14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/charyf/engine/dispatcher/default.rb', line 14
def dispatch(request)
context = Charyf::Engine::Context.new
context.request = request
context.session = session_processor.get.process(request)
intents = intent_processors.collect do |processor_klass|
processor = processor_klass.get_for(context.session ? context.session.skill : nil)
processor.determine(
request
)
end.collect do |intent|
[intent, intent.alternatives].flatten
end.flatten.sort_by do |intent|
intent.confidence
end.reverse
best_match = intents.shift
if best_match
context.intent = Charyf::Engine::Intent.new(
best_match.skill,
best_match.controller,
best_match.action,
best_match.confidence,
best_match.matches,
intents
)
context.intent = best_match
end
spawn_controller(context)
end
|