class TSS::Trie
Main class for creating Trie
Substring Search from array of words of dictionary
Attributes
dictionary[R]
Dictionary attribute
root[R]
Root vertex
trie[R]
Trie
attribute
trie_class[R]
Trie
class reference switched by type
trie_instance[R]
Trie
class instance
Public Class Methods
new(dictionary, type = :full)
click to toggle source
Initialize new trie and fill it with words from dictionary
# File lib/tss/trie.rb, line 23 def initialize(dictionary, type = :full) switch_trie_type(type) @root = TSS::Vertex.new @dictionary = dictionary build_trie end
Public Instance Methods
backtrace_to_word(vertex)
click to toggle source
Returns hash with word and indexes at dictionary
-
Ending vertex of chain should be used as argument, it means that it should contain at least one value in the array of end_indexes attribute
# File lib/tss/trie.rb, line 40 def backtrace_to_word(vertex) @trie_instance.backtrace_to_word(vertex) end
extend_dictionary(dict)
click to toggle source
Adds additional words(chains of vertexes) to the trie object
-
Argument should be array of words
Example:
>> tss.extend_dictionary(["our", "it", "them"])
# File lib/tss/trie.rb, line 49 def extend_dictionary(dict) @trie_instance.extend_dictionary(dict) end
parse(text)
click to toggle source
Executes text analyzis and returns map occurring words with indexes from dictionary
# File lib/tss/trie.rb, line 32 def parse(text) @trie_instance.parse(text) end
Private Instance Methods
build_trie()
click to toggle source
# File lib/tss/trie.rb, line 55 def build_trie @trie_instance = @trie_class.new(@dictionary, @root) end
switch_trie_type(type)
click to toggle source
# File lib/tss/trie.rb, line 59 def switch_trie_type(type) @trie_class = TSS::Tries.const_get(trie_symbol(type), @root) end
trie_symbol(type)
click to toggle source
# File lib/tss/trie.rb, line 63 def trie_symbol(type) return :Full if type == :full return :AC if type == :aho_corasick return :Flat if type == :flat raise ArgumentError, 'Wrong trie type. Possible is: :full, :flat or :aho_corasick' end