aho_corasick 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ spec = Gem::Specification.new do |s|
19
19
 
20
20
  # Change these as appropriate
21
21
  s.name = "aho_corasick"
22
- s.version = "0.0.1"
22
+ s.version = "0.0.2"
23
23
  s.summary = "The Aho-Corasick string-matching algorithm"
24
24
  s.author = "Tim Cowlishaw"
25
25
  s.email = "tim@timcowlishaw.co.uk"
data/lib/aho_corasick.rb CHANGED
@@ -9,7 +9,7 @@ class AhoCorasick
9
9
  matches = []
10
10
  node = string.each_char.inject(@root) do |node, char|
11
11
  matches += node.matches if node
12
- (node && node.find(char)) || @root.find(char)
12
+ (node && node.find(char.to_sym)) || @root.find(char.to_sym)
13
13
  end
14
14
  matches += node.matches if node
15
15
  return matches
@@ -24,7 +24,7 @@ class AhoCorasick
24
24
 
25
25
  def unsafe_insert(terms)
26
26
  terms.each do |t|
27
- t.each_char.inject(@root) {|node, char| node.child_for(char) }.add_match(t)
27
+ t.each_char.inject(@root) {|node, char| node.child_for(char.to_sym) }.add_match(t)
28
28
  end
29
29
  end
30
30
 
@@ -32,7 +32,7 @@ class AhoCorasick
32
32
  queue = @root.children.to_a.dup
33
33
  while !queue.empty?
34
34
  char, node = queue.shift
35
- node.suffix = node.parent == @root ? @root : (node.parent.suffix && node.parent.suffix.children[char])
35
+ node.suffix = node.parent == @root ? @root : (node.parent.suffix && node.parent.suffix.children[char.to_sym])
36
36
  node.children.to_a.each do |entry|
37
37
  queue.push(entry)
38
38
  end
@@ -52,7 +52,7 @@ class AhoCorasick
52
52
 
53
53
 
54
54
  def find(char)
55
- @children[char] || (suffix && suffix.find(char))
55
+ @children[char.to_sym] || (suffix && suffix.find(char.to_sym))
56
56
  end
57
57
 
58
58
  def add_match(str)
@@ -60,7 +60,7 @@ class AhoCorasick
60
60
  end
61
61
 
62
62
  def child_for(char)
63
- @children[char] ||= TreeNode.new(self)
63
+ @children[char.to_sym] ||= TreeNode.new(self)
64
64
  end
65
65
 
66
66
  end
@@ -27,6 +27,11 @@ describe "AhoCorasick" do
27
27
  a.match("abcd").to_set.must_equal ["ab", "cd"].to_set
28
28
  end
29
29
 
30
+ it "matches terms directly following a partial match" do
31
+ a = AhoCorasick.new("abc", "de")
32
+ a.match("ade").must_include("de")
33
+ end
34
+
30
35
  it "returns terms added to the matcher after instantiation" do
31
36
  a = AhoCorasick.new("ab")
32
37
  a.insert("cd", "ef")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aho_corasick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-25 00:00:00.000000000Z
12
+ date: 2011-11-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &13072560 !ruby/object:Gem::Requirement
16
+ requirement: &12269020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *13072560
24
+ version_requirements: *12269020
25
25
  description:
26
26
  email: tim@timcowlishaw.co.uk
27
27
  executables: []
@@ -52,13 +52,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  segments:
54
54
  - 0
55
- hash: -4104333102682146250
55
+ hash: 3276065860397495026
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ segments:
63
+ - 0
64
+ hash: 3276065860397495026
62
65
  requirements: []
63
66
  rubyforge_project:
64
67
  rubygems_version: 1.8.10