attentive 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attentive/entities/core/date/future.rb +2 -1
- data/lib/attentive/entities/core/date/past.rb +2 -1
- data/lib/attentive/entity.rb +4 -0
- data/lib/attentive/version.rb +1 -1
- data/lib/attentive.rb +11 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ed20d6d06d7bd6ed7310ce2a21b1845147c85e0
|
4
|
+
data.tar.gz: 5c9d38c8b0d02e2df99e05b0079b61da0d844a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5332983ceaa6b98858a9fb25ad013bea52e446b677030980263fdd0d058d79fb8d6ad0a41c07a1c991787f3dc6f866790a8d854a3d4a9817862bfd4b1af9bf6
|
7
|
+
data.tar.gz: edceb04320ea91fc4b416554d3cbbd03bbce2872f3f0e3387e78480e10fc06b1ef54e88a63a1e3f05469872a90235ed55ca82bdf99816c0774bce24ee3ffaa5a
|
data/lib/attentive/entity.rb
CHANGED
data/lib/attentive/version.rb
CHANGED
data/lib/attentive.rb
CHANGED
@@ -23,13 +23,20 @@ module Attentive
|
|
23
23
|
entities = Attentive::Entity.entities.map { |entity| Attentive::Phrase.new([entity.new]) }
|
24
24
|
i = 0
|
25
25
|
while i < message.tokens.length
|
26
|
-
entities.
|
26
|
+
abstractions = entities.each_with_object({}) do |entity, abstractions|
|
27
27
|
match = Attentive::Matcher.new(entity, Cursor.new(message, i)).match!
|
28
|
-
|
28
|
+
abstractions[entity[0].name.to_s] = { entity: entity, match: match } if match
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
# Pick the most abstract entity: if we match both
|
32
|
+
# {{core.date}} and {{core.date.past}}, use {{core.date}}
|
33
|
+
if abstractions.any?
|
34
|
+
keys = abstractions.keys
|
35
|
+
keys.reject! { |key| keys.any? { |other_key| key != other_key && key.start_with?(other_key) } }
|
36
|
+
abstraction = abstractions[keys.first]
|
37
|
+
i = abstraction[:match].replace_with(abstraction[:entity])
|
32
38
|
end
|
39
|
+
|
33
40
|
i += 1
|
34
41
|
end
|
35
42
|
message.tokens.to_s
|