Class: NLP::SearchTree

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeSearchTree

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

#subtreesObject

Returns the value of attribute subtrees.



7
8
9
# File 'lib/stree.rb', line 7

def subtrees
  @subtrees
end

#valueObject

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

Yields:



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