Class: Reddy::RdfaParser
Overview
An RDFa parser in Ruby
Based on processing rules described here: www.w3.org/TR/rdfa-syntax/#s_model
Ben Adida 2008-05-07 Gregg Kellogg 2009-08-04
Defined Under Namespace
Classes: EvaluationContext
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Attributes inherited from Parser
Instance Method Summary collapse
-
#parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Parse XHTML+RDFa document from a string or input stream to closure or graph.
Methods inherited from Parser
#initialize, n3_parser, parse, rdfa_parser, rdfxml_parser
Constructor Details
This class inherits a constructor from Reddy::Parser
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
12 13 14 |
# File 'lib/reddy/rdfaparser.rb', line 12 def namespace @namespace end |
Instance Method Details
#parse(stream, uri = nil, options = {}, &block) ⇒ Graph
Parse XHTML+RDFa 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]
-
Raise Error if true, continue with lax parsing, otherwise
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/reddy/rdfaparser.rb', line 62 def parse(stream, uri = nil, = {}, &block) # :yields: triple super @doc = case stream when Nokogiri::HTML::Document then stream when Nokogiri::XML::Document then stream else Nokogiri::XML.parse(stream, uri) end raise ParserException, "Empty document" if @doc.nil? && @strict @callback = block # If the doc has a default, use that as "html" ns = @doc.namespaces["xmlns"] ns ||= "http://www.w3.org/1999/xhtml" # FIXME: intuite from DOCTYPE, or however @namespace = Namespace.new(ns, "html") if ns # parse parse_whole_document(@doc, @uri) @graph end |