adapt-charyf 0.2.2 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/adapt-charyf.gemspec +1 -1
- data/lib/adapt-charyf.rb +7 -0
- data/lib/adapt/generators/intent/intent_generator.rb +1 -5
- data/lib/adapt/generators/intent/templates/intents/adapt/routing.adapt.rb.tt +8 -0
- data/lib/adapt/processor.rb +44 -33
- data/lib/adapt/routing_builder.rb +8 -26
- data/lib/adapt/version.rb +1 -1
- metadata +5 -6
- data/lib/adapt/generators/intent/templates/intents/adapt_private.rb.tt +0 -3
- data/lib/adapt/generators/intent/templates/intents/adapt_public.rb.tt +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dec5de8819127266f5e2f2dfac6d62d3e5dbcdd
|
4
|
+
data.tar.gz: 5ab85c234384a3ef92a3f9ad47500c2fd463fa24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e941870d9ade1edf90918bf8838924fd90d824323a679b55792cc3fb82ae636c13f94141bdc1a089176f8840f7cb79807f7351ae384bde424f68309f0d583577
|
7
|
+
data.tar.gz: bf1928a2ffbe8fcda1084759bc84cdee237cbedd9232d8f6a9ec14a962459fafe230efd83eb2b67d81b3140564a539369cfaf1f5f400301412531ae8a0a06786
|
data/adapt-charyf.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
33
|
spec.require_paths = ["lib"]
|
34
34
|
|
35
|
-
spec.add_runtime_dependency "charyf", "~> 0"
|
35
|
+
spec.add_runtime_dependency "charyf", "~> 0.2"
|
36
36
|
spec.add_runtime_dependency "pycall", "~> 1.0.3"
|
37
37
|
|
38
38
|
spec.add_development_dependency "bundler", "~> 1.15"
|
data/lib/adapt-charyf.rb
CHANGED
@@ -7,13 +7,9 @@ module Adapt
|
|
7
7
|
source_root File.expand_path('templates', __dir__)
|
8
8
|
|
9
9
|
def public_routing
|
10
|
-
template 'intents/
|
10
|
+
template 'intents/adapt/routing.adapt.rb', File.join('app/skills', skill_content_path, 'intents', 'adapt', 'default_routing.adapt.rb')
|
11
11
|
end
|
12
12
|
|
13
|
-
# def private_routing
|
14
|
-
# template 'intents/adapt_private.rb', File.join('app/skills', skill_content_path, 'intents', 'adapt_private.rb')
|
15
|
-
# end
|
16
|
-
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
data/lib/adapt/processor.rb
CHANGED
@@ -6,60 +6,72 @@ module Adapt
|
|
6
6
|
module Intent
|
7
7
|
class Processor < Charyf::Engine::Intent::Processor::Base
|
8
8
|
|
9
|
-
|
9
|
+
class NameCollisionError < StandardError; end
|
10
10
|
|
11
|
-
|
12
|
-
private_constant :MUTEX
|
11
|
+
strategy_name :adapt
|
13
12
|
|
14
13
|
class << self
|
15
14
|
include PyCall::Import
|
16
15
|
|
17
|
-
def
|
18
|
-
engine = engine(skill_name)
|
19
|
-
|
20
|
-
self.new(skill_name, engine)
|
21
|
-
end
|
22
|
-
|
23
|
-
def engine(skill_name = nil)
|
24
|
-
MUTEX.synchronize {
|
25
|
-
return _engines[skill_name] ||= init_engine
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def init_engine
|
16
|
+
def engine
|
30
17
|
unless @_python_loaded
|
31
|
-
pyfrom 'adapt.intent', import: :IntentBuilder
|
32
|
-
pyfrom 'adapt.engine', import: :IntentDeterminationEngine
|
18
|
+
self.pyfrom 'adapt.intent', import: :IntentBuilder
|
19
|
+
self.pyfrom 'adapt.engine', import: :IntentDeterminationEngine
|
33
20
|
@_python_loaded = true
|
34
21
|
end
|
35
22
|
|
36
|
-
IntentDeterminationEngine.new
|
37
|
-
end
|
38
|
-
|
39
|
-
def _engines
|
40
|
-
@engines ||= {}
|
23
|
+
@engine ||= IntentDeterminationEngine.new
|
41
24
|
end
|
42
25
|
|
43
26
|
def _intents
|
44
27
|
@intents ||= {}
|
45
28
|
end
|
46
29
|
|
30
|
+
def setup
|
31
|
+
return if @initialized
|
32
|
+
@initialized = true
|
33
|
+
|
34
|
+
load_files
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def load_files
|
40
|
+
# Seek skill folders
|
41
|
+
Charyf::Skill.list.each do |skill_klass|
|
42
|
+
root = skill_klass.skill_root
|
43
|
+
|
44
|
+
Dir[root.join('intents', '**', '*.adapt.rb')].each do |intent_definition_file|
|
45
|
+
require intent_definition_file
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Load additional paths
|
50
|
+
Adapt.lookup_paths.each do |path|
|
51
|
+
Dir[Pathname.new(path.to_s).join('**', '*.adapt.rb')].each do |intent_definition_file|
|
52
|
+
require intent_definition_file
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
47
57
|
end
|
48
58
|
|
49
|
-
def initialize
|
50
|
-
|
51
|
-
@engine = engine
|
59
|
+
def initialize
|
60
|
+
self.class.setup
|
61
|
+
@engine = self.class.engine
|
52
62
|
end
|
53
63
|
|
54
|
-
def
|
55
|
-
builder = Adapt::RoutingBuilder.new
|
64
|
+
def define(&block)
|
65
|
+
builder = Adapt::RoutingBuilder.new
|
56
66
|
|
57
67
|
block.call(builder)
|
58
68
|
|
59
69
|
intents = builder.build(@engine, IntentBuilder)
|
60
70
|
|
61
|
-
# TODO handle already existing
|
62
71
|
intents.each do |intent|
|
72
|
+
# TODO handle already existing
|
73
|
+
raise NameCollisionError.new("Intent name '#{intent.name}' already in use.") if self.class._intents[intent.name]
|
74
|
+
|
63
75
|
self.class._intents[intent.name] = intent
|
64
76
|
end
|
65
77
|
end
|
@@ -80,15 +92,14 @@ module Adapt
|
|
80
92
|
app_intent = self.class._intents[adapt_intent['intent_type']]
|
81
93
|
|
82
94
|
|
83
|
-
|
84
|
-
h[
|
95
|
+
entities = app_intent.entities.map { |e| e.keys.first }.inject({}) do |h, entity|
|
96
|
+
h[entity] = adapt_intent[entity]
|
85
97
|
h
|
86
98
|
end
|
87
99
|
|
88
|
-
Charyf::Engine::Intent.new(app_intent.
|
100
|
+
return Charyf::Engine::Intent.new(app_intent.name, confidence, entities)
|
89
101
|
end
|
90
102
|
|
91
|
-
|
92
103
|
end
|
93
104
|
end
|
94
105
|
end
|
@@ -4,40 +4,29 @@ module Adapt
|
|
4
4
|
class InvalidState < StandardError; end
|
5
5
|
|
6
6
|
class Intent
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :name, :entities
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@skill_name = skill_name
|
9
|
+
def initialize(name)
|
11
10
|
@name = name
|
12
|
-
@controller = nil
|
13
|
-
@action = nil
|
14
11
|
|
15
12
|
@entities = []
|
16
13
|
end
|
17
14
|
|
18
15
|
def required(entity)
|
19
|
-
entity = Adapt::Intent::Processor.scoped_name(@skill_name, entity)
|
20
16
|
@entities << {entity => :required}
|
21
17
|
|
22
18
|
return self
|
23
19
|
end
|
24
20
|
|
25
21
|
def optional(entity)
|
26
|
-
entity = Adapt::Intent::Processor.scoped_name(@skill_name, entity)
|
27
22
|
@entities << {entity => :optional}
|
28
23
|
|
29
24
|
return self
|
30
25
|
end
|
31
26
|
|
32
|
-
def route_to(controller, action)
|
33
|
-
@controller = controller
|
34
|
-
@action = action
|
35
|
-
end
|
36
27
|
end # End of Intent.class
|
37
28
|
|
38
|
-
def initialize
|
39
|
-
@skill_name = skill_name
|
40
|
-
|
29
|
+
def initialize
|
41
30
|
@keywords = {}
|
42
31
|
@regexps = []
|
43
32
|
@intents = []
|
@@ -46,22 +35,21 @@ module Adapt
|
|
46
35
|
def register_keywords(category, word, *words)
|
47
36
|
words = [word] + words
|
48
37
|
|
49
|
-
(@keywords[
|
38
|
+
(@keywords[category] ||= []).push(words).flatten!
|
50
39
|
end
|
51
40
|
|
52
41
|
def register_regex(regex)
|
53
|
-
@regexps <<
|
54
|
-
|
42
|
+
@regexps << regex
|
55
43
|
end
|
56
44
|
|
57
45
|
def intent(name)
|
58
|
-
intent = Intent.new(
|
46
|
+
intent = Intent.new(name)
|
59
47
|
@intents << intent
|
60
48
|
|
61
49
|
intent
|
62
50
|
end
|
63
51
|
|
64
|
-
def build(engine,
|
52
|
+
def build(engine, python_builder)
|
65
53
|
@keywords.each do |group, words|
|
66
54
|
words.each do |word|
|
67
55
|
engine.register_entity(word, group)
|
@@ -73,7 +61,7 @@ module Adapt
|
|
73
61
|
end
|
74
62
|
|
75
63
|
@intents.each do |intent|
|
76
|
-
builder =
|
64
|
+
builder = python_builder.new(intent.name)
|
77
65
|
|
78
66
|
intent.entities.each do |entity|
|
79
67
|
entity, method = entity.first
|
@@ -94,11 +82,5 @@ module Adapt
|
|
94
82
|
@intents
|
95
83
|
end
|
96
84
|
|
97
|
-
private
|
98
|
-
|
99
|
-
def scope_regex(regex)
|
100
|
-
regex.to_s.gsub(/\(\?P\<(.*)\>/, "(?P<#{Adapt::Intent::Processor.scoped_name(@skill_name, '\1').gsub('.', '_')}>")
|
101
|
-
end
|
102
|
-
|
103
85
|
end
|
104
86
|
end
|
data/lib/adapt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adapt-charyf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Ludvigh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: charyf
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pycall
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,8 +114,7 @@ files:
|
|
114
114
|
- bin/setup
|
115
115
|
- lib/adapt-charyf.rb
|
116
116
|
- lib/adapt/generators/intent/intent_generator.rb
|
117
|
-
- lib/adapt/generators/intent/templates/intents/
|
118
|
-
- lib/adapt/generators/intent/templates/intents/adapt_public.rb.tt
|
117
|
+
- lib/adapt/generators/intent/templates/intents/adapt/routing.adapt.rb.tt
|
119
118
|
- lib/adapt/processor.rb
|
120
119
|
- lib/adapt/routing_builder.rb
|
121
120
|
- lib/adapt/version.rb
|