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.



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_classStandardError (readonly)

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



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

def failure_class
  @failure_class
end

#failure_reasonString (readonly)

Returns The error message.

Returns:

  • (String)

    The error message



28
29
30
# File 'lib/dendroid/recognizer/chart.rb', line 28

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



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

def success=(value)
  @success = value
end

#tokensArray<Dendroid::Lexical::Token>

Returns The input tokens.

Returns:



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

def tokens
  @tokens
end

Instance Method Details

#append_new_setObject

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.

Parameters:

  • exception_class (StandardError)

    Exception class

  • message (String)

    Error message



60
61
62
63
# File 'lib/dendroid/recognizer/chart.rb', line 60

def failure(exception_class, message)
  @failure_class = exception_class
  @failure_reason = message
end

#seed_last_set(e_item) ⇒ Object

Add an EItem to the last item set

Parameters:



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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/dendroid/recognizer/chart.rb', line 53

def successful?
  @success
end