aho-corasick-trie-search 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.drone.yml +27 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +95 -0
- data/README.md +90 -0
- data/Rakefile +6 -0
- data/act.gemspec +52 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/lib/act/act.rb +6 -0
- data/lib/act/trie.rb +135 -0
- data/lib/act/version.rb +3 -0
- data/lib/act/vertex.rb +68 -0
- metadata +217 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a644e1e23eca78c17a99cb5f2bbe13fe33592f113a9f5495acc08e61178142e
|
4
|
+
data.tar.gz: d000ba6f6f948daf099e524d10b5f413b1005839a45816a042d2c5e20006d3b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df6067ef38f5f07714fa88ec8a3b219a6148549148cf8fbc049b360e62cc699602cbb0627861348745261d7ebb9c7bfd62b0210ad5c55f3bea513820860303c2
|
7
|
+
data.tar.gz: c11478922a4efa1e0d27043f697923f5f86e232060511b9ea3c040b6b773e8b893a4c5583c54f640e1bb32575dcebcd57fb0ca299a8c379c77f5bccf50ab8f87
|
data/.drone.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
kind: pipeline
|
2
|
+
name: default
|
3
|
+
|
4
|
+
steps:
|
5
|
+
- name: install
|
6
|
+
image: ruby
|
7
|
+
volumes:
|
8
|
+
- name: bundle
|
9
|
+
path: /usr/local/bundle
|
10
|
+
commands:
|
11
|
+
- bundle install --jobs=3 --retry=3
|
12
|
+
|
13
|
+
- name: test
|
14
|
+
image: ruby
|
15
|
+
environment:
|
16
|
+
CODECOV_TOKEN:
|
17
|
+
from_secret: CODECOV_TOKEN
|
18
|
+
CI: true
|
19
|
+
volumes:
|
20
|
+
- name: bundle
|
21
|
+
path: /usr/local/bundle
|
22
|
+
commands:
|
23
|
+
- rake
|
24
|
+
|
25
|
+
volumes:
|
26
|
+
- name: bundle
|
27
|
+
temp: {}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aho-corasick-trie-search (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
ast (2.4.0)
|
11
|
+
benchmark-malloc (0.1.0)
|
12
|
+
benchmark-perf (0.5.0)
|
13
|
+
benchmark-trend (0.3.0)
|
14
|
+
codecov (0.1.14)
|
15
|
+
json
|
16
|
+
simplecov
|
17
|
+
url
|
18
|
+
coderay (1.1.2)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
docile (1.3.1)
|
21
|
+
hirb (0.7.3)
|
22
|
+
jaro_winkler (1.5.2)
|
23
|
+
json (2.2.0)
|
24
|
+
method_source (0.9.2)
|
25
|
+
parallel (1.17.0)
|
26
|
+
parser (2.6.3.0)
|
27
|
+
ast (~> 2.4.0)
|
28
|
+
pry (0.12.2)
|
29
|
+
coderay (~> 1.1.0)
|
30
|
+
method_source (~> 0.9.0)
|
31
|
+
psych (3.1.0)
|
32
|
+
rainbow (3.0.0)
|
33
|
+
rake (10.5.0)
|
34
|
+
rspec (3.8.0)
|
35
|
+
rspec-core (~> 3.8.0)
|
36
|
+
rspec-expectations (~> 3.8.0)
|
37
|
+
rspec-mocks (~> 3.8.0)
|
38
|
+
rspec-benchmark (0.5.0)
|
39
|
+
benchmark-malloc (~> 0.1.0)
|
40
|
+
benchmark-perf (~> 0.5.0)
|
41
|
+
benchmark-trend (~> 0.3.0)
|
42
|
+
rspec (>= 3.0.0, < 4.0.0)
|
43
|
+
rspec-collection_matchers (1.1.3)
|
44
|
+
rspec-expectations (>= 2.99.0.beta1)
|
45
|
+
rspec-core (3.8.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-expectations (3.8.3)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-mocks (3.8.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-support (3.8.0)
|
54
|
+
rubocop (0.67.2)
|
55
|
+
jaro_winkler (~> 1.5.1)
|
56
|
+
parallel (~> 1.10)
|
57
|
+
parser (>= 2.5, != 2.5.1.1)
|
58
|
+
psych (>= 3.1.0)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
62
|
+
rubocop-performance (1.1.0)
|
63
|
+
rubocop (>= 0.67.0)
|
64
|
+
ruby-progressbar (1.10.0)
|
65
|
+
simplecov (0.16.1)
|
66
|
+
docile (~> 1.1)
|
67
|
+
json (>= 1.8, < 3)
|
68
|
+
simplecov-html (~> 0.10.0)
|
69
|
+
simplecov-console (0.4.2)
|
70
|
+
ansi
|
71
|
+
hirb
|
72
|
+
simplecov
|
73
|
+
simplecov-html (0.10.2)
|
74
|
+
unicode-display_width (1.5.0)
|
75
|
+
url (0.3.2)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
aho-corasick-trie-search!
|
82
|
+
bundler (~> 1.17)
|
83
|
+
codecov
|
84
|
+
pry
|
85
|
+
rake (~> 10.0)
|
86
|
+
rspec (~> 3.0)
|
87
|
+
rspec-benchmark
|
88
|
+
rspec-collection_matchers (~> 1.1.0)
|
89
|
+
rubocop
|
90
|
+
rubocop-performance
|
91
|
+
simplecov
|
92
|
+
simplecov-console
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
1.17.2
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Aho-Corasick Trie Substring Search
|
2
|
+
|
3
|
+
[![Build Status](https://cloud.drone.io/api/badges/sbezugliy/aho-corasick-trie-search/status.svg)](https://cloud.drone.io/sbezugliy/aho-corasick-trie-search)
|
4
|
+
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/a491e842aac7b4f62751/maintainability)](https://codeclimate.com/github/sbezugliy/aho-corasick-trie-search/maintainability)
|
6
|
+
[![codecov](https://codecov.io/gh/sbezugliy/aho-corasick-trie-search/branch/master/graph/badge.svg)](https://codecov.io/gh/sbezugliy/aho-corasick-trie-search)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'aho-corasick-trie-search'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install aho-corasick-trie-search
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Array of words in the dictionary
|
28
|
+
dictionary = %w[he she her his him he they their she]
|
29
|
+
# Initialize trie
|
30
|
+
act = ACT::Trie.new(dictionary)
|
31
|
+
# Parse text and receive array of all occurrences of words in texts with indexes of word in dictionary
|
32
|
+
act.parse('he their them height have then their shelter')
|
33
|
+
# => [{:word=>"he", :indexes=>[0, 5]},
|
34
|
+
# {:word=>"their", :indexes=>[7]},
|
35
|
+
# {:word=>"he", :indexes=>[0, 5]},
|
36
|
+
# {:word=>"he", :indexes=>[0, 5]},
|
37
|
+
# {:word=>"he", :indexes=>[0, 5]},
|
38
|
+
# {:word=>"he", :indexes=>[0, 5]},
|
39
|
+
# {:word=>"their", :indexes=>[7]},
|
40
|
+
# {:word=>"he", :indexes=>[0, 5]},
|
41
|
+
# {:word=>"she", :indexes=>[1, 8]},
|
42
|
+
# {:word=>"he", :indexes=>[0, 5]}]
|
43
|
+
# Add additional words to the dictionary
|
44
|
+
act.extend_dictionary(["our", "it", "them"])
|
45
|
+
# Get end vertex of word 'they'
|
46
|
+
vertex = act.trie.get_child('s').get_child('h').get_child('e')
|
47
|
+
# => #<ACT::Vertex:0x000055cabb2399d0
|
48
|
+
# @char="e",
|
49
|
+
# @children=[],
|
50
|
+
# @end_indexes=[1, 8],
|
51
|
+
# @parent=
|
52
|
+
# #<ACT::Vertex:0x000055cabb239ac0
|
53
|
+
# @char="h",
|
54
|
+
# @children=[#<ACT::Vertex:0x000055cabb2399d0 ...>],
|
55
|
+
# @end_indexes=[],
|
56
|
+
# @parent=
|
57
|
+
# #<ACT::Vertex:0x000055cabb239bb0
|
58
|
+
# @char="s",
|
59
|
+
# @children=[#<ACT::Vertex:0x000055cabb239ac0 ...>],
|
60
|
+
# get array of indexes of word
|
61
|
+
vertex.end_indexes
|
62
|
+
# => [1, 8]
|
63
|
+
# Recover word from trie with indexes in dictionary
|
64
|
+
act.backtrace_to_word(vertex)
|
65
|
+
# => {:word=>"she", :indexes=>[1, 8]}
|
66
|
+
```
|
67
|
+
|
68
|
+
Index of word in dictionary can be used to get relations with additional array with external data(or collection, or can be easily replaced by foreign key in the future). If dictionary contain duplicates, then you will get few indexes in result.
|
69
|
+
|
70
|
+
## Benchmark
|
71
|
+
|
72
|
+
dictionary: 100000 words
|
73
|
+
number of executions with uniq text: 44555
|
74
|
+
results of benchmark:
|
75
|
+
|
76
|
+
user system total real
|
77
|
+
1.749733 0.116561 1.866294 ( 1.876876)
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
### TBD Improvements:
|
84
|
+
|
85
|
+
- TODO: Mode providing ability to return whole words, that contain substring from dictionary
|
86
|
+
- TODO: Suffix references is not implemented. Just now it contains full syntax tree, so it is less memory efficient then original Aho-Corasick algorithm.
|
87
|
+
- TODO: Maybe, will be good to implement next features for trie build stage:
|
88
|
+
- post optimization of vertex connections, creating suffixes
|
89
|
+
- some parallelism
|
90
|
+
- pre optimization of a dictionary.
|
data/Rakefile
ADDED
data/act.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require './lib/act/version'
|
4
|
+
require './lib/act/act'
|
5
|
+
require './lib/act/trie'
|
6
|
+
require './lib/act/vertex'
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'aho-corasick-trie-search'
|
9
|
+
spec.version = ACT::VERSION
|
10
|
+
spec.authors = ['Sergey Bezugliy']
|
11
|
+
spec.email = ['s.bezugliy@gmail.com']
|
12
|
+
spec.homepage = 'https://codenv.top/projects/aho-corasick-trie'
|
13
|
+
spec.summary = 'Aho-Corasick substring search algorithm implementation'
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
spec.description = <<-DESCRIPTION
|
16
|
+
This gem provides ruby library with Aho-Corasick
|
17
|
+
substring search algorithm implementation.
|
18
|
+
DESCRIPTION
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
|
+
|
24
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
25
|
+
spec.metadata['source_code_uri'] = 'https://github.com/sbezugliy/aho-corasick-trie-search'
|
26
|
+
# spec.metadata['changelog_uri'] = 'https://github.com/sbezugliy/aho-corasick-trie-search/changelog.md'
|
27
|
+
else
|
28
|
+
raise 'RubyGems 2.0 or newer is required to protect against' \
|
29
|
+
'public gem pushes.'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Specify which files should be added to the gem when it is released.
|
33
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
34
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
35
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
36
|
+
end
|
37
|
+
spec.bindir = 'exe'
|
38
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
39
|
+
spec.require_paths = ['lib']
|
40
|
+
|
41
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
42
|
+
spec.add_development_dependency 'codecov', '~> 0.1'
|
43
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
44
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
45
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
46
|
+
spec.add_development_dependency 'rspec-benchmark', '~> 0.5.0'
|
47
|
+
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1.0'
|
48
|
+
spec.add_development_dependency 'rubocop', '~> 0.67.0'
|
49
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
|
50
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.0'
|
51
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.67.0'
|
52
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'act/act'
|
5
|
+
require 'act/trie'
|
6
|
+
require 'act/vertex'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require "pry"
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'pry'
|
16
|
+
Pry.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/act/act.rb
ADDED
data/lib/act/trie.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# ACT module
|
2
|
+
module ACT
|
3
|
+
require 'act/vertex'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Main class for creating Aho-Corasick Trie from array of words of dictionary
|
7
|
+
class Trie
|
8
|
+
##
|
9
|
+
# Root vertex
|
10
|
+
attr_reader :root
|
11
|
+
##
|
12
|
+
# Dictionary attribute
|
13
|
+
attr_reader :dictionary
|
14
|
+
##
|
15
|
+
# Trie attribute
|
16
|
+
attr_reader :trie
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initialize new trie and fill it with words from dictionary
|
20
|
+
#
|
21
|
+
# Remarks:
|
22
|
+
# * dictioanry is array of characters
|
23
|
+
# * if indexing is important array should not be sorted
|
24
|
+
# * word from sentence may contain spaces and special characters, so
|
25
|
+
# one "word" can be the whole sentence
|
26
|
+
# * word can be an integer, but result will be converted to the string
|
27
|
+
def initialize(dictionary)
|
28
|
+
@root = ACT::Vertex.new
|
29
|
+
@dictionary = dictionary
|
30
|
+
@trie = build_trie
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Executes text analyze and returns map occurring words with indexes from dictionary
|
35
|
+
def parse(text)
|
36
|
+
text = text.to_s.split('')
|
37
|
+
vm = vertex_map(text) { :vertex }
|
38
|
+
exec_branches(text, vm).flatten.compact
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Returns hash with word and indexes at dictionary
|
43
|
+
# * Ending vertex of chain should be used as argument, it means that it should
|
44
|
+
# contain at least one value in the array of end_indexes attribute
|
45
|
+
def backtrace_to_word(vertex)
|
46
|
+
if vertex.end_indexes.empty?
|
47
|
+
raise 'Argument should be ending vertex of chain, and contain at'\
|
48
|
+
'least one value in the array of end_indexes attribute'
|
49
|
+
else
|
50
|
+
chain = backtrace(vertex)
|
51
|
+
{
|
52
|
+
word: chain.reduce('') { |acc, v| acc << v.char },
|
53
|
+
indexes: chain.last.end_indexes
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Adds additional words(chains of vertexes) to the trie object
|
60
|
+
# * Argument should be array of words
|
61
|
+
def extend_dictionay(dict)
|
62
|
+
build_trie(dict)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def exec_branches(text, vertex_map)
|
68
|
+
vertex_map.map do |b|
|
69
|
+
b[:indexes].map do |index|
|
70
|
+
search(b[:key], text[index + 1..-1])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def search(vertex, text)
|
76
|
+
result = []
|
77
|
+
return result unless vertex
|
78
|
+
|
79
|
+
result << backtrace_to_word(vertex) if end_vertex?(vertex)
|
80
|
+
return result if vertex.children.empty?
|
81
|
+
|
82
|
+
ending = search_rest(vertex, text)
|
83
|
+
!ending.empty? ? (result + ending) : result
|
84
|
+
end
|
85
|
+
|
86
|
+
def search_rest(vertex, text)
|
87
|
+
result = []
|
88
|
+
text.each do |char|
|
89
|
+
current_vertex = vertex.get_child(char)
|
90
|
+
break if current_vertex.nil?
|
91
|
+
|
92
|
+
result << backtrace_to_word(current_vertex) if end_vertex?(current_vertex)
|
93
|
+
break if current_vertex.children.empty?
|
94
|
+
|
95
|
+
vertex = current_vertex
|
96
|
+
end
|
97
|
+
result
|
98
|
+
end
|
99
|
+
|
100
|
+
def vertex_map(text)
|
101
|
+
@trie.children.map do |vertex|
|
102
|
+
{
|
103
|
+
key: vertex.send(yield),
|
104
|
+
indexes: text.collect.with_index { |c, i| i if c == vertex.char }.compact
|
105
|
+
}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def end_vertex?(vertex)
|
110
|
+
!vertex.end_indexes.empty?
|
111
|
+
end
|
112
|
+
|
113
|
+
def backtrace(vertex)
|
114
|
+
result = !vertex.nil? ? [vertex] : []
|
115
|
+
until vertex.parent.nil?
|
116
|
+
result << vertex.parent unless vertex.parent.char.nil?
|
117
|
+
vertex = vertex.parent
|
118
|
+
end
|
119
|
+
result.reverse
|
120
|
+
end
|
121
|
+
|
122
|
+
def build_trie(dict = @dictionary)
|
123
|
+
parent = @root
|
124
|
+
dict.each_with_index do |word, index|
|
125
|
+
word = word.to_s
|
126
|
+
word.to_s.each_char.with_index do |char, char_index|
|
127
|
+
end_index = char_index == (word.length - 1) ? index : nil
|
128
|
+
@vertex = (char_index.zero? ? @root : parent)
|
129
|
+
parent = @vertex.add_child(char, end_index)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
@root
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/act/version.rb
ADDED
data/lib/act/vertex.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# ACT module
|
2
|
+
module ACT
|
3
|
+
##
|
4
|
+
# Trie vertex class
|
5
|
+
class Vertex
|
6
|
+
##
|
7
|
+
# Reference to the parent ACT::Vertex
|
8
|
+
attr_reader :parent
|
9
|
+
##
|
10
|
+
# Array of children ACT::Vertex references, ACT::Vertex
|
11
|
+
attr_reader :children
|
12
|
+
##
|
13
|
+
# Array of indexes of word in dictionary
|
14
|
+
# Empty if it is intermediate ACT::Vertex in chain
|
15
|
+
attr_accessor :end_indexes
|
16
|
+
##
|
17
|
+
# Letter representing this vertex
|
18
|
+
attr_accessor :char
|
19
|
+
|
20
|
+
##
|
21
|
+
# Initializes new vertex
|
22
|
+
# * +parent+ is parent ACT::Vertex
|
23
|
+
def initialize(parent = nil)
|
24
|
+
@char = nil
|
25
|
+
@parent = parent
|
26
|
+
@children = []
|
27
|
+
@end_indexes = []
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Initializes new ACT::Vertex and adds it to the parent attribute
|
32
|
+
def add_child(char, end_index)
|
33
|
+
child = get_child(char)
|
34
|
+
if child
|
35
|
+
child.end_indexes << end_index unless end_index.nil?
|
36
|
+
child
|
37
|
+
else
|
38
|
+
init_subchild(char, end_index)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Returns child ACT::Vertex by letter, from children attribute
|
44
|
+
def get_child(char)
|
45
|
+
@children.find { |c| c.char == char }
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Returns array of characters from array of children ACT::Vertex
|
50
|
+
def children_chars
|
51
|
+
@children.map(&:char)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def vertex
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
def init_subchild(char, end_index)
|
61
|
+
child = self.class.new(self)
|
62
|
+
child.char = char
|
63
|
+
child.end_indexes << end_index unless end_index.nil?
|
64
|
+
@children << child
|
65
|
+
child
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aho-corasick-trie-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Bezugliy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-benchmark
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-collection_matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.67.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.67.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-performance
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.1.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.1.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.16.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.16.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov-console
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.67.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.67.0
|
167
|
+
description: |2
|
168
|
+
This gem provides ruby library with Aho-Corasick
|
169
|
+
substring search algorithm implementation.
|
170
|
+
email:
|
171
|
+
- s.bezugliy@gmail.com
|
172
|
+
executables: []
|
173
|
+
extensions: []
|
174
|
+
extra_rdoc_files: []
|
175
|
+
files:
|
176
|
+
- ".drone.yml"
|
177
|
+
- ".gitignore"
|
178
|
+
- ".rspec"
|
179
|
+
- ".travis.yml"
|
180
|
+
- Gemfile
|
181
|
+
- Gemfile.lock
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- act.gemspec
|
185
|
+
- bin/console
|
186
|
+
- bin/setup
|
187
|
+
- lib/act/act.rb
|
188
|
+
- lib/act/trie.rb
|
189
|
+
- lib/act/version.rb
|
190
|
+
- lib/act/vertex.rb
|
191
|
+
homepage: https://codenv.top/projects/aho-corasick-trie
|
192
|
+
licenses:
|
193
|
+
- Apache-2.0
|
194
|
+
metadata:
|
195
|
+
allowed_push_host: https://rubygems.org
|
196
|
+
homepage_uri: https://codenv.top/projects/aho-corasick-trie
|
197
|
+
source_code_uri: https://github.com/sbezugliy/aho-corasick-trie-search
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubygems_version: 3.0.1
|
214
|
+
signing_key:
|
215
|
+
specification_version: 4
|
216
|
+
summary: Aho-Corasick substring search algorithm implementation
|
217
|
+
test_files: []
|