rdf-rdfa 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /.DS_Store
2
+ /pkg
data/.yardopts ADDED
@@ -0,0 +1,11 @@
1
+ --title "RDF::RDFa - XHTML+RDFa Support for RDF.rb"
2
+ --output-dir doc/yard
3
+ --protected
4
+ --no-private
5
+ --hide-void-return
6
+ --markup rdoc
7
+ --readme README.rdoc
8
+ -
9
+ AUTHORS
10
+ CONTRIBUTORS
11
+ VERSION
data/CONTRIBUTORS ADDED
@@ -0,0 +1 @@
1
+ * Nicholas Humfrey <nicholas.humfrey@bbc.co.uk>
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.0.3
2
+ * Removed interal graph in Reader and implement each_triple & each_statement to perform parsing
3
+
1
4
  === 0.0.2
2
5
  * Remove dependency on Namespace
3
6
  * Changed to RDF::RDFa, and moved files accordingly.
data/README.rdoc CHANGED
@@ -4,12 +4,14 @@ RDFa parser for RDF.rb.
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- RDF::RDFa is an RDFa parser for Ruby using the RDF.rb library suite.
7
+ RDF::RDFa is an RDFa reader for Ruby using the RDF.rb library suite.
8
8
 
9
9
  == FEATURES:
10
- RDF::RDFa parses RDFa into a Graph object.
10
+ RDF::RDFa parses RDFa into statements or triples.
11
11
 
12
- * Fully compliant XHTML/RDFa 1.0 parser.
12
+ * Fully compliant XHTML/RDFa 1.1 parser.
13
+ * Uses Nokogiri for parsing XHTML
14
+ * RDFa tests use SPARQL for most tests due to Rasqal limitations. Other tests compare directly against N-triples.
13
15
 
14
16
  Install with 'gem install rdf-rdfa'
15
17
 
@@ -22,10 +24,26 @@ Instantiate a parser and parse source, specifying type and base-URL
22
24
  end
23
25
  end
24
26
 
27
+ == Dependencies
28
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.1.6)
29
+ * [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.3.3)
30
+ * [Patron](http://rubygems.org/gems/patron) (>= 0.4.6) -- For RDFa profiles
31
+
32
+ == TODO
33
+ * Add support for LibXML and REXML bindings, and use the best available
34
+ * Consider a SAX-based parser for improved performance
35
+ * Port SPARQL tests to native SPARQL processor, when one becomes available.
36
+ * Add generic XHTML+RDFa Writer
37
+ * Only parse profiles if Patron included, don't force otherwise
38
+
25
39
  == Resources:
40
+ * RDF.rb[http://rdf.rubyforge.org/]
26
41
  * Distiller[http://kellogg-assoc/distiller]
27
42
  * RDoc[http://rdoc.info/projects/gkellogg/rdf-rdfa]
28
43
  * History[http://github.com/gkellogg/rdf-rdfa/blob/master/History.txt]
44
+ * "RDFa 1.1 Core"[http://www.w3.org/TR/2010/WD-rdfa-core-20100422/]
45
+ * "XHTML+RDFa 1.1 Core"[http://www.w3.org/TR/2010/WD-xhtml-rdfa-20100422/]
46
+ * "RDFa test suite"[http://rdfa.digitalbazaar.com/test-suite/]
29
47
 
30
48
  == LICENSE:
31
49
 
data/Rakefile CHANGED
@@ -5,16 +5,15 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gemspec|
7
7
  gemspec.name = "rdf-rdfa"
8
- gemspec.summary = "RDFa parser for RDF.rb."
8
+ gemspec.summary = "RDFa reader for RDF.rb."
9
9
  gemspec.description = <<-DESCRIPTION
10
- RDF::RDFa is an RDFa parser for Ruby using the RDF.rb library suite.
10
+ RDF::RDFa is an RDFa reader for Ruby using the RDF.rb library suite.
11
11
  DESCRIPTION
12
12
  gemspec.email = "gregg@kellogg-assoc.com"
13
13
  gemspec.homepage = "http://github.com/gkellogg/rdf-rdfa"
14
- gemspec.authors = ["Gregg Kellogg", "Nicholas Humfrey"]
14
+ gemspec.authors = ["Gregg Kellogg"]
15
15
  gemspec.add_dependency('rdf', '>= 0.1.6')
16
16
  gemspec.add_dependency('nokogiri', '>= 1.3.3')
17
- gemspec.add_dependency('patron', '>= 0.4.6')
18
17
  gemspec.add_development_dependency('rspec')
19
18
  gemspec.add_development_dependency('rdf-spec')
20
19
  gemspec.add_development_dependency('activesupport', '>= 2.3.0')
@@ -36,6 +35,7 @@ Spec::Rake::SpecTask.new("spec:rcov") do |spec|
36
35
  spec.libs << 'lib' << 'spec'
37
36
  spec.pattern = 'spec/*_spec.rb'
38
37
  spec.rcov = true
38
+ spec.rcov_opts = ['-x', '/Library', '-x', '/System/Library', '-x', 'spec']
39
39
  end
40
40
 
41
41
  desc "Generate HTML report specs"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/etc/basic.html ADDED
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <title>W3C standard prefixes</title>
6
+ </head>
7
+ <body xmlns:rdfa="http://www.w3.org/ns/rdfa#">
8
+ <p typeof="">The URI "<span property="rdfa:uri">http://purl.org/dc/terms/</span>" can be used with the "<span property="rdfa:prefix">dc</span>" prefix.</p>
9
+ <p typeof="">The URI "<span property="rdfa:uri">http://xmlns.com/foaf/0.1/</span>" can be used with the "<span property="rdfa:prefix">foaf</span>" prefix.</p>
10
+ <p typeof="">The URI "<span property="rdfa:uri">http://www.w3.org/2001/vcard-rdf/3.0#</span>" can be used with the "<span property="rdfa:prefix">vcard</span>" prefix.</p>
11
+ <p typeof="">The URI "<span property="rdfa:uri">http://rdf.data-vocabulary.org/#</span>" can be used with the "<span property="rdfa:prefix">g</span>" prefix.</p>
12
+ <p typeof="">The URI "<span property="rdfa:uri">http://rdfs.org/sioc/ns#</span>" can be used with the "<span property="rdfa:prefix">sioc</span>" prefix.</p>
13
+ <p typeof="">The URI "<span property="rdfa:uri">http://creativecommons.org/ns#</span>" can be used with the "<span property="rdfa:prefix">cc</span>" prefix.</p>
14
+ </body>
15
+ </html>
data/example.rb CHANGED
@@ -1,27 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
-
5
3
  require 'rubygems'
6
- require 'rdfa/reader'
4
+ require 'rdf/rdfa'
7
5
 
8
6
  data = <<-EOF;
9
- <?xml version="1.0" encoding="UTF-8"?>
10
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
11
- <html xmlns="http://www.w3.org/1999/xhtml"
12
- xmlns:dc="http://purl.org/dc/elements/1.1/">
13
- <head>
14
- <title>Test 0001</title>
15
- </head>
16
- <body>
17
- <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
18
- </body>
19
- </html>
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
9
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0"
10
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
11
+ <head>
12
+ <title>Test 0001</title>
13
+ </head>
14
+ <body>
15
+ <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
16
+ </body>
17
+ </html>
20
18
  EOF
21
19
 
22
- $DEBUG = false
23
-
24
- reader = RDFa::Reader.new(data, :debug => false)
20
+ reader = RDF::RDFa::Reader.new(data, :base_uri => 'http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml')
25
21
  reader.each_statement do |statement|
26
22
  statement.inspect!
27
23
  end
data/lib/rdf/rdfa.rb CHANGED
@@ -1,4 +1,4 @@
1
- $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
2
2
  require 'rdf'
3
3
 
4
4
  module RDF
@@ -15,13 +15,6 @@ module RDF
15
15
  # end
16
16
  # end
17
17
  #
18
- # @example Serializing RDF statements into a XHTML+RDFa file
19
- # RDF::RDFa::Writer.open("etc/test.xml") do |writer|
20
- # reader.each_statement do |statement|
21
- # writer << statement
22
- # end
23
- # end
24
- #
25
18
  # @see http://rdf.rubyforge.org/
26
19
  # @see http://www.w3.org/TR/xhtml-rdfa-primer/
27
20
  # @see http://www.w3.org/2010/02/rdfa/wiki/Main_Page
@@ -30,9 +23,9 @@ module RDF
30
23
  #
31
24
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
32
25
  module RDFa
33
- require 'rdfa/format'
26
+ require 'rdf/rdfa/format'
27
+ require 'rdf/rdfa/vocab'
34
28
  autoload :Reader, 'rdf/rdfa/reader'
35
- autoload :Writer, 'rdf/rdfa/writer'
36
29
  autoload :VERSION, 'rdf/rdfa/version'
37
30
  end
38
- end\
31
+ end
@@ -1,6 +1,4 @@
1
1
  require 'nokogiri' # FIXME: Implement using different modules as in RDF::TriX
2
- require 'rdf'
3
- require 'rdf/rdfa/vocab'
4
2
 
5
3
  module RDF::RDFa
6
4
  ##
@@ -9,8 +7,7 @@ module RDF::RDFa
9
7
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
10
8
  class Reader < RDF::Reader
11
9
  format Format
12
- autoload :VERSION, 'rdf/rdfa/version'
13
-
10
+
14
11
  NC_REGEXP = Regexp.new(
15
12
  %{^
16
13
  (?!\\\\u0301) # &#x301; is a non-spacing acute accent.
@@ -26,12 +23,6 @@ module RDF::RDFa
26
23
 
27
24
  XML_LITERAL = RDF['XMLLiteral']
28
25
 
29
- attr_reader :debug
30
-
31
- ##
32
- # @return [RDF::Graph]
33
- attr_reader :graph
34
-
35
26
  # Host language, One of:
36
27
  # :xhtml_rdfa_1_0
37
28
  # :xhtml_rdfa_1_1
@@ -89,9 +80,9 @@ module RDF::RDFa
89
80
 
90
81
  # Copy this Evaluation Context
91
82
  def initialize_copy(from)
92
- # clone the evaluation context correctly
93
- @uri_mappings = from.uri_mappings.clone
94
- @incomplete_triples = from.incomplete_triples.clone
83
+ # clone the evaluation context correctly
84
+ @uri_mappings = from.uri_mappings.clone
85
+ @incomplete_triples = from.incomplete_triples.clone
95
86
  end
96
87
 
97
88
  def inspect
@@ -103,38 +94,22 @@ module RDF::RDFa
103
94
  end
104
95
  end
105
96
 
106
- # Parse XHTML+RDFa document from a string or input stream to closure or graph.
107
- #
108
- # If the parser is called with a block, triples are passed to the block rather
109
- # than added to the graph.
110
- #
111
- # Optionally, the stream may be a Nokogiri::HTML::Document or Nokogiri::XML::Document
112
- # With a block, yeilds each statement with URI, BNode or Literal elements
113
- #
114
- # @param [IO] stream:: the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
115
- # @param [String] uri:: the URI of the document
116
- # @param [Hash] options:: Parser options, one of
117
- # <em>options[:debug]</em>:: Array to place debug messages
118
- # <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
119
- # @return [Graph]:: Returns the graph containing parsed triples
120
- # @raise [Error]:: Raises RdfError if _strict_
121
-
122
97
  ##
123
98
  # Initializes the RDFa reader instance.
124
99
  #
125
- # @param [IO, File, String] input
126
- # @param [Hash{Symbol => Object}] options
100
+ # @param [IO, File, String]:: input
101
+ # @param [Hash{Symbol => Object}]:: options
102
+ # <em>options[:debug]</em>:: Array to place debug messages
103
+ # <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
104
+ # <em>options[:base_uri]</em>:: Base URI to use for relative URIs.
127
105
  # @yield [reader]
128
106
  # @yieldparam [Reader] reader
107
+ # @raise [RDF::ReaderError]:: Raises RDF::ReaderError if _strict_
129
108
  def initialize(input = $stdin, options = {}, &block)
130
- super
131
-
132
- @graph = RDF::Graph.new
109
+ super do
133
110
  @debug = options[:debug]
134
111
  @strict = options[:strict]
135
- @base_uri = options[:base_uri]
136
- @base_uri = RDF::URI.parse(@base_uri) if @base_uri.is_a?(String)
137
- @named_bnodes = {}
112
+ @base_uri = RDF::URI.new(options[:base_uri])
138
113
  @@vocabulary_cache ||= {}
139
114
 
140
115
  @doc = case input
@@ -143,37 +118,10 @@ module RDF::RDFa
143
118
  else Nokogiri::XML.parse(input, @base_uri.to_s)
144
119
  end
145
120
 
146
- raise ParserException, "Empty document" if @doc.nil? && @strict
147
- @callback = block
148
-
149
- # Determine host language
150
- # XXX - right now only XHTML defined
151
- @host_language = case @doc.root.attributes["version"].to_s
152
- when /XHTML+RDFa/ then :xhtml
153
- end
154
-
155
- # If none found, assume xhtml
156
- @host_language ||= :xhtml
157
-
158
- @host_defaults = {}
159
- @host_defaults = case @host_language
160
- when :xhtml
161
- {
162
- :vocabulary => RDF::XHV["uri"],
163
- :prefix => "xhv",
164
- :term_mappings => %w(
165
- alternate appendix bookmark cite chapter contents copyright first glossary help icon index
166
- last license meta next p3pv1 prev role section stylesheet subsection start top up
167
- ).inject({}) { |hash, term| hash[term] = RDF::XHV[term]; hash },
168
- }
169
- else
170
- {}
171
- end
172
-
173
- # parse
174
- parse_whole_document(@doc, @base_uri)
175
-
121
+ raise RDF::ReaderError, "Synax errors:\n#{@doc.errors}" if !@doc.errors.empty? && @strict
122
+ raise RDF::ReaderError, "Empty document" if (@doc.nil? || @doc.root.nil?) && @strict
176
123
  block.call(self) if block_given?
124
+ end
177
125
  end
178
126
 
179
127
 
@@ -185,7 +133,34 @@ module RDF::RDFa
185
133
  # @yieldparam [RDF::Statement] statement
186
134
  # @return [void]
187
135
  def each_statement(&block)
188
- @graph.each_statement(&block)
136
+ @callback = block
137
+
138
+ # Determine host language
139
+ # XXX - right now only XHTML defined
140
+ @host_language = case @doc.root.attributes["version"].to_s
141
+ when /XHTML+RDFa/ then :xhtml
142
+ end
143
+
144
+ # If none found, assume xhtml
145
+ @host_language ||= :xhtml
146
+
147
+ @host_defaults = {}
148
+ @host_defaults = case @host_language
149
+ when :xhtml
150
+ {
151
+ :vocabulary => RDF::XHV.to_s,
152
+ :prefix => "xhv",
153
+ :term_mappings => %w(
154
+ alternate appendix bookmark cite chapter contents copyright first glossary help icon index
155
+ last license meta next p3pv1 prev role section stylesheet subsection start top up
156
+ ).inject({}) { |hash, term| hash[term] = RDF::XHV[term]; hash },
157
+ }
158
+ else
159
+ {}
160
+ end
161
+
162
+ # parse
163
+ parse_whole_document(@doc, @base_uri)
189
164
  end
190
165
 
191
166
  ##
@@ -197,7 +172,9 @@ module RDF::RDFa
197
172
  # @yieldparam [RDF::Value] object
198
173
  # @return [void]
199
174
  def each_triple(&block)
200
- @graph.each_triple(&block)
175
+ each_statement do |statement|
176
+ block.call(*statement.to_triple)
177
+ end
201
178
  end
202
179
 
203
180
  private
@@ -227,17 +204,11 @@ module RDF::RDFa
227
204
  # @param [URI] predicate:: the predicate of the statement
228
205
  # @param [URI, BNode, Literal] object:: the object of the statement
229
206
  # @return [Statement]:: Added statement
230
- # @raise [Exception]:: Checks parameter types and raises if they are incorrect if parsing mode is _strict_.
207
+ # @raise [ReaderError]:: Checks parameter types and raises if they are incorrect if parsing mode is _strict_.
231
208
  def add_triple(node, subject, predicate, object)
232
209
  statement = RDF::Statement.new(subject, predicate, object)
233
210
  add_debug(node, "statement: #{statement}")
234
- @graph << statement
235
- statement
236
- # FIXME: rescue RdfException => e
237
- rescue Exception => e
238
- add_debug(node, "add_triple raised #{e.class}: #{e.message}")
239
- puts e.backtrace if $DEBUG
240
- raise if @strict
211
+ @callback.call(statement)
241
212
  end
242
213
 
243
214
 
@@ -283,57 +254,40 @@ module RDF::RDFa
283
254
  um = @@vocabulary_cache[profile][:uri_mappings]
284
255
  tm = @@vocabulary_cache[profile][:term_mappings]
285
256
  add_debug(element, "extract_mappings: profile open <#{profile}>")
286
- require 'patron' unless defined?(Patron)
287
- sess = Patron::Session.new
288
- sess.timeout = 10
289
- resp = sess.get(profile)
290
- raise RuntimeError, "HTTP returned status #{resp.status} when reading #{profile}" if resp.status >= 400
291
-
292
- # Parse profile, and extract mappings from graph
257
+
293
258
  old_debug, old_verbose, = $DEBUG, $verbose
294
259
  $DEBUG, $verbose = false, false
295
- p_graph = Parser.parse(resp.body, profile)
296
- ttl = p_graph.serialize(:format => :ttl) if @debug || $DEBUG
260
+ # FIXME: format shouldn't need to be specified here
261
+ p_graph = RDF::Graph.load(profile, :base_uri => profile, :format => :rdfa)
297
262
  $DEBUG, $verbose = old_debug, old_verbose
298
- add_debug(element, ttl) if ttl
299
- p_graph.subjects.each do |subject|
300
- props = p_graph.properties(subject)
301
- #puts props.inspect
302
-
303
- # If one of the objects is not a Literal or if there are additional rdfa:uri or rdfa:term
304
- # predicates sharing the same subject, no mapping is created.
305
- uri = props[RDF::RDFA["uri"].to_s]
306
- term = props[RDF::RDFA["term"].to_s]
307
- prefix = props[RDF::RDFA["prefix"].to_s]
263
+ p_graph.each_subject do |subject|
264
+ # If one of the objects is not a Literal no mapping is created.
265
+ uri = p_graph.first_object([subject, RDF::RDFA['uri'], nil])
266
+ term = p_graph.first_object([subject, RDF::RDFA['term'], nil])
267
+ prefix = p_graph.first_object([subject, RDF::RDFA['prefix'], nil])
308
268
  add_debug(element, "extract_mappings: uri=#{uri.inspect}, term=#{term.inspect}, prefix=#{prefix.inspect}")
309
269
 
310
270
  next if !uri || (!term && !prefix)
311
- raise ParserException, "multi-valued rdf:uri" if uri.length != 1
312
- raise ParserException, "multi-valued rdf:term." if term && term.length != 1
313
- raise ParserException, "multi-valued rdf:prefix" if prefix && prefix.length != 1
314
-
315
- uri = uri.first
316
- term = term.first if term
317
- prefix = prefix.first if prefix
318
- raise ParserException, "rdf:uri must be a Literal" unless uri.is_a?(Literal)
319
- raise ParserException, "rdf:term must be a Literal" unless term.nil? || term.is_a?(Literal)
320
- raise ParserException, "rdf:prefix must be a Literal" unless prefix.nil? || prefix.is_a?(Literal)
271
+ raise RDF::ReaderError, "rdf:uri must be a Literal" unless uri.is_a?(RDF::Literal)
272
+ raise RDF::ReaderError, "rdf:term must be a Literal" unless term.nil? || term.is_a?(RDF::Literal)
273
+ raise RDF::ReaderError, "rdf:prefix must be a Literal" unless prefix.nil? || prefix.is_a?(RDF::Literal)
321
274
 
322
275
  # For every extracted triple that is the common subject of an rdfa:prefix and an rdfa:uri
323
276
  # predicate, create a mapping from the object literal of the rdfa:prefix predicate to the
324
277
  # object literal of the rdfa:uri predicate. Add or update this mapping in the local list of
325
278
  # URI mappings after transforming the 'prefix' component to lower-case.
326
279
  # For every extracted
327
- um[prefix.to_s.downcase] = RDF::URI.new(uri) if prefix
280
+ um[prefix.value.downcase] = uri.value if prefix
328
281
 
329
282
  # triple that is the common subject of an rdfa:term and an rdfa:uri predicate, create a
330
283
  # mapping from the object literal of the rdfa:term predicate to the object literal of the
331
284
  # rdfa:uri predicate. Add or update this mapping in the local term mappings.
332
- tm[term.to_s] = RDF::URI.new(uri) if term
285
+ tm[term.value] = RDF::URI.new(uri.value) if term
333
286
  end
334
- rescue ParserException
335
- add_debug(element, "extract_mappings: profile subject #{subject.to_s}: #{e.message}")
336
- raise if @strict
287
+ # FIXME: subject isn't in scope here
288
+ #rescue RDF::ReaderError
289
+ # add_debug(element, "extract_mappings: profile subject #{subject.to_s}: #{e.message}")
290
+ # raise if @strict
337
291
  rescue RuntimeError => e
338
292
  add_debug(element, "extract_mappings: profile: #{e.message}")
339
293
  raise if @strict
@@ -353,9 +307,8 @@ module RDF::RDFa
353
307
  element.namespaces.each do |attr_name, attr_value|
354
308
  begin
355
309
  abbr, prefix = attr_name.split(":")
356
- uri_mappings[prefix.to_s.downcase] = RDF::URI.new(attr_value) if abbr.downcase == "xmlns" && prefix
357
- # FIXME: rescue RdfException => e
358
- rescue Exception => e
310
+ uri_mappings[prefix.to_s.downcase] = attr_value.to_s if abbr.downcase == "xmlns" && prefix
311
+ rescue ReaderError => e
359
312
  add_debug(element, "extract_mappings raised #{e.class}: #{e.message}")
360
313
  raise if @strict
361
314
  end
@@ -372,18 +325,18 @@ module RDF::RDFa
372
325
  next unless prefix.match(/:$/)
373
326
  prefix.chop!
374
327
 
375
- uri_mappings[prefix] = RDF::URI.new(uri)
328
+ uri_mappings[prefix] = uri
376
329
  end
377
330
 
378
- add_debug(element, "uri_mappings: #{uri_mappings.values.map{|ns|ns.to_s}.join(", ")}")
379
- add_debug(element, "term_mappings: #{term_mappings.keys.join(", ")}")
331
+ add_debug(element, "uri_mappings: #{uri_mappings.map{|k,v|"#{k}='#{v}'"}.join(", ")}")
332
+ add_debug(element, "term_mappings: #{term_mappings.map{|k,v|"#{k}='#{v}'"}.join(", ")}")
380
333
  end
381
334
 
382
335
  # The recursive helper function
383
336
  def traverse(element, evaluation_context)
384
337
  if element.nil?
385
338
  add_debug(element, "traverse nil element")
386
- raise ParserException, "Can't parse nil element" if @strict
339
+ raise RDF::ReaderError, "Can't parse nil element" if @strict
387
340
  return nil
388
341
  end
389
342
 
@@ -428,7 +381,7 @@ module RDF::RDFa
428
381
  # Set default_vocabulary to host language default
429
382
  @host_defaults.fetch(:voabulary, nil)
430
383
  else
431
- RDF::URI.new(vocab)
384
+ vocab.to_s
432
385
  end
433
386
  add_debug(element, "[Step 2] traverse, default_vocaulary: #{default_vocabulary.inspect}")
434
387
  end
@@ -538,7 +491,7 @@ module RDF::RDFa
538
491
  types = process_uris(element, typeof, evaluation_context, :uri_mappings => uri_mappings, :term_mappings => term_mappings, :vocab => default_vocabulary)
539
492
  add_debug(element, "typeof: #{typeof}")
540
493
  types.each do |one_type|
541
- add_triple(element, new_subject, RDF_TYPE, one_type)
494
+ add_triple(element, new_subject, RDF.type, one_type)
542
495
  end
543
496
  end
544
497
 
@@ -681,7 +634,7 @@ module RDF::RDFa
681
634
  if uri
682
635
  add_debug(element, "process_uri: #{value} => CURIE => <#{uri}>")
683
636
  else
684
- #FIXME: uri = URIRef.new(value, evaluation_context.base)
637
+ ## FIXME: throw exception if there is no base uri set?
685
638
  uri = RDF::URI.new(evaluation_context.base + value)
686
639
  add_debug(element, "process_uri: #{value} => URI => <#{uri}>")
687
640
  end
@@ -703,7 +656,7 @@ module RDF::RDFa
703
656
  options[:term_mappings][value.to_s.downcase]
704
657
  when options[:vocab]
705
658
  # Otherwise, if there is a local default vocabulary the URI is obtained by concatenating that value and the term.
706
- options[:vocab].join(value)
659
+ RDF::URI.new(options[:vocab] + value)
707
660
  else
708
661
  # Finally, if there is no local default vocabulary, the term has no associated URI and must be ignored.
709
662
  nil
@@ -717,15 +670,13 @@ module RDF::RDFa
717
670
 
718
671
  # consider the bnode situation
719
672
  if prefix == "_"
720
- # we force a non-nil name, otherwise it generates a new name
721
- # FIXME: BNode.new(reference || "", @named_bnodes)
722
- RDF::Node.new(reference || nil)
673
+ RDF::Node.new(reference)
723
674
  elsif curie.to_s.match(/^:/)
724
675
  # Default prefix
725
676
  if uri_mappings[""]
726
- uri_mappings[""].join(reference)
677
+ RDF::URI.new(uri_mappings[""] + reference)
727
678
  elsif @host_defaults[:prefix]
728
- @host_defaults[:prefix].join(reference)
679
+ RDF::URI.new(@host_defaults[:prefix] + reference)
729
680
  end
730
681
  elsif !curie.to_s.match(/:/)
731
682
  # No prefix, undefined (in this context, it is evaluated as a term elsewhere)
@@ -734,7 +685,7 @@ module RDF::RDFa
734
685
  # Prefixes always downcased
735
686
  ns = uri_mappings[prefix.to_s.downcase]
736
687
  if ns
737
- ns.join(reference)
688
+ RDF::URI.new(ns +reference)
738
689
  else
739
690
  add_debug(element, "curie_to_resource_or_bnode No namespace mapping for #{prefix.downcase}")
740
691
  nil