adapt-charyf 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51a5cabed9c862b2c6e06b064f84de2bc985cd5e
4
- data.tar.gz: 034a37ea4bb271a25c299100a23cb9a890073451
3
+ metadata.gz: 0ae0b4187634b74e19145a589d728f4dfbcff32e
4
+ data.tar.gz: 5aade8cc3b617e4e6943e4d718f7265b7b527d03
5
5
  SHA512:
6
- metadata.gz: d6879e92a75b1c8287e62ed3d6271c61c3625eec8bcb251fb044dad8efaba76ac11dc9ae6bc23bddd332011aba64a19a54d7e4f451f832404d72f76a80b4b687
7
- data.tar.gz: 7903736b38b307a33056dcf57c60934c81a1142a68daaf94c5de0982e3f0e18803a5770887a72ace3227aa9c537f15743c9e8037012c89f6111f607769b1bca7
6
+ metadata.gz: 2a91885e56eb0ffb1f51331c9ab66135ddba69683127d8bf55d839be9c6f3594622d2b435a1f6711048cc20a756a28477db7341db296edc278caa96e290c2a72
7
+ data.tar.gz: e29fab6d2614932133f5fb2d3a54ddb06e2e83c57775f7f2244c880ba5f83b555e77ae41305fbdbdf8f3c4ddec9153ae2f3a32f1c0f43957bddb7825c7958693
data/adapt-charyf.gemspec CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.add_runtime_dependency "charyf", "~> 0.2"
36
36
  spec.add_runtime_dependency "pycall", "~> 1.0.3"
37
+ spec.add_runtime_dependency "i18n", "~> 0.9"
37
38
 
38
39
  spec.add_development_dependency "bundler", "~> 1.15"
39
40
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,22 @@
1
+ require 'charyf/utils/generator/base'
2
+
3
+ module Adapt
4
+ module Generators
5
+ class InstallGenerator < Charyf::Generators::Base
6
+
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def initializer
10
+ template 'config/initializers/adapt.rb.tt'
11
+ end
12
+
13
+ def finalize
14
+ return unless behavior == :invoke
15
+
16
+ say_status 'notice', "Adapt installed" +
17
+ "\n\t\tDo not forget to set adapt intent processor in application configuration", :green
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ # Alternatively set the python path in code
2
+ # ENV['PYTHON'] = 'python3'
@@ -0,0 +1,97 @@
1
+ require_relative 'parser'
2
+
3
+ module Adapt
4
+ module Helpers
5
+ module Parser
6
+ # noinspection RubyLiteralArrayInspection,RubyQuotedStringsInspection
7
+ # English string normalization
8
+ class English < Base
9
+
10
+ strategy_name :en
11
+
12
+ CONTRACTION = ["ain't", "aren't", "can't", "could've", "couldn't",
13
+ "didn't", "doesn't", "don't", "gonna", "gotta",
14
+ "hadn't", "hasn't", "haven't", "he'd", "he'll", "he's",
15
+ "how'd", "how'll", "how's", "I'd", "I'll", "I'm",
16
+ "I've", "isn't", "it'd", "it'll", "it's", "mightn't",
17
+ "might've", "mustn't", "must've", "needn't", "oughtn't",
18
+ "shan't", "she'd", "she'll", "she's", "shouldn't",
19
+ "should've", "somebody's", "someone'd", "someone'll",
20
+ "someone's", "that'll", "that's", "that'd", "there'd",
21
+ "there're", "there's", "they'd", "they'll", "they're",
22
+ "they've", "wasn't", "we'd", "we'll", "we're", "we've",
23
+ "weren't", "what'd", "what'll", "what're", "what's",
24
+ "whats",
25
+ "what've", "when's", "when'd", "where'd", "where's",
26
+ "where've", "who'd", "who'd've", "who'll", "who're",
27
+ "who's", "who've", "why'd", "why're", "why's", "won't",
28
+ "won't've", "would've", "wouldn't", "wouldn't've",
29
+ "y'all", "ya'll", "you'd", "you'd've", "you'll",
30
+ "y'aint", "y'ain't", "you're", "you've"].map(&:downcase).freeze
31
+
32
+ EXPANSION = ["is not", "are not", "can not", "could have",
33
+ "could not", "did not", "does not", "do not",
34
+ "going to", "got to", "had not", "has not",
35
+ "have not", "he would", "he will", "he is", "how did",
36
+ "how will", "how is", "I would", "I will", "I am",
37
+ "I have", "is not", "it would", "it will", "it is",
38
+ "might not", "might have", "must not", "must have",
39
+ "need not", "ought not", "shall not", "she would",
40
+ "she will", "she is", "should not", "should have",
41
+ "somebody is", "someone would", "someone will",
42
+ "someone is", "that will", "that is", "that would",
43
+ "there would", "there are", "there is", "they would",
44
+ "they will", "they are", "they have", "was not",
45
+ "we would", "we will", "we are", "we have",
46
+ "were not", "what did", "what will", "what are",
47
+ "what is",
48
+ "what is", "what have", "when is", "when did",
49
+ "where did", "where is", "where have", "who would",
50
+ "who would have", "who will", "who are", "who is",
51
+ "who have", "why did", "why are", "why is",
52
+ "will not", "will not have", "would have",
53
+ "would not", "would not have", "you all", "you all",
54
+ "you would", "you would have", "you will",
55
+ "you are not", "you are not", "you are", "you have"].map(&:downcase).freeze
56
+
57
+ TEXT_NUMBERS = ["zero", "one", "two", "three", "four", "five", "six",
58
+ "seven", "eight", "nine", "ten", "eleven", "twelve",
59
+ "thirteen", "fourteen", "fifteen", "sixteen",
60
+ "seventeen", "eighteen", "nineteen", "twenty"].map(&:downcase).freeze
61
+
62
+ ARTICLES = ["the", "a", "an"].map(&:downcase).freeze
63
+
64
+ def self.normalize(text, remove_articles: true)
65
+ words = text.split
66
+
67
+ normalized = ''
68
+
69
+ words.each do |word|
70
+ next if word.empty?
71
+ next if remove_articles && ARTICLES.include?(word.downcase)
72
+
73
+ # Expand common contractions, e.g. "isn't" -> "is not"
74
+ if CONTRACTION.include?(word.downcase)
75
+ capitalize = false
76
+ if word[0] == word[0].upcase
77
+ capitalize = true
78
+ end
79
+ word = EXPANSION[CONTRACTION.index(word.downcase)]
80
+
81
+ word.capitalize! if capitalize
82
+ end
83
+
84
+ if TEXT_NUMBERS.include?(word.downcase)
85
+ word = TEXT_NUMBERS.index(word.downcase)
86
+ end
87
+
88
+ normalized += " " + word
89
+ end
90
+
91
+ normalized.strip
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,28 @@
1
+ require 'charyf/utils/strategy/base_class'
2
+ require 'charyf/utils/strategy/owner_class'
3
+
4
+ module Adapt
5
+ module Helpers
6
+ module Parser
7
+
8
+ extend Charyf::Strategy::OwnerClass
9
+
10
+ class Base
11
+
12
+ include Charyf::Strategy::BaseClass
13
+
14
+ def self.normalize(text, remove_articles: true)
15
+ raise Charyf::Utils::NotImplemented.new
16
+ end
17
+
18
+ end # End of base
19
+
20
+ def self.get(language)
21
+ list[language]
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+ require_relative 'en_parser'
@@ -1,6 +1,7 @@
1
1
  require 'pycall/import'
2
2
 
3
3
  require_relative 'routing_builder'
4
+ require_relative 'helpers/parser'
4
5
 
5
6
  module Adapt
6
7
  module Intent
@@ -20,20 +21,28 @@ module Adapt
20
21
  @_python_loaded = true
21
22
  end
22
23
 
23
- @engine ||= IntentDeterminationEngine.new
24
+ @_engine ||= IntentDeterminationEngine.new
24
25
  end
25
26
 
26
27
  def _intents
27
- @intents ||= {}
28
+ @_intents ||= {}
28
29
  end
29
30
 
30
31
  def setup
31
- return if @initialized
32
- @initialized = true
32
+ return if @_initialized
33
+ @_initialized = true
33
34
 
34
35
  load_files
35
36
  end
36
37
 
38
+ def parser
39
+ return @_parser if @_parser_initialized
40
+
41
+ @_parser = Adapt::Helpers::Parser.get(Adapt.config.locale)
42
+ @_parser_initialized = true
43
+ puts "No language helper for locale '#{Adapt.config.locale}' available" if @_parser.nil?
44
+ end
45
+
37
46
  private
38
47
 
39
48
  def load_files
@@ -47,7 +56,7 @@ module Adapt
47
56
  end
48
57
 
49
58
  # Load additional paths
50
- Adapt.lookup_paths.each do |path|
59
+ Adapt.config.lookup_paths.each do |path|
51
60
  Dir[Pathname.new(path.to_s).join('**', '*.adapt.rb')].each do |intent_definition_file|
52
61
  require intent_definition_file
53
62
  end
@@ -59,6 +68,8 @@ module Adapt
59
68
  def initialize
60
69
  self.class.setup
61
70
  @engine = self.class.engine
71
+
72
+ @parser = self.class.parser
62
73
  end
63
74
 
64
75
  def define(&block)
@@ -78,7 +89,10 @@ module Adapt
78
89
 
79
90
  def determine(request)
80
91
  adapt_intent = nil
81
- text = Charyf.application.parser.normalize(request.text)
92
+
93
+ # Normalize text
94
+ text = @parser ? @parser.normalize(request.text) : request.text
95
+
82
96
  generator = @engine.determine_intent(text)
83
97
  begin
84
98
  adapt_intent = PyCall.builtins.next(generator)
@@ -93,7 +107,10 @@ module Adapt
93
107
 
94
108
 
95
109
  entities = app_intent.entities.map { |e| e.keys.first }.inject({}) do |h, entity|
96
- h[entity] = adapt_intent[entity]
110
+ h[entity] = {
111
+ value: adapt_intent[entity]
112
+ }
113
+
97
114
  h
98
115
  end
99
116
 
data/lib/adapt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Adapt
2
- VERSION = '0.2.6'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/adapt-charyf.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'charyf'
2
+ require 'i18n'
3
+
2
4
  require_relative 'adapt/processor'
3
5
 
4
6
  module Adapt
@@ -6,16 +8,21 @@ module Adapt
6
8
 
7
9
  generators do
8
10
  require_relative 'adapt/generators/intent/intent_generator'
11
+ require_relative 'adapt/generators/install/install_generator'
9
12
  end
10
13
 
11
14
  config.generators.skill_hooks :intents, :adapt => true
12
15
 
16
+ # If unset, I18n locale will be used
17
+ config.locale = nil
18
+ config.lookup_paths = []
19
+
13
20
  end
14
21
 
15
22
  extend self
16
23
 
17
- def lookup_paths
18
- @lookup_paths ||= []
24
+ def config
25
+ Extension.config
19
26
  end
20
27
 
21
28
  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.6
4
+ version: 0.3.0
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-31 00:00:00.000000000 Z
11
+ date: 2018-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: charyf
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -113,8 +127,12 @@ files:
113
127
  - bin/console
114
128
  - bin/setup
115
129
  - lib/adapt-charyf.rb
130
+ - lib/adapt/generators/install/install_generator.rb
131
+ - lib/adapt/generators/install/templates/config/initializers/adapt.rb.tt
116
132
  - lib/adapt/generators/intent/intent_generator.rb
117
133
  - lib/adapt/generators/intent/templates/intents/adapt/routing.adapt.rb.tt
134
+ - lib/adapt/helpers/en_parser.rb
135
+ - lib/adapt/helpers/parser.rb
118
136
  - lib/adapt/processor.rb
119
137
  - lib/adapt/routing_builder.rb
120
138
  - lib/adapt/version.rb