Class: Reddy::N3Parser

Inherits:
Parser
  • Object
show all
Defined in:
lib/reddy/n3parser.rb

Instance Attribute Summary

Attributes inherited from Parser

#debug, #doc, #graph

Instance Method Summary collapse

Methods inherited from Parser

#initialize, n3_parser, parse, rdfa_parser, rdfxml_parser

Constructor Details

This class inherits a constructor from Reddy::Parser

Instance Method Details

#parse(stream, uri = nil, options = {}, &block) ⇒ Graph

Parse N3 document from a string or input stream to closure or graph.

Optionally, the stream may be a Nokogiri::HTML::Document or Nokogiri::XML::Document With a block, yeilds each statement with URIRef, BNode or Literal elements

options[:debug]

Array to place debug messages

options[:strict]

Abort or proceed on error

Parameters:

  • n3_str:: (String)

    the Notation3/Turtle string

  • uri:: (String)

    the URI of the document

  • options:: (Hash)

    Options include the following

Returns:

Raises:

  • Reddy::RdfException or subclass

Author:

  • Patrick Sinclair (metade)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/reddy/n3parser.rb', line 23

def parse(stream, uri = nil, options = {}, &block) # :yields: triple
  super

  @callback = block
  parser = N3GrammerParser.new

  @doc = stream.respond_to?(:read) ? stream.read : stream
  
  document = parser.parse(@doc)
  unless document
    reason = parser.failure_reason
    raise ParserException.new(reason)
  end
  
  process_directives(document)
  process_statements(document)
  @graph
end