Class: TSS::Trie
- Inherits:
-
Object
- Object
- TSS::Trie
- Defined in:
- lib/tss/trie.rb
Overview
Main class for creating Trie Substring Search from array of words of dictionary
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
Dictionary attribute.
-
#root ⇒ Object
readonly
Root vertex.
-
#trie ⇒ Object
readonly
Trie attribute.
-
#trie_class ⇒ Object
readonly
Trie class reference switched by type.
-
#trie_instance ⇒ Object
readonly
Trie class instance.
Instance Method Summary collapse
-
#backtrace_to_word(vertex) ⇒ Object
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.
-
#extend_dictionary(dict) ⇒ Object
Adds additional words(chains of vertexes) to the trie object * Argument should be array of words Example: >> tss.extend_dictionary([“our”, “it”, “them”]).
-
#initialize(dictionary, type = :full) ⇒ Trie
constructor
Initialize new trie and fill it with words from dictionary.
-
#parse(text) ⇒ Object
Executes text analyzis and returns map occurring words with indexes from dictionary.
Constructor Details
Instance Attribute Details
#dictionary ⇒ Object (readonly)
Dictionary attribute
14 15 16 |
# File 'lib/tss/trie.rb', line 14 def dictionary @dictionary end |
#trie ⇒ Object (readonly)
Trie attribute
17 18 19 |
# File 'lib/tss/trie.rb', line 17 def trie @trie end |
#trie_class ⇒ Object (readonly)
Trie class reference switched by type
20 21 22 |
# File 'lib/tss/trie.rb', line 20 def trie_class @trie_class end |
#trie_instance ⇒ Object (readonly)
Trie class instance
23 24 25 |
# File 'lib/tss/trie.rb', line 23 def trie_instance @trie_instance end |
Instance Method Details
#backtrace_to_word(vertex) ⇒ Object
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
45 46 47 |
# File 'lib/tss/trie.rb', line 45 def backtrace_to_word(vertex) @trie_instance.backtrace_to_word(vertex) end |
#extend_dictionary(dict) ⇒ Object
Adds additional words(chains of vertexes) to the trie object
-
Argument should be array of words
Example:
>> tss.extend_dictionary(["our", "it", "them"])
54 55 56 |
# File 'lib/tss/trie.rb', line 54 def extend_dictionary(dict) @trie_instance.extend_dictionary(dict) end |
#parse(text) ⇒ Object
Executes text analyzis and returns map occurring words with indexes from dictionary
37 38 39 |
# File 'lib/tss/trie.rb', line 37 def parse(text) @trie_instance.parse(text) end |