Class: NLP::SearchTree
- Inherits:
-
Object
- Object
- NLP::SearchTree
- Defined in:
- lib/stree.rb
Constant Summary collapse
- ALPHABET =
%w{* - a ą b c ć d e ę f g h i j k l ł m n ń o ó p r s ś t u w y z ź ż}
- SYMBOLS =
%w{* - : - / ) (}
Instance Attribute Summary collapse
-
#subtrees ⇒ Object
Returns the value of attribute subtrees.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #find(s) ⇒ Object
-
#initialize ⇒ SearchTree
constructor
0 -> * 1 -> - 2 -> a 33 -> ź.
- #insert(s, value) ⇒ Object
- #traverse {|@value| ... } ⇒ Object
Constructor Details
#initialize ⇒ SearchTree
0 -> * 1 -> - 2 -> a 33 -> ź
13 14 15 16 |
# File 'lib/stree.rb', line 13 def initialize @subtrees = Array.new( 34, nil ) @value = [] end |
Instance Attribute Details
#subtrees ⇒ Object
Returns the value of attribute subtrees.
7 8 9 |
# File 'lib/stree.rb', line 7 def subtrees @subtrees end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/stree.rb', line 6 def value @value end |
Instance Method Details
#find(s) ⇒ Object
22 23 24 |
# File 'lib/stree.rb', line 22 def find( s ) priv_find( s.scan(/./) ) end |
#insert(s, value) ⇒ Object
18 19 20 |
# File 'lib/stree.rb', line 18 def insert( s, value ) priv_insert( s.scan(/./), value ) end |
#traverse {|@value| ... } ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/stree.rb', line 73 def traverse() list = [] yield @value list.concat @subrees if @subtrees != nil loop do break if list.empty? node = list.shift yield node.value list.concat node.subtrees if node.subtrees != nil end end |