attentive 0.3.0 → 0.3.1

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: 880167573144b1749ba6f538a4922210ff5e087b
4
- data.tar.gz: 4b50dad29e7eacdf650c58741230d90c44c75c9b
3
+ metadata.gz: 0ed20d6d06d7bd6ed7310ce2a21b1845147c85e0
4
+ data.tar.gz: 5c9d38c8b0d02e2df99e05b0079b61da0d844a97
5
5
  SHA512:
6
- metadata.gz: b89a7ed8760e5e5acc8104c27f2d059fe82a05983fc29d077efabaf25b8cdc4ded15be16e601b1b9e9f94d902bebe5c30908d4d8d1e6311a8e92b24bf7e6cf16
7
- data.tar.gz: d440c72708774dedbecf2117e4838ad97e2aaa13ebebdada905ccee018bebebc47cc1f3e3f7d6c5d15834a28279a709adec3164facb703779be0392c0c7aab0e
6
+ metadata.gz: e5332983ceaa6b98858a9fb25ad013bea52e446b677030980263fdd0d058d79fb8d6ad0a41c07a1c991787f3dc6f866790a8d854a3d4a9817862bfd4b1af9bf6
7
+ data.tar.gz: edceb04320ea91fc4b416554d3cbbd03bbce2872f3f0e3387e78480e10fc06b1ef54e88a63a1e3f05469872a90235ed55ca82bdf99816c0774bce24ee3ffaa5a
@@ -7,4 +7,5 @@ require "attentive/entities/core/date/explicit"
7
7
  Attentive::CompositeEntity.define "core.date.future",
8
8
  "core.date.explicit",
9
9
  "core.date.relative.future",
10
- "core.date.partial.future"
10
+ "core.date.partial.future",
11
+ published: false
@@ -7,4 +7,5 @@ require "attentive/entities/core/date/explicit"
7
7
  Attentive::CompositeEntity.define "core.date.past",
8
8
  "core.date.explicit",
9
9
  "core.date.relative.past",
10
- "core.date.partial.past"
10
+ "core.date.partial.past",
11
+ published: false
@@ -72,6 +72,10 @@ module Attentive
72
72
  super pos
73
73
  end
74
74
 
75
+ def name
76
+ self.class.token_name
77
+ end
78
+
75
79
  def ==(other)
76
80
  self.class == other.class && self.variable_name == other.variable_name
77
81
  end
@@ -1,3 +1,3 @@
1
1
  module Attentive
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.each do |entity|
26
+ abstractions = entities.each_with_object({}) do |entity, abstractions|
27
27
  match = Attentive::Matcher.new(entity, Cursor.new(message, i)).match!
28
- next unless match
28
+ abstractions[entity[0].name.to_s] = { entity: entity, match: match } if match
29
+ end
29
30
 
30
- i = match.replace_with(entity)
31
- break
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attentive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail