Class: Dendroid::Recognizer::Chart

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dendroid/recognizer/chart.rb

Overview

Also called a parse table. It records the progress of the Earley recognizer whens its verifies the compliance of the input text to the language grammar rules. It essentially consists in an array of item sets. If n is the number of input tokens then the chart has n + 1 entry sets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChart

Constructor Initialize the chart with one empty item set.



31
32
33
34
35
# File 'lib/dendroid/recognizer/chart.rb', line 31

def initialize
  @item_sets = []
  @success = false
  append_new_set
end

Instance Attribute Details

#failure_classStandardError

Returns The exception class in case of an error found by the recognizer.

Returns:

  • (StandardError)

    The exception class in case of an error found by the recognizer



22
23
24
# File 'lib/dendroid/recognizer/chart.rb', line 22

def failure_class
  @failure_class
end

#failure_reasonString

Returns The error message.

Returns:

  • (String)

    The error message



25
26
27
# File 'lib/dendroid/recognizer/chart.rb', line 25

def failure_reason
  @failure_reason
end

#item_setsArray<Recognizer::ItemSet> (readonly)

Returns The array of item sets.

Returns:



16
17
18
# File 'lib/dendroid/recognizer/chart.rb', line 16

def item_sets
  @item_sets
end

#success=(value) ⇒ Boolean (writeonly)

Returns Indicates whether the recognizer successfully processed the whole input.

Returns:

  • (Boolean)

    Indicates whether the recognizer successfully processed the whole input



19
20
21
# File 'lib/dendroid/recognizer/chart.rb', line 19

def success=(value)
  @success = value
end

Instance Method Details

#append_new_setObject

Add a new empty item set at the end of the array of item sets



38
39
40
# File 'lib/dendroid/recognizer/chart.rb', line 38

def append_new_set
  item_sets << ItemSet.new
end

#seed_last_set(e_item) ⇒ Object

Add an EItem to the last item set

Parameters:



44
45
46
# File 'lib/dendroid/recognizer/chart.rb', line 44

def seed_last_set(e_item)
  item_sets.last.add_item(e_item)
end

#successful?Boolean

Return true if the input text is valid according to the grammar.

Returns:

  • (Boolean)


50
51
52
# File 'lib/dendroid/recognizer/chart.rb', line 50

def successful?
  @success
end