lib/rdf_context/parser.rb in rdf_context-0.4.8 vs lib/rdf_context/parser.rb in rdf_context-0.5.0
- old
+ new
@@ -1,11 +1,11 @@
require File.join(File.dirname(__FILE__), 'graph')
module RdfContext
# Generic RdfContext Parser class
class Parser
- attr_reader :debug
+ attr_reader :debug, :uri
attr_accessor :doc, :graph
##
# Creates a new parser for N3 (or Turtle).
#
@@ -70,11 +70,11 @@
# raise ParserException.new("type option must be one of :rdfxml, :html, or :n3")
end
@delegate.parse(stream, uri, options, &block)
else
# Common parser operations
- @uri = Addressable::URI.parse(uri.to_s).to_s unless uri.nil?
+ @uri = URIRef.new(uri.to_s) unless uri.nil?
@strict = options[:strict] if options.has_key?(:strict)
@debug = options[:debug] if options.has_key?(:debug)
@graph ||= Graph.new(:identifier => @uri)
end
@@ -91,10 +91,11 @@
# Return Rdfa Parser instance
def self.rdfa_parser(options = {}); RdfaParser.new(options); end
# Heuristically detect the format of the uri
def detect_format(stream, uri = nil)
+ uri ||= stream.path if stream.respond_to?(:path)
format = case uri.to_s
when /\.(rdf|xml)$/ then :rdfxml
when /\.(html|xhtml)$/ then :rdfa
when /\.(nt|n3|txt)$/ then :n3
else
@@ -129,10 +130,10 @@
#
# @param [XML Node, any] node:: XML Node or string for showing context
# @param [String] message::
def add_debug(node, message)
puts "#{node_path(node)}: #{message}" if $DEBUG
- @debug << "#{node_path(node)}: #{message}" if @debug
+ @debug << "#{node_path(node)}: #{message}" if @debug.is_a?(Array)
end
# add a triple, object can be literal or URI or bnode
#
# If the parser is called with a block, triples are passed to the block rather