Class: Gullah::Iterator

Inherits:
Object
  • Object
show all
Defined in:
lib/gullah/iterator.rb

Overview

for iterating over reductions of a given parse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse, hopper, starters, do_unary_branch_check) ⇒ Iterator

Returns a new instance of Iterator.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gullah/iterator.rb', line 8

def initialize(parse, hopper, starters, do_unary_branch_check)
  @parse = parse
  @hopper = hopper
  @starters = starters
  @do_unary_branch_check = do_unary_branch_check
  @returned_any = false
  # this iterator iterates over both node indices and rule indices
  @root_index = 0
  @rule_index = 0
  @node = parse.roots[0]
end

Instance Attribute Details

#parseObject (readonly)

:nodoc:



6
7
8
# File 'lib/gullah/iterator.rb', line 6

def parse
  @parse
end

Instance Method Details

#errorsObject

number of erroneous nodes in the parse



43
44
45
# File 'lib/gullah/iterator.rb', line 43

def errors
  @parse.incorrectness_count
end

#lengthObject

number of nodes that need reduction



38
39
40
# File 'lib/gullah/iterator.rb', line 38

def length
  @parse.length
end

#never_returned_any?Boolean

Returns:



47
48
49
# File 'lib/gullah/iterator.rb', line 47

def never_returned_any?
  !@returned_any
end

#nextObject

return the next reduction, if any



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gullah/iterator.rb', line 21

def next
  loop do
    return nil unless (a = current_rule)

    @rule_index += 1
    unless (offset = a.match(parse.roots, @root_index))
      next
    end

    if (p = @hopper.vet(parse, @root_index, offset, a.parent, @do_unary_branch_check))
      @returned_any = true
      return p
    end
  end
end