class Gullah::Parse
A parse is the collection of root nodes produced by parsing a text.
class Example extend Gullah rule :S, 'NP VP' rule :NP, 'D N' rule :VP, 'V' leaf :D, /the/ leaf :N, /cat/ leaf :V, /sat/ end parses = Example.parse 'the cat sat', n: 1 # this is a Parse parse = parses.first puts parse.length # => 1 puts parse.size # => 8 puts parse.summary # => S[NP[D,_ws,N],_ws,VP[V]]
Attributes
The root nodes of all subtrees found in this parse in sequence. This is an array.
A concise stringification of the syntactic structure of this parse. For a given string and grammar all the parses will have a unique summary.
The text parsed by this parse.
Public Instance Methods
a simplified representation for debugging “so” = “significant only”
# File lib/gullah/parse.rb, line 116 def dbg(so: false) roots.map { |n| n.dbg so: so } end
The end offset of the last leaf in the parse.
# File lib/gullah/parse.rb, line 146 def end roots.last.end end
Are there any nodes in the parse that are erroneous, either because some test failed or because they correspond to “trash” – characters that matched no leaf rule?
# File lib/gullah/parse.rb, line 98 def errors? incorrectness_count.positive? end
Not a success?
# File lib/gullah/parse.rb, line 110 def failure? !success? end
The count of nodes that failed some test. Structure tests mark both the child and the ancestor node where the test was run as erroneous, so they will increase the incorrectness_count
by 2.
# File lib/gullah/parse.rb, line 83 def incorrectness_count @incorrectness_count ||= roots.select(&:failed?).count end
The number of root nodes in this parse. This is not the same as size.
# File lib/gullah/parse.rb, line 69 def length roots.length end
return an enumeration of all the nodes in the parse.
parses = Grammar.parse "this grammar uses the usual whitespace rule" parses.first.nodes.select { |n| n.name == :_ws }.count # => 6
# File lib/gullah/parse.rb, line 126 def nodes NodeIterator.new self end
The count of nodes which have some structure test which was never successfully run.
# File lib/gullah/parse.rb, line 90 def pending_count @pending_count ||= roots.select(&:pending_tests?).count end
The total number of nodes in this parse. This is not the same as length.
# File lib/gullah/parse.rb, line 75 def size @size ||= roots.sum(&:size) end
The start offset of the first leaf in the parse.
# File lib/gullah/parse.rb, line 140 def start roots.first.start end
Are all leaves accounted for without errors and have all tests passed?
# File lib/gullah/parse.rb, line 104 def success? !errors? && roots.all? { |n| n.ignorable? || n.nonterminal? && !n.pending_tests? } end