Class: RDF::TriG::Reader
- Inherits:
-
RDF::Turtle::Reader
- Object
- RDF::Turtle::Reader
- RDF::TriG::Reader
- Defined in:
- lib/rdf/trig/reader.rb
Overview
A parser for the TriG
Leverages the Turtle reader
Instance Method Summary collapse
-
#add_statement(production, statement) ⇒ RDF::Statement
add a statement, object can be literal or URI or bnode.
-
#each_quad {|subject, predicate, object, graph_name| ... } ⇒ void
Iterates the given block for each RDF quad in the input.
-
#each_statement {|statement| ... } ⇒ void
Iterates the given block for each RDF statement in the input.
Instance Method Details
#add_statement(production, statement) ⇒ RDF::Statement
add a statement, object can be literal or URI or bnode
91 92 93 94 95 96 97 98 |
# File 'lib/rdf/trig/reader.rb', line 91 def add_statement(production, statement) error("Statement is invalid: #{statement.inspect.inspect}", production: produciton) if validate? && statement.invalid? statement.graph_name = @graph_name if @graph_name @callback.call(statement) if statement.subject && statement.predicate && statement.object && (validate? ? statement.valid? : true) end |
#each_quad {|subject, predicate, object, graph_name| ... } ⇒ void
This method returns an undefined value.
Iterates the given block for each RDF quad in the input.
76 77 78 79 80 81 82 83 |
# File 'lib/rdf/trig/reader.rb', line 76 def each_quad(&block) if block_given? each_statement do |statement| block.call(*statement.to_quad) end end enum_for(:each_quad) end |
#each_statement {|statement| ... } ⇒ void
This method returns an undefined value.
Iterates the given block for each RDF statement in the input.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rdf/trig/reader.rb', line 47 def each_statement(&block) if block_given? @recovering = false @callback = block begin while (@lexer.first rescue true) read_trigDoc end rescue EBNF::LL1::Lexer::Error, SyntaxError, EOFError, Recovery # Terminate loop if EOF found while recovering end if validate? && log_statistics[:error] raise RDF::ReaderError, "Errors found during processing" end end enum_for(:each_statement) end |