This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Home
Ruby-AhoCorasick API
require 'ahocorasick'
Classes defined inside AhoCorasick modules:
KeywordTree
Class Methods
initializecreates a new and empty KeywordTree
tree = AhoCorasick::KeywordTree.new # => #<AhoCorasick::KeywordTree:0x762474>
from_file(file_name)creates a new KeywordTree and loads each line fromfile_nameinto the tree
tree= AhoCorasick::KeywordTree.from_file('dictionary.txt') # => #<AhoCorasick::KeywordTree:0x921381>
Instance Methods
add_string(string, [int id])adds a new item to the tree, if the id is nil this method will generate one, otherwise will use the one that has been provided. Returns the id.
tree.add_string("string") => 1
tree.add_string("other string", 5) => 5
tree << "another one" # => 6
sizegets the size of the tree
tree.size # => 3
makefreeze the tree, an Error will be raised if a new entry is added afterwards. A new search will unlock the tree.
>> tree.add_string "foo"
=> 1
>> tree.make
=> true
>> tree.add_string "bar"
RuntimeError: Cannot add `bar" into a frozen tree.
from (irb):7:in `add_string'
from (irb):7
>> tree.find_all "foo"
=> [{:value=>"foo", :ends_at=>3, :starts_at=>0, :id=>1}]
>> tree.add_string "bar"
=> 2
find_all(string)does the search
results= tree.find_all("another one bites the dust") # => Array
results.each do | result |
puts result[:starts_at] # => 0
puts result[:ends_at] # => 11
puts result[:value] # => "another one"
puts result[:id] # => 6
end
filterreturns the attached ResultFilter.
filter=sets a new ResultFilter
ResultFilter
This class expose only an interface for one to define his own filter, see ResultFilter for details.






