Class: Dendroid::Recognizer::Chart
- Inherits:
-
Object
- Object
- Dendroid::Recognizer::Chart
- 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
-
#failure_class ⇒ StandardError
readonly
The exception class in case of an error found by the recognizer.
-
#failure_reason ⇒ String
readonly
The error message.
-
#item_sets ⇒ Array<Recognizer::ItemSet>
readonly
The array of item sets.
-
#success ⇒ Boolean
writeonly
Indicates whether the recognizer successfully processed the whole input.
-
#tokens ⇒ Array<Dendroid::Lexical::Token>
The input tokens.
Instance Method Summary collapse
-
#append_new_set ⇒ Object
Add a new empty item set at the end of the array of item sets.
-
#failure(exception_class, message) ⇒ Object
Set the error cause.
-
#initialize ⇒ Chart
constructor
Constructor Initialize the chart with one empty item set.
-
#seed_last_set(e_item) ⇒ Object
Add an EItem to the last item set.
-
#successful? ⇒ Boolean
Return true if the input text is valid according to the grammar.
Constructor Details
#initialize ⇒ Chart
Constructor Initialize the chart with one empty item set.
34 35 36 37 38 |
# File 'lib/dendroid/recognizer/chart.rb', line 34 def initialize @item_sets = [] @success = false append_new_set end |
Instance Attribute Details
#failure_class ⇒ StandardError (readonly)
Returns The exception class in case of an error found by the recognizer.
25 26 27 |
# File 'lib/dendroid/recognizer/chart.rb', line 25 def failure_class @failure_class end |
#failure_reason ⇒ String (readonly)
Returns The error message.
28 29 30 |
# File 'lib/dendroid/recognizer/chart.rb', line 28 def failure_reason @failure_reason end |
#item_sets ⇒ Array<Recognizer::ItemSet> (readonly)
Returns The array of item sets.
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.
22 23 24 |
# File 'lib/dendroid/recognizer/chart.rb', line 22 def success=(value) @success = value end |
#tokens ⇒ Array<Dendroid::Lexical::Token>
Returns The input tokens.
19 20 21 |
# File 'lib/dendroid/recognizer/chart.rb', line 19 def tokens @tokens end |
Instance Method Details
#append_new_set ⇒ Object
Add a new empty item set at the end of the array of item sets
41 42 43 |
# File 'lib/dendroid/recognizer/chart.rb', line 41 def append_new_set item_sets << ItemSet.new end |
#failure(exception_class, message) ⇒ Object
Set the error cause.
60 61 62 63 |
# File 'lib/dendroid/recognizer/chart.rb', line 60 def failure(exception_class, ) @failure_class = exception_class @failure_reason = end |
#seed_last_set(e_item) ⇒ Object
Add an EItem to the last item set
47 48 49 |
# File 'lib/dendroid/recognizer/chart.rb', line 47 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.
53 54 55 |
# File 'lib/dendroid/recognizer/chart.rb', line 53 def successful? @success end |