Class: Reddy::Parser
- Inherits:
-
Object
- Object
- Reddy::Parser
- Defined in:
- lib/reddy/parser.rb,
lib/reddy/n3parser.rb
Overview
Generic Reddy Parser class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#graph ⇒ Object
Returns the value of attribute graph.
Class Method Summary collapse
-
.n3_parser(options = {}) ⇒ Object
Return N3 Parser instance.
-
.parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Instantiate Parser and parse document.
-
.rdfa_parser(options = {}) ⇒ Object
Return Rdfa Parser instance.
-
.rdfxml_parser(options = {}) ⇒ Object
Return RDF/XML Parser instance.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
Creates a new parser for N3 (or Turtle).
-
#parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Parse RDF document from a string or input stream to closure or graph.
Constructor Details
#initialize(options = {}) ⇒ Parser
Creates a new parser for N3 (or Turtle).
- options[:graph]
-
Graph to parse into, otherwise a new Reddy::Graph instance is created
- options[:debug]
-
Array to place debug messages
- options[:type]
-
One of rdfxml, html, or n3
- options[:strict]
-
Raise Error if true, continue with lax parsing, otherwise
17 18 19 20 21 22 23 |
# File 'lib/reddy/parser.rb', line 17 def initialize( = {}) # initialize the triplestore @graph = [:graph] @debug = [:debug] @strict = [:strict] @named_bnodes = {} end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
4 5 6 |
# File 'lib/reddy/parser.rb', line 4 def debug @debug end |
#doc ⇒ Object
Returns the value of attribute doc.
5 6 7 |
# File 'lib/reddy/parser.rb', line 5 def doc @doc end |
#graph ⇒ Object
Returns the value of attribute graph.
5 6 7 |
# File 'lib/reddy/parser.rb', line 5 def graph @graph end |
Class Method Details
.n3_parser(options = {}) ⇒ Object
Return N3 Parser instance
78 |
# File 'lib/reddy/parser.rb', line 78 def self.n3_parser( = {}); N3Parser.new(); end |
.parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Instantiate Parser and parse document
- options[:debug]
-
Array to place debug messages
- options[:type]
-
One of rdfxml, html, or n3
- options[:strict]
-
Raise Error if true, continue with lax parsing, otherwise
37 38 39 40 |
# File 'lib/reddy/parser.rb', line 37 def self.parse(stream, uri = nil, = {}, &block) # :yields: triple parser = self.new() parser.parse(stream, uri, , &block) end |
.rdfa_parser(options = {}) ⇒ Object
Return Rdfa Parser instance
82 |
# File 'lib/reddy/parser.rb', line 82 def self.rdfa_parser( = {}); RdfaParser.new(); end |
.rdfxml_parser(options = {}) ⇒ Object
Return RDF/XML Parser instance
80 |
# File 'lib/reddy/parser.rb', line 80 def self.rdfxml_parser( = {}); RdfXmlParser.new(); end |
Instance Method Details
#parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Parse RDF document from a string or input stream to closure or graph.
Virtual Class, prototype for Parser subclass.
- options[:debug]
-
Array to place debug messages
- options[:strict]
-
Raise Error if true, continue with lax parsing, otherwise
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/reddy/parser.rb', line 55 def parse(stream, uri = nil, = {}, &block) # :yields: triple if self.class == Parser # Create a delegate of a specific parser class @delegate ||= case [:type].to_s when "n3", "ntriples", "turtle" then N3Parser.new() when "rdfa", "html", "xhtml" then RdfaParser.new() when "xml", "rdf", "rdfxml" then RdfXmlParser.new() else RdfXmlParser.new() # raise ParserException.new("type option must be one of :rdfxml, :html, or :n3") end @delegate.parse(stream, uri, , &block) else # Common parser operations @uri = Addressable::URI.parse(uri.to_s).to_s unless uri.nil? @strict = [:strict] if .has_key?(:strict) @debug = [:debug] if .has_key?(:debug) @graph ||= Graph.new(:identifier => @uri) end end |