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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -105
  3. data/README.md +7 -1
  4. data/lib/charyf/engine/all.rb +3 -0
  5. data/lib/charyf/engine/context.rb +1 -53
  6. data/lib/charyf/engine/controller/controller.rb +6 -3
  7. data/lib/charyf/engine/controller/helpers.rb +7 -3
  8. data/lib/charyf/engine/controller/renderers.rb +2 -2
  9. data/lib/charyf/engine/dispatcher/base.rb +47 -40
  10. data/lib/charyf/engine/dispatcher/default.rb +8 -18
  11. data/lib/charyf/engine/intent/intent.rb +7 -42
  12. data/lib/charyf/engine/intent/processors/dummy.rb +0 -8
  13. data/lib/charyf/engine/intent/processors/helpers.rb +1 -11
  14. data/lib/charyf/engine/intent/processors/processor.rb +6 -32
  15. data/lib/charyf/engine/interface/interface.rb +25 -18
  16. data/lib/charyf/engine/interface/program.rb +15 -1
  17. data/lib/charyf/engine/request.rb +6 -18
  18. data/lib/charyf/engine/response.rb +7 -26
  19. data/lib/charyf/engine/routing/default.rb +58 -0
  20. data/lib/charyf/engine/routing/result.rb +25 -0
  21. data/lib/charyf/engine/routing/router.rb +33 -0
  22. data/lib/charyf/engine/session/processors/processor.rb +4 -15
  23. data/lib/charyf/engine/skill/skill.rb +0 -2
  24. data/lib/charyf/utils/all.rb +3 -2
  25. data/lib/charyf/utils/app_engine.rb +28 -0
  26. data/lib/charyf/utils/application/bootstrap.rb +21 -62
  27. data/lib/charyf/utils/application/configuration.rb +5 -5
  28. data/lib/charyf/utils/application.rb +15 -2
  29. data/lib/charyf/utils/command/actions.rb +10 -2
  30. data/lib/charyf/utils/commands/all.rb +1 -0
  31. data/lib/charyf/utils/commands/cli/cli_command.rb +12 -1
  32. data/lib/charyf/utils/commands/help/USAGE +2 -0
  33. data/lib/charyf/utils/commands/server/server_command.rb +31 -0
  34. data/lib/charyf/utils/generators/app/app_generator.rb +1 -0
  35. data/lib/charyf/utils/generators/app/templates/app/skill_controller.rb.tt +6 -1
  36. data/lib/charyf/utils/generators/app/templates/config/routes.rb.tt +6 -0
  37. data/lib/charyf/utils/generators/defaults.rb +11 -2
  38. data/lib/charyf/utils/generators/intents/intents_generator.rb +1 -1
  39. data/lib/charyf/utils/parser/parser.rb +6 -13
  40. data/lib/charyf/utils/pipeline.rb +28 -0
  41. data/lib/charyf/utils/storage/provider.rb +5 -13
  42. data/lib/charyf/utils/strategy/base_class.rb +50 -0
  43. data/lib/charyf/utils/strategy/owner_class.rb +23 -0
  44. data/lib/charyf/version.rb +2 -2
  45. data/todo.md +8 -3
  46. metadata +10 -4
  47. data/lib/charyf/engine/skill/routing.rb +0 -57
  48. data/lib/charyf/utils/strategy.rb +0 -44
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../../command/base'
3
+ require_relative '../../command/environment_argument'
4
+
5
+ module Charyf
6
+
7
+ module Command
8
+
9
+ class ServerCommand < Base # :nodoc:
10
+
11
+ include EnvironmentArgument
12
+
13
+ hide_command!
14
+
15
+ def perform
16
+ extract_environment_option
17
+
18
+ # CHARYF_ENV needs to be set before application is required.
19
+ ENV["CHARYF_ENV"] = options[:environment]
20
+
21
+ require_application_and_environment!
22
+
23
+ start_interfaces!
24
+
25
+ start_pipeline!
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -80,6 +80,7 @@ module Charyf
80
80
  template "boot.rb"
81
81
  template "chapp.rb"
82
82
  template "load.rb"
83
+ template "routes.rb"
83
84
 
84
85
  directory "environments"
85
86
  empty_directory_with_keep_file "initializers"
@@ -5,4 +5,9 @@ class SkillController < Charyf::Controller::Base
5
5
  reply(text: "I am sorry, I can't help you with that.")
6
6
  end
7
7
 
8
- end
8
+ def invalid
9
+ logger.warn("Unknown intent routing for request: #{request.inspect}")
10
+ reply(text: "Don't know where to route intent '#{intent.name}'")
11
+ end
12
+
13
+ end
@@ -0,0 +1,6 @@
1
+ Charyf.application.routes.draw do
2
+
3
+ # This is dont automatically, override to change
4
+ # route 'charyf/unknown', to: {skill: nil, controller: 'skill', action: 'unknown'}
5
+
6
+ end
@@ -24,13 +24,22 @@ Should not be used on production environments as it is not persisted.
24
24
  INTENT_PROCESSORS = {
25
25
  adapt: {
26
26
  gem: 'adapt-charyf',
27
- gem_version: ['>= 0.2'],
27
+ gem_version: ['>= 0.2.4'],
28
28
  require: 'adapt-charyf',
29
29
  desc: <<-EOM
30
- Ruby wrapper around python library from mycroft [adapt]
30
+ Ruby wrapper around python library from mycroft [adapt]. Works offline.
31
31
  It uses building blocks as regexps or small expressions to define and determine intents.
32
32
  see more at: https://github.com/Charyf/charyf-adapt-processor
33
33
  EOM
34
+ },
35
+ wit: {
36
+ gem: 'witai-charyf',
37
+ gem_version: ['>= 0.2'],
38
+ require: 'witai/charyf',
39
+ desc: <<-EOM
40
+ Charyf wrapper around WIT.ai service. Utilizes powerful NLP (works online as service).
41
+ Supports builtin entity tagging like datetimes, amounts, locations and more.
42
+ EOM
34
43
  }
35
44
  }
36
45
 
@@ -29,7 +29,7 @@ module Charyf
29
29
  private
30
30
 
31
31
  def intent_generators
32
- Charyf::Generators.options[:intents].keys.map(&:downcase)
32
+ (Charyf::Generators.options[:intents] || {}).keys.map(&:downcase)
33
33
  end
34
34
 
35
35
  def generator_name(intent_processor_name)
@@ -1,15 +1,16 @@
1
1
  require_relative '../../support/string'
2
- require_relative '../strategy'
2
+ require_relative '../strategy/base_class'
3
+ require_relative '../strategy/owner_class'
3
4
 
4
5
  module Charyf
5
6
  module Utils
6
7
  module Parser
8
+
9
+ extend Charyf::Strategy::OwnerClass
10
+
7
11
  class Base
8
12
 
9
- include Charyf::Strategy
10
- def self.base
11
- Base
12
- end
13
+ include Charyf::Strategy::BaseClass
13
14
 
14
15
  # TODO sig
15
16
  def self.normalize(text, remove_articles: true)
@@ -18,14 +19,6 @@ module Charyf
18
19
 
19
20
  end # End of base
20
21
 
21
- def self.known
22
- Base.known
23
- end
24
-
25
- def self.list
26
- Base.list
27
- end
28
-
29
22
  # TODO sig
30
23
  def self.get(language)
31
24
  # TODO implement
@@ -0,0 +1,28 @@
1
+ require 'thread'
2
+
3
+ module Charyf
4
+ module Pipeline
5
+
6
+ class << self
7
+
8
+ #
9
+ # This method si blocking
10
+ #
11
+ def dequeue
12
+ _pipeline.deq
13
+ end
14
+
15
+ def enqueue(request)
16
+ _pipeline.enq(request)
17
+ end
18
+
19
+ private
20
+
21
+ def _pipeline
22
+ @pipeline ||= Queue.new
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -1,14 +1,14 @@
1
- require_relative '../strategy'
1
+ require_relative '../strategy/base_class'
2
2
 
3
3
  module Charyf
4
4
  module Utils
5
5
  module StorageProvider
6
+
7
+ extend Charyf::Strategy::OwnerClass
8
+
6
9
  class Base
7
10
 
8
- include Charyf::Strategy
9
- def self.base
10
- Base
11
- end
11
+ include Charyf::Strategy::BaseClass
12
12
 
13
13
  sig_self [['Module', 'String']], ['Charyf::Utils::StorageProvider::Base'],
14
14
  def self.get_for(klass)
@@ -31,14 +31,6 @@ module Charyf
31
31
  end
32
32
 
33
33
  end # End of Base
34
-
35
- def self.known
36
- Base.known
37
- end
38
-
39
- def self.list
40
- Base.list
41
- end
42
34
  end
43
35
  end
44
36
  end
@@ -0,0 +1,50 @@
1
+ module Charyf
2
+ module Strategy
3
+ module BaseClass
4
+
5
+ class << self
6
+ def included(base)
7
+ base.extend(ClassMethods)
8
+ base.instance_variable_set('@_base_class', base)
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def inherited(subclass)
14
+ base._subclasses << subclass
15
+ subclass.instance_variable_set('@_base_class', base)
16
+ end
17
+
18
+ def strategy_name(name = nil)
19
+ if name
20
+ @_strategy_name = name
21
+ base._aliases[name] = self
22
+ end
23
+
24
+ @_strategy_name
25
+ end
26
+
27
+ def _subclasses
28
+ @_subclasses ||= []
29
+ end
30
+
31
+ def _aliases
32
+ @_aliases ||= Hash.new
33
+ end
34
+
35
+ def known
36
+ base._subclasses
37
+ end
38
+
39
+ def list
40
+ base._aliases
41
+ end
42
+
43
+ def base
44
+ @_base_class
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ module Charyf
2
+ module Strategy
3
+ module OwnerClass
4
+
5
+ def known
6
+ base_class.known
7
+ end
8
+
9
+ def list
10
+ base_class.list
11
+ end
12
+
13
+ def base_class(name = nil)
14
+ if name
15
+ @_base_class = name
16
+ end
17
+
18
+ self.const_get(@_base_class || :Base)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -10,8 +10,8 @@ module Charyf
10
10
 
11
11
  module VERSION
12
12
  MAJOR = 0
13
- MINOR = 1
14
- TINY = 1
13
+ MINOR = 2
14
+ TINY = 5
15
15
  PRE = nil
16
16
 
17
17
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
data/todo.md CHANGED
@@ -1,3 +1,8 @@
1
- * check that dispatcher can handle namespaces
2
- * inject namespace to controller name
3
- * can result to Weather::ForecastSkill::ForecastController
1
+ * remove all imports, everything should import what is needed
2
+ * remove sig -> too many problems
3
+ * dispatcher - sync vs async
4
+ * only one reply, however allow sends to the same interface
5
+ * this should add a message id to request
6
+ * reply will be part of the return value -> wrap in hash with meta info
7
+ * messages will be send to the interface with conversation + request message id
8
+ * async interfaces will receive {async: true} return value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charyf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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-01-13 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_sig
@@ -167,11 +167,13 @@ files:
167
167
  - lib/charyf/engine/interface/program.rb
168
168
  - lib/charyf/engine/request.rb
169
169
  - lib/charyf/engine/response.rb
170
+ - lib/charyf/engine/routing/default.rb
171
+ - lib/charyf/engine/routing/result.rb
172
+ - lib/charyf/engine/routing/router.rb
170
173
  - lib/charyf/engine/session/processors/default.rb
171
174
  - lib/charyf/engine/session/processors/processor.rb
172
175
  - lib/charyf/engine/session/session.rb
173
176
  - lib/charyf/engine/skill/info.rb
174
- - lib/charyf/engine/skill/routing.rb
175
177
  - lib/charyf/engine/skill/skill.rb
176
178
  - lib/charyf/support.rb
177
179
  - lib/charyf/support/all.rb
@@ -203,6 +205,7 @@ files:
203
205
  - lib/charyf/utils/commands/generate/generate_command.rb
204
206
  - lib/charyf/utils/commands/help/USAGE
205
207
  - lib/charyf/utils/commands/help/help.rb
208
+ - lib/charyf/utils/commands/server/server_command.rb
206
209
  - lib/charyf/utils/configuration.rb
207
210
  - lib/charyf/utils/error_handler.rb
208
211
  - lib/charyf/utils/extension.rb
@@ -224,6 +227,7 @@ files:
224
227
  - lib/charyf/utils/generators/app/templates/config/environments/production.rb.tt
225
228
  - lib/charyf/utils/generators/app/templates/config/environments/test.rb.tt
226
229
  - lib/charyf/utils/generators/app/templates/config/load.rb.tt
230
+ - lib/charyf/utils/generators/app/templates/config/routes.rb.tt
227
231
  - lib/charyf/utils/generators/app/templates/gitignore
228
232
  - lib/charyf/utils/generators/app_base.rb
229
233
  - lib/charyf/utils/generators/defaults.rb
@@ -238,9 +242,11 @@ files:
238
242
  - lib/charyf/utils/machine.rb
239
243
  - lib/charyf/utils/parser/en_parser.rb
240
244
  - lib/charyf/utils/parser/parser.rb
245
+ - lib/charyf/utils/pipeline.rb
241
246
  - lib/charyf/utils/ruby_version_check.rb
242
247
  - lib/charyf/utils/storage/provider.rb
243
- - lib/charyf/utils/strategy.rb
248
+ - lib/charyf/utils/strategy/base_class.rb
249
+ - lib/charyf/utils/strategy/owner_class.rb
244
250
  - lib/charyf/utils/utils.rb
245
251
  - lib/charyf/version.rb
246
252
  - lib/locale/en.yml
@@ -1,57 +0,0 @@
1
- module Charyf
2
- module Skill
3
- module Routing
4
-
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
-
11
- sig ['Pathname'], ['Pathname'],
12
- def routing_source_dir(abs_path = nil)
13
- if abs_path
14
- @_routing_source_dir = abs_path
15
- end
16
-
17
- @_routing_source_dir || skill_root.join('intents')
18
- end
19
-
20
- def public_routing_for(processor_name)
21
- _public_routing(processor_name) << Proc.new
22
-
23
- nil
24
- end
25
-
26
- def private_routing_for(processor_name)
27
- _private_routing(processor_name) << Proc.new
28
-
29
- nil
30
- end
31
-
32
-
33
- def _public_routing(processor)
34
- processor = processor.to_sym
35
-
36
- @_public_routing ||= Hash.new
37
-
38
- @_public_routing[processor] ||= []
39
-
40
- @_public_routing[processor]
41
- end
42
-
43
- def _private_routing(processor)
44
- processor = processor.to_sym
45
-
46
- @_public_routing ||= Hash.new
47
-
48
- @_public_routing[processor] ||= []
49
-
50
- @_public_routing[processor]
51
- end
52
-
53
- end # End of ClassMethods
54
-
55
- end
56
- end
57
- end
@@ -1,44 +0,0 @@
1
- module Charyf
2
- module Strategy
3
-
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def inherited(subclass)
10
- base._subclasses << subclass
11
- end
12
-
13
- def strategy_name(name = nil)
14
- if name
15
- @_strategy_name = name
16
- base._aliases[name] = self
17
- end
18
-
19
- @_strategy_name
20
- end
21
-
22
- def _subclasses
23
- @_subclasses ||= []
24
- end
25
-
26
- def _aliases
27
- @_aliases ||= Hash.new
28
- end
29
-
30
- def known
31
- base._subclasses
32
- end
33
-
34
- def list
35
- base._aliases
36
- end
37
-
38
- def base
39
- raise Charyf::Utils::NotImplemented.new("No base class found for #{self}")
40
- end
41
- end
42
-
43
- end
44
- end