attentive 0.1.0.beta1 → 0.1.0
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 +4 -4
- data/README.md +18 -2
- data/Rakefile +59 -0
- data/attentive.gemspec +1 -1
- data/lib/attentive.rb +11 -2
- data/lib/attentive/abbreviations.rb +3 -0
- data/lib/attentive/config.rb +11 -0
- data/lib/attentive/contractions.rb +3 -0
- data/lib/attentive/entities/relative_date.rb +2 -2
- data/lib/attentive/entity.rb +1 -1
- data/lib/attentive/listener.rb +2 -6
- data/lib/attentive/listener_collection.rb +9 -10
- data/lib/attentive/match.rb +5 -2
- data/lib/attentive/matcher.rb +5 -2
- data/lib/attentive/message.rb +2 -1
- data/lib/attentive/text.rb +0 -39
- data/lib/attentive/token.rb +2 -2
- data/lib/attentive/tokenizer.rb +7 -5
- data/lib/attentive/tokens.rb +3 -3
- data/lib/attentive/tokens/{me.rb → invocation.rb} +4 -3
- data/lib/attentive/version.rb +1 -1
- metadata +8 -7
- data/data/contractions.tsv +0 -134
- data/data/slang.tsv +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f08339af1a0af46d0ed601f66c0fa93196d3921
|
4
|
+
data.tar.gz: 77b5040ac0c4b37a9dad94a60e7e8d196f9718ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d81240212f8cef0eeaf6f69f3cbf1512b3870dc11e8205555384b2bbb1584717b8f23795ad1d38de1fbd486c3d34e4090d143f37f31ce8ac5d82268cc327565
|
7
|
+
data.tar.gz: 34dff8d29cc4b5b1f674a29032dabcd9d0bbd50068616ea2fe9e09e0ae05f77818d94ddaa431363f4aeedcf2a5348256f4dddd57cd296f46a40a4ccf954cb123
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
4
4
|
|
5
5
|
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
|
+
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -20,9 +22,21 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
$ gem install attentive
|
22
24
|
|
25
|
+
|
26
|
+
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
```ruby
|
30
|
+
include Attentive
|
31
|
+
|
32
|
+
listen_for "hi there!" do
|
33
|
+
puts "heard greeting"
|
34
|
+
end
|
35
|
+
|
36
|
+
hear "hi, there :wink:"
|
37
|
+
```
|
38
|
+
|
39
|
+
|
26
40
|
|
27
41
|
## Development
|
28
42
|
|
@@ -30,12 +44,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
44
|
|
31
45
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
46
|
|
47
|
+
|
48
|
+
|
33
49
|
## Contributing
|
34
50
|
|
35
51
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/attentive.
|
36
52
|
|
37
53
|
|
54
|
+
|
38
55
|
## License
|
39
56
|
|
40
57
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/Rakefile
CHANGED
@@ -7,4 +7,63 @@ Rake::TestTask.new(:test) do |t|
|
|
7
7
|
t.test_files = FileList['test/**/*_test.rb']
|
8
8
|
end
|
9
9
|
|
10
|
+
namespace :compile do
|
11
|
+
|
12
|
+
desc "Compile contractions.rb and abbreviations.rb"
|
13
|
+
task :data do
|
14
|
+
|
15
|
+
data_path = File.expand_path(File.dirname(__FILE__) + "/data")
|
16
|
+
output_path = File.expand_path(File.dirname(__FILE__) + "/lib/attentive")
|
17
|
+
|
18
|
+
contractions = {}
|
19
|
+
File.open(data_path + "/contractions.tsv") do |file|
|
20
|
+
file.each do |line|
|
21
|
+
next if line.start_with?("#") # skip comments
|
22
|
+
next if line == "\n" # skip blank lines
|
23
|
+
|
24
|
+
# the file contains tab-separated values.
|
25
|
+
# the first value is the contraction.
|
26
|
+
# the remaining values are possible phrases that match it
|
27
|
+
phrases = line.downcase.chomp.split("\t")
|
28
|
+
raise "#{line.inspect} must have exactly two values" unless phrases.length >= 2
|
29
|
+
|
30
|
+
contractions[phrases.shift] = phrases
|
31
|
+
end
|
32
|
+
end
|
33
|
+
File.open(output_path + "/contractions.rb", "w") do |file|
|
34
|
+
file.write <<-RUBY
|
35
|
+
module Attentive
|
36
|
+
CONTRACTIONS = #{contractions.inspect}.freeze
|
37
|
+
end
|
38
|
+
RUBY
|
39
|
+
end
|
40
|
+
|
41
|
+
abbreviations = {}
|
42
|
+
File.open(data_path + "/abbreviations.tsv") do |file|
|
43
|
+
file.each do |line|
|
44
|
+
next if line.start_with?("#") # skip comments
|
45
|
+
next if line == "\n" # skip blank lines
|
46
|
+
|
47
|
+
# the file contains tab-separated values.
|
48
|
+
# every line should have exactly two values:
|
49
|
+
# + the first is the slang word
|
50
|
+
# + the second is the normal word
|
51
|
+
words = line.downcase.chomp.split("\t")
|
52
|
+
raise "#{line.inspect} must have exactly two values" unless words.length == 2
|
53
|
+
|
54
|
+
abbreviations[words[0]] = words[1]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
File.open(output_path + "/abbreviations.rb", "w") do |file|
|
58
|
+
file.write <<-RUBY
|
59
|
+
module Attentive
|
60
|
+
ABBREVIATIONS = #{abbreviations.inspect}.freeze
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
10
69
|
task :default => :spec
|
data/attentive.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/houston/attentive"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(data|test|spec|features)/}) }
|
17
17
|
spec.bindir = "exe"
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
data/lib/attentive.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
require "attentive/version"
|
2
|
-
require "attentive/
|
3
|
-
require "attentive/message"
|
2
|
+
require "attentive/config"
|
4
3
|
|
5
4
|
module Attentive
|
5
|
+
extend Attentive::Config
|
6
|
+
|
7
|
+
# Default configuration
|
8
|
+
self.invocations = ["@me".freeze]
|
9
|
+
|
10
|
+
|
11
|
+
# Attentive DSL
|
6
12
|
|
7
13
|
def listeners
|
8
14
|
@listeners ||= Attentive::ListenerCollection.new
|
@@ -18,3 +24,6 @@ module Attentive
|
|
18
24
|
end
|
19
25
|
|
20
26
|
end
|
27
|
+
|
28
|
+
require "attentive/listener_collection"
|
29
|
+
require "attentive/message"
|
@@ -0,0 +1,3 @@
|
|
1
|
+
module Attentive
|
2
|
+
ABBREVIATIONS = {"bye"=>"goodbye", "gonna"=>"going to", "hi"=>"hello", "ol'"=>"old", "'sup"=>"what is up", "thanks"=>"thank you", "wanna"=>"want to", "mon"=>"monday", "tue"=>"tuesday", "tues"=>"tuesday", "wed"=>"wednesday", "thu"=>"thursday", "thur"=>"thursday", "thurs"=>"thursday", "fri"=>"friday", "sat"=>"saturday", "sun"=>"sunday"}.freeze
|
3
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
module Attentive
|
2
|
+
CONTRACTIONS = {"ain't"=>["am not"], "aren't"=>["are not"], "can't"=>["can not"], "cannot"=>["can not"], "could've"=>["could have"], "couldn't"=>["could not"], "couldn't've"=>["could not have"], "didn't"=>["did not"], "doesn't"=>["does not"], "don't"=>["do not"], "hadn't"=>["had not"], "hadn't've"=>["had not have"], "hasn't"=>["has not"], "haven't"=>["have not"], "he'd"=>["he had", "he would"], "he'd've"=>["he would have"], "he'll"=>["he will", "he shall"], "he's"=>["he is", "he has"], "he'sn't"=>["he is not", "he has not"], "how'd"=>["how did", "how would"], "how'll"=>["how will"], "how's"=>["how is", "how has", "how does"], "i'd"=>["i would", "i had"], "i'd've"=>["i would have"], "i'll"=>["i shall", "i will"], "i'm"=>["i am"], "i've"=>["i have"], "i'ven't"=>["i have not"], "isn't"=>["is not"], "it'd"=>["it would", "it had"], "it'd've"=>["it would have"], "it'll"=>["it will", "it shall"], "it's"=>["it is", "it has"], "it'sn't"=>["it is not", "it has not"], "let's"=>["let us"], "ma'am"=>["madam"], "mightn't"=>["might not"], "mightn't've"=>["might not have"], "might've"=>["might have"], "mustn't"=>["must not"], "must've"=>["must have"], "needn't"=>["need not"], "not've"=>["not have"], "o'clock"=>["of the clock"], "oughtn't"=>["ought not"], "shan't"=>["shall not"], "she'd"=>["she had", "she would"], "she'd've"=>["she would have"], "she'll"=>["she shall", "she will"], "she's"=>["she is", "she has"], "she'sn't"=>["she is not", "she has not"], "should've"=>["should have"], "shouldn't"=>["should not"], "shouldn't've"=>["should not have"], "somebody'd"=>["somebody had", "somebody would"], "somebody'd've"=>["somebody would have"], "somebody'dn't've"=>["somebody would not have"], "somebody'll"=>["somebody shall", "somebody will"], "somebody's"=>["somebody is", "somebody has"], "someone'd"=>["someone had", "someone would"], "someone'd've"=>["someone would have"], "someone'll"=>["someone shall", "someone will"], "someone's"=>["someone is", "someone has"], "something'd"=>["something had", "something would"], "something'd've"=>["something would have"], "something'll"=>["something shall", "something will"], "something's"=>["something is", "something has"], "that'll"=>["that will"], "that's"=>["that is", "that has"], "there'd"=>["there had", "there would"], "there'd've"=>["there would have"], "there're"=>["there are"], "there's"=>["there is", "there has"], "they'd"=>["they would", "they had"], "they'dn't"=>["they would not"], "they'dn't've"=>["they would not have"], "they'd've"=>["they would have"], "they'd'ven't"=>["they would have not"], "they'll"=>["they shall", "they will"], "they'lln't've"=>["they will not have"], "they'll'ven't"=>["they will have not"], "they're"=>["they are"], "they've"=>["they have"], "they'ven't"=>["they have not"], "'tis"=>["it is"], "'twas"=>["it was"], "wasn't"=>["was not"], "we'd"=>["we had", "we would"], "we'd've"=>["we would have"], "we'dn't've"=>["we would not have"], "we'll"=>["we will"], "we'lln't've"=>["we will not have"], "we're"=>["we are"], "we've"=>["we have"], "weren't"=>["were not"], "what'll"=>["what shall", "what will"], "what're"=>["what are"], "what's"=>["what is", "what does", "what has"], "what've"=>["what have"], "when's"=>["when is", "when has"], "where'd"=>["where did"], "where's"=>["where is", "where does", "where has"], "where've"=>["where have"], "who'd"=>["who would", "who had"], "who'd've"=>["who would have"], "who'll"=>["who shall", "who will"], "who're"=>["who are"], "who's"=>["who is", "who has"], "who've"=>["who have"], "why'll"=>["why will"], "why're"=>["why are"], "why's"=>["why is", "why has"], "won't"=>["will not"], "won't've"=>["will not have"], "would've"=>["would have"], "wouldn't"=>["would not"], "wouldn't've"=>["would not have"], "y'all"=>["you all"], "y'all'd've"=>["you all would have"], "y'all'dn't've"=>["you all would not have"], "y'all'll"=>["you all will"], "y'all'lln't"=>["you all will not"], "y'all'll've"=>["you all will have"], "y'all'll'ven't"=>["you all will have not"], "you'd"=>["you had", "you would"], "you'd've"=>["you would have"], "you'll"=>["you shall", "you will"], "you're"=>["you are"], "you'ren't"=>["you are not"], "you've"=>["you have"], "you'ven't"=>["you have not"]}.freeze
|
3
|
+
end
|
@@ -27,7 +27,7 @@ Attentive::Entity.define :"relative-date",
|
|
27
27
|
when /^thu/ then next_wday[4]
|
28
28
|
when /^fri/ then next_wday[5]
|
29
29
|
when /^sat/ then next_wday[6]
|
30
|
-
else raise NotImplementedError, "
|
30
|
+
else raise NotImplementedError, "Unrecognized weekday: #{weekday.inspect}"
|
31
31
|
end
|
32
32
|
|
33
33
|
date += 7 if match.to_s.start_with?("next")
|
@@ -38,7 +38,7 @@ Attentive::Entity.define :"relative-date",
|
|
38
38
|
when "today" then today
|
39
39
|
when "tomorrow" then today + 1
|
40
40
|
when "yesterday" then today - 1
|
41
|
-
else raise NotImplementedError, "
|
41
|
+
else raise NotImplementedError, "Unrecognized match: #{match.to_s}"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/lib/attentive/entity.rb
CHANGED
data/lib/attentive/listener.rb
CHANGED
@@ -6,10 +6,7 @@ module Attentive
|
|
6
6
|
class Listener
|
7
7
|
attr_reader :phrases
|
8
8
|
|
9
|
-
def initialize(listeners,
|
10
|
-
options = args.last.is_a?(::Hash) ? args.pop : {}
|
11
|
-
|
12
|
-
# Ugh!
|
9
|
+
def initialize(listeners, phrases, options, callback)
|
13
10
|
context_options = options.fetch(:context, {})
|
14
11
|
@required_contexts = context_options.fetch(:in, %i{conversation})
|
15
12
|
@required_contexts = [] if @required_contexts == :any
|
@@ -18,8 +15,8 @@ module Attentive
|
|
18
15
|
@prohibited_contexts = Set[*@prohibited_contexts]
|
19
16
|
|
20
17
|
@listeners = listeners
|
18
|
+
@phrases = tokenize_phrases!(phrases)
|
21
19
|
@callback = callback
|
22
|
-
@phrases = tokenize_phrases!(args)
|
23
20
|
end
|
24
21
|
|
25
22
|
def matches_context?(message)
|
@@ -47,7 +44,6 @@ module Attentive
|
|
47
44
|
end
|
48
45
|
|
49
46
|
def tokenize_phrase!(phrase)
|
50
|
-
# should this be {regexps: false}?
|
51
47
|
Attentive::Tokenizer.tokenize(phrase, entities: true, regexps: true, ambiguous: false)
|
52
48
|
end
|
53
49
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "attentive"
|
1
2
|
require "thread_safe"
|
2
3
|
require "delegate"
|
3
4
|
require "attentive/cursor"
|
@@ -12,19 +13,13 @@ module Attentive
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def listen_for(*args, &block)
|
15
|
-
|
16
|
-
push listener
|
17
|
-
end
|
18
|
-
end
|
16
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
19
17
|
|
20
|
-
|
21
|
-
Listener.new(self, args, block).tap do |listener|
|
18
|
+
Attentive::Listener.new(self, args, options, block).tap do |listener|
|
22
19
|
push listener
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
23
|
def hear(message)
|
29
24
|
listeners = select { |listener| listener.matches_context?(message) }
|
30
25
|
|
@@ -33,8 +28,12 @@ module Attentive
|
|
33
28
|
message.tokens.each_with_index do |token, i|
|
34
29
|
listeners.each do |listener|
|
35
30
|
listener.phrases.each do |phrase|
|
36
|
-
match = Attentive::Matcher.new(phrase, Cursor.new(message.tokens, i)).match!
|
37
|
-
|
31
|
+
match = Attentive::Matcher.new(phrase, Cursor.new(message.tokens, i), listener: listener, message: message).match!
|
32
|
+
next unless match
|
33
|
+
|
34
|
+
# Don't match more than one phrase per listener
|
35
|
+
matches.push match
|
36
|
+
break
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
data/lib/attentive/match.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
module Attentive
|
2
2
|
class Match
|
3
|
+
attr_reader :listener, :phrase, :message
|
3
4
|
|
4
5
|
def initialize(phrase, attributes={})
|
5
6
|
@phrase = phrase.to_s
|
6
7
|
@match_data = attributes.fetch(:match_data, {})
|
8
|
+
@listener = attributes[:listener]
|
9
|
+
@message = attributes[:message]
|
7
10
|
end
|
8
11
|
|
9
12
|
def matched?(variable_name)
|
10
|
-
@match_data.key?
|
13
|
+
@match_data.key? variable_name.to_s
|
11
14
|
end
|
12
15
|
|
13
16
|
def [](variable_name)
|
14
|
-
@match_data.fetch
|
17
|
+
@match_data.fetch variable_name.to_s
|
15
18
|
end
|
16
19
|
|
17
20
|
def to_s
|
data/lib/attentive/matcher.rb
CHANGED
@@ -8,6 +8,7 @@ module Attentive
|
|
8
8
|
@phrase = phrase
|
9
9
|
@cursor = cursor
|
10
10
|
@pos = params.fetch(:pos, 0)
|
11
|
+
@match_params = params.each_with_object({}) { |(key, value), new_hash| new_hash[key] = value if %i{listener message}.member?(key) }
|
11
12
|
@pos += 1 while phrase[pos] && phrase[pos].whitespace?
|
12
13
|
@match_data = {}
|
13
14
|
@state = :matching
|
@@ -46,8 +47,10 @@ module Attentive
|
|
46
47
|
end
|
47
48
|
@pos += 1 while phrase[pos] && phrase[pos].whitespace?
|
48
49
|
@state = :found
|
49
|
-
|
50
|
-
|
50
|
+
|
51
|
+
|
52
|
+
# -> This is the one spot where we instantiate a Match
|
53
|
+
return Attentive::Match.new(phrase, @match_params.merge(match_data: @match_data)) if pos == phrase.length
|
51
54
|
|
52
55
|
elsif !token.skippable?
|
53
56
|
@state = :mismatch
|
data/lib/attentive/message.rb
CHANGED
@@ -5,9 +5,10 @@ module Attentive
|
|
5
5
|
class Message
|
6
6
|
attr_reader :contexts, :text
|
7
7
|
|
8
|
-
def initialize(text, params)
|
8
|
+
def initialize(text, params={})
|
9
9
|
@text = text
|
10
10
|
@contexts = Set.new(params.fetch(:contexts, []))
|
11
|
+
contexts << :conversation if tokens.grep(Attentive::Tokens::Invocation).any?
|
11
12
|
end
|
12
13
|
|
13
14
|
def tokens
|
data/lib/attentive/text.rb
CHANGED
@@ -14,44 +14,5 @@ module Attentive
|
|
14
14
|
text.gsub(/[“”]/, "\"").gsub(/[‘’]/, "'")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
DATA_PATH = File.expand_path(File.dirname(__FILE__) + "/../../data").freeze
|
20
|
-
|
21
|
-
CONTRACTIONS = {}.tap do |contractions|
|
22
|
-
File.open(DATA_PATH + "/contractions.tsv") do |file|
|
23
|
-
file.each do |line|
|
24
|
-
next if line.start_with?("#") # skip comments
|
25
|
-
next if line == "\n" # skip blank lines
|
26
|
-
|
27
|
-
# the file contains tab-separated values.
|
28
|
-
# the first value is the contraction.
|
29
|
-
# the remaining values are possible phrases that match it
|
30
|
-
phrases = line.chomp.split("\t")
|
31
|
-
raise "#{line.inspect} must have exactly two values" unless phrases.length >= 2
|
32
|
-
|
33
|
-
contractions[phrases.shift] = phrases
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end.freeze
|
37
|
-
|
38
|
-
SLANG = {}.tap do |slang|
|
39
|
-
File.open(DATA_PATH + "/slang.tsv") do |file|
|
40
|
-
file.each do |line|
|
41
|
-
next if line.start_with?("#") # skip comments
|
42
|
-
next if line == "\n" # skip blank lines
|
43
|
-
|
44
|
-
# the file contains tab-separated values.
|
45
|
-
# every line should have exactly two values:
|
46
|
-
# + the first is the slang word
|
47
|
-
# + the second is the normal word
|
48
|
-
words = line.chomp.split("\t")
|
49
|
-
raise "#{line.inspect} must have exactly two values" unless words.length == 2
|
50
|
-
|
51
|
-
slang[words[0]] = words[1]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end.freeze
|
55
|
-
|
56
17
|
end
|
57
18
|
end
|
data/lib/attentive/token.rb
CHANGED
@@ -2,7 +2,7 @@ module Attentive
|
|
2
2
|
class Token
|
3
3
|
attr_reader :pos
|
4
4
|
|
5
|
-
def initialize(pos)
|
5
|
+
def initialize(pos=nil)
|
6
6
|
@pos = pos
|
7
7
|
end
|
8
8
|
|
@@ -37,7 +37,7 @@ module Attentive
|
|
37
37
|
class StringToken < Token
|
38
38
|
attr_reader :string
|
39
39
|
|
40
|
-
def initialize(string, pos)
|
40
|
+
def initialize(string, pos=nil)
|
41
41
|
@string = string
|
42
42
|
super pos
|
43
43
|
end
|
data/lib/attentive/tokenizer.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require "attentive/abbreviations"
|
2
|
+
require "attentive/contractions"
|
1
3
|
require "attentive/text"
|
2
4
|
require "attentive/tokens"
|
3
5
|
require "attentive/phrase"
|
4
6
|
require "attentive/errors"
|
5
7
|
|
8
|
+
|
6
9
|
module Attentive
|
7
10
|
class Tokenizer
|
8
11
|
extend Attentive::Tokens
|
@@ -14,7 +17,6 @@ module Attentive
|
|
14
17
|
SPLITTER = /(\n|{{|}}|\s+|\.{2,}|[^\s\w'@-])/.freeze
|
15
18
|
PUNCTUATION = /^\W+$/.freeze
|
16
19
|
WHITESPACE = /^\s+$/.freeze
|
17
|
-
ME = "@me".freeze
|
18
20
|
ENTITY_START = "{{".freeze
|
19
21
|
ENTITY_END = "}}".freeze
|
20
22
|
REGEXP_START = "(".freeze
|
@@ -109,14 +111,14 @@ module Attentive
|
|
109
111
|
when PUNCTUATION
|
110
112
|
tokens << punctuation(string, pos: pos)
|
111
113
|
|
112
|
-
when
|
113
|
-
tokens <<
|
114
|
+
when *Attentive.invocations
|
115
|
+
tokens << invocation(string, pos: pos)
|
114
116
|
|
115
117
|
else
|
116
|
-
if replace_with = Attentive::
|
118
|
+
if replace_with = Attentive::ABBREVIATIONS[string]
|
117
119
|
tokens.concat tokenize(replace_with, options)
|
118
120
|
|
119
|
-
elsif expands_to = Attentive::
|
121
|
+
elsif expands_to = Attentive::CONTRACTIONS[string]
|
120
122
|
possibilities = expands_to.map do |possibility|
|
121
123
|
tokenize(possibility, options)
|
122
124
|
end
|
data/lib/attentive/tokens.rb
CHANGED
@@ -13,8 +13,8 @@ module Attentive
|
|
13
13
|
Attentive::Entity[entity_name.to_sym].new(variable_name)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
Attentive::Tokens::
|
16
|
+
def invocation(string, pos: nil)
|
17
|
+
Attentive::Tokens::Invocation.new string, pos
|
18
18
|
end
|
19
19
|
|
20
20
|
def punctuation(string, pos: nil)
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
|
39
39
|
require "attentive/tokens/any_of"
|
40
40
|
require "attentive/tokens/emoji"
|
41
|
-
require "attentive/tokens/
|
41
|
+
require "attentive/tokens/invocation"
|
42
42
|
require "attentive/tokens/punctuation"
|
43
43
|
require "attentive/tokens/regexp"
|
44
44
|
require "attentive/tokens/whitespace"
|
@@ -2,10 +2,11 @@ require "attentive/token"
|
|
2
2
|
|
3
3
|
module Attentive
|
4
4
|
module Tokens
|
5
|
-
class
|
5
|
+
class Invocation < StringToken
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# All invocations are equal
|
8
|
+
def ==(other)
|
9
|
+
self.class == other.class
|
9
10
|
end
|
10
11
|
|
11
12
|
def skippable?
|
data/lib/attentive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attentive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thread_safe
|
@@ -152,10 +152,11 @@ files:
|
|
152
152
|
- attentive.gemspec
|
153
153
|
- bin/console
|
154
154
|
- bin/setup
|
155
|
-
- data/contractions.tsv
|
156
|
-
- data/slang.tsv
|
157
155
|
- lib/attentive.rb
|
156
|
+
- lib/attentive/abbreviations.rb
|
158
157
|
- lib/attentive/composite_entity.rb
|
158
|
+
- lib/attentive/config.rb
|
159
|
+
- lib/attentive/contractions.rb
|
159
160
|
- lib/attentive/cursor.rb
|
160
161
|
- lib/attentive/entities/integer.rb
|
161
162
|
- lib/attentive/entities/relative_date.rb
|
@@ -173,7 +174,7 @@ files:
|
|
173
174
|
- lib/attentive/tokens.rb
|
174
175
|
- lib/attentive/tokens/any_of.rb
|
175
176
|
- lib/attentive/tokens/emoji.rb
|
176
|
-
- lib/attentive/tokens/
|
177
|
+
- lib/attentive/tokens/invocation.rb
|
177
178
|
- lib/attentive/tokens/punctuation.rb
|
178
179
|
- lib/attentive/tokens/regexp.rb
|
179
180
|
- lib/attentive/tokens/whitespace.rb
|
@@ -194,9 +195,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
195
|
version: '0'
|
195
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
197
|
requirements:
|
197
|
-
- - "
|
198
|
+
- - ">="
|
198
199
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
200
|
+
version: '0'
|
200
201
|
requirements: []
|
201
202
|
rubyforge_project:
|
202
203
|
rubygems_version: 2.2.2
|
data/data/contractions.tsv
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
# List of English Contractions
|
2
|
-
# https://en.wikipedia.org/wiki/Wikipedia:List_of_English_contractions
|
3
|
-
|
4
|
-
ain't am not
|
5
|
-
aren't are not
|
6
|
-
can't can not
|
7
|
-
cannot can not
|
8
|
-
could've could have
|
9
|
-
couldn't could not
|
10
|
-
couldn't've could not have
|
11
|
-
didn't did not
|
12
|
-
doesn't does not
|
13
|
-
don't do not
|
14
|
-
hadn't had not
|
15
|
-
hadn't've had not have
|
16
|
-
hasn't has not
|
17
|
-
haven't have not
|
18
|
-
he'd he had he would
|
19
|
-
he'd've he would have
|
20
|
-
he'll he will he shall
|
21
|
-
he's he is he has
|
22
|
-
he'sn't he is not he has not
|
23
|
-
how'd how did how would
|
24
|
-
how'll how will
|
25
|
-
how's how is how has how does
|
26
|
-
I'd I would I had
|
27
|
-
I'd've I would have
|
28
|
-
I'll I shall I will
|
29
|
-
I'm I am
|
30
|
-
I've I have
|
31
|
-
I'ven't I have not
|
32
|
-
isn't is not
|
33
|
-
it'd it would it had
|
34
|
-
it'd've it would have
|
35
|
-
it'll it will it shall
|
36
|
-
it's it is it has
|
37
|
-
it'sn't it is not it has not
|
38
|
-
let's let us
|
39
|
-
ma'am madam
|
40
|
-
mightn't might not
|
41
|
-
mightn't've might not have
|
42
|
-
might've might have
|
43
|
-
mustn't must not
|
44
|
-
must've must have
|
45
|
-
needn't need not
|
46
|
-
not've not have
|
47
|
-
o'clock of the clock
|
48
|
-
oughtn't ought not
|
49
|
-
shan't shall not
|
50
|
-
she'd she had she would
|
51
|
-
she'd've she would have
|
52
|
-
she'll she shall she will
|
53
|
-
she's she is she has
|
54
|
-
she'sn't she is not she has not
|
55
|
-
should've should have
|
56
|
-
shouldn't should not
|
57
|
-
shouldn't've should not have
|
58
|
-
somebody'd somebody had somebody would
|
59
|
-
somebody'd've somebody would have
|
60
|
-
somebody'dn't've somebody would not have
|
61
|
-
somebody'll somebody shall somebody will
|
62
|
-
somebody's somebody is somebody has
|
63
|
-
someone'd someone had someone would
|
64
|
-
someone'd've someone would have
|
65
|
-
someone'll someone shall someone will
|
66
|
-
someone's someone is someone has
|
67
|
-
something'd something had something would
|
68
|
-
something'd've something would have
|
69
|
-
something'll something shall something will
|
70
|
-
something's something is something has
|
71
|
-
that'll that will
|
72
|
-
that's that is that has
|
73
|
-
there'd there had there would
|
74
|
-
there'd've there would have
|
75
|
-
there're there are
|
76
|
-
there's there is there has
|
77
|
-
they'd they would they had
|
78
|
-
they'dn't they would not
|
79
|
-
they'dn't've they would not have
|
80
|
-
they'd've they would have
|
81
|
-
they'd'ven't they would have not
|
82
|
-
they'll they shall they will
|
83
|
-
they'lln't've they will not have
|
84
|
-
they'll'ven't they will have not
|
85
|
-
they're they are
|
86
|
-
they've they have
|
87
|
-
they'ven't they have not
|
88
|
-
'tis it is
|
89
|
-
'twas it was
|
90
|
-
wasn't was not
|
91
|
-
we'd we had we would
|
92
|
-
we'd've we would have
|
93
|
-
we'dn't've we would not have
|
94
|
-
we'll we will
|
95
|
-
we'lln't've we will not have
|
96
|
-
we're we are
|
97
|
-
we've we have
|
98
|
-
weren't were not
|
99
|
-
what'll what shall what will
|
100
|
-
what're what are
|
101
|
-
what's what is what does what has
|
102
|
-
what've what have
|
103
|
-
when's when is when has
|
104
|
-
where'd where did
|
105
|
-
where's where is where does where has
|
106
|
-
where've where have
|
107
|
-
who'd who would who had
|
108
|
-
who'd've who would have
|
109
|
-
who'll who shall who will
|
110
|
-
who're who are
|
111
|
-
who's who is who has
|
112
|
-
who've who have
|
113
|
-
why'll why will
|
114
|
-
why're why are
|
115
|
-
why's why is why has
|
116
|
-
won't will not
|
117
|
-
won't've will not have
|
118
|
-
would've would have
|
119
|
-
wouldn't would not
|
120
|
-
wouldn't've would not have
|
121
|
-
y'all you all
|
122
|
-
y'all'd've you all would have
|
123
|
-
y'all'dn't've you all would not have
|
124
|
-
y'all'll you all will
|
125
|
-
y'all'lln't you all will not
|
126
|
-
y'all'll've you all will have
|
127
|
-
y'all'll'ven't you all will have not
|
128
|
-
you'd you had you would
|
129
|
-
you'd've you would have
|
130
|
-
you'll you shall you will
|
131
|
-
you're you are
|
132
|
-
you'ren't you are not
|
133
|
-
you've you have
|
134
|
-
you'ven't you have not
|
data/data/slang.tsv
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Slang / Shorthand
|
2
|
-
|
3
|
-
bye goodbye
|
4
|
-
gonna going to
|
5
|
-
hi hello
|
6
|
-
ol' old
|
7
|
-
'sup what is up
|
8
|
-
thanks thank you
|
9
|
-
wanna want to
|
10
|
-
mon monday
|
11
|
-
tue tuesday
|
12
|
-
tues tuesday
|
13
|
-
wed wednesday
|
14
|
-
thu thursday
|
15
|
-
thur thursday
|
16
|
-
thurs thursday
|
17
|
-
fri friday
|
18
|
-
sat saturday
|
19
|
-
sun sunday
|