adapt-charyf 0.2.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58675ed86d6a65dde20735ccc22f933b2ecd7c39
4
- data.tar.gz: 4581a150ab87359a8c126ed5666a56c0e2dd4abd
3
+ metadata.gz: 8dec5de8819127266f5e2f2dfac6d62d3e5dbcdd
4
+ data.tar.gz: 5ab85c234384a3ef92a3f9ad47500c2fd463fa24
5
5
  SHA512:
6
- metadata.gz: 570418b35b9a1ba545eea34bbd33334d942364e0795b9a06f7ef00f630508e85860fb499df121af6f78603eaeed29438359ce0279c1fb2fb51ef617415cf7252
7
- data.tar.gz: 7ba6374978dada5577c75b93808cfd9bf866203f335de1543868d9c10f61b3eadfeae4a7f7ab87ec3be18578e6086bbc1e59283ec7e5631f9c1378e653ffc3b9
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
@@ -11,4 +11,11 @@ module Adapt
11
11
  config.generators.skill_hooks :intents, :adapt => true
12
12
 
13
13
  end
14
+
15
+ extend self
16
+
17
+ def lookup_paths
18
+ @lookup_paths ||= []
19
+ end
20
+
14
21
  end
@@ -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/adapt_public.rb', File.join('app/skills', skill_content_path, 'intents', 'adapt_public.rb')
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
@@ -0,0 +1,8 @@
1
+ Adapt.instance.load do |routing|
2
+
3
+ routing.register_keywords 'skill_name', '<%= class_name.gsub("::", " ") -%>'
4
+
5
+ routing.intent('<%= class_name.gsub("::", "/") -%>/example')
6
+ .required('skill_name')
7
+
8
+ end
@@ -6,60 +6,72 @@ module Adapt
6
6
  module Intent
7
7
  class Processor < Charyf::Engine::Intent::Processor::Base
8
8
 
9
- strategy_name :adapt
9
+ class NameCollisionError < StandardError; end
10
10
 
11
- MUTEX = Mutex.new.freeze
12
- private_constant :MUTEX
11
+ strategy_name :adapt
13
12
 
14
13
  class << self
15
14
  include PyCall::Import
16
15
 
17
- def get_for(skill_name = nil)
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(skill_name, engine)
50
- @skill_name = skill_name
51
- @engine = engine
59
+ def initialize
60
+ self.class.setup
61
+ @engine = self.class.engine
52
62
  end
53
63
 
54
- def load(skill_name, block)
55
- builder = Adapt::RoutingBuilder.new(skill_name)
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
- matches = app_intent.entities.map { |e| e.keys.first }.inject({}) do |h, entity|
84
- h[self.class.unscope_name(app_intent.skill_name, entity)] = adapt_intent[entity]
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.skill_name, app_intent.controller, app_intent.action, confidence, matches)
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 :skill_name, :name, :controller, :action, :entities
7
+ attr_reader :name, :entities
8
8
 
9
- def initialize(skill_name, name)
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(skill_name)
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[Adapt::Intent::Processor.scoped_name(@skill_name, category)] ||= []).push(words).flatten!
38
+ (@keywords[category] ||= []).push(words).flatten!
50
39
  end
51
40
 
52
41
  def register_regex(regex)
53
- @regexps << scope_regex(regex)
54
-
42
+ @regexps << regex
55
43
  end
56
44
 
57
45
  def intent(name)
58
- intent = Intent.new(@skill_name, Adapt::Intent::Processor.scoped_name(@skill_name,name.to_s.gsub(' ', '')))
46
+ intent = Intent.new(name)
59
47
  @intents << intent
60
48
 
61
49
  intent
62
50
  end
63
51
 
64
- def build(engine, intent_builder_class)
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 = intent_builder_class.new(intent.name)
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
@@ -1,3 +1,3 @@
1
1
  module Adapt
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.5'
3
3
  end
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.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-02 00:00:00.000000000 Z
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/adapt_private.rb.tt
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
@@ -1,3 +0,0 @@
1
- <%= class_name -%>.private_routing_for :adapt do |routing|
2
-
3
- end
@@ -1,9 +0,0 @@
1
- <%= class_name -%>.public_routing_for :adapt do |routing|
2
-
3
- routing.register_keywords 'skill_name', '<%= class_name.gsub("::", " ") -%>'
4
-
5
- routing.intent('Example')
6
- .required('skill_name')
7
- .route_to('base', 'example')
8
-
9
- end