rdf_context 0.5.9.1 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/History.rdoc +23 -2
- data/Rakefile +17 -17
- data/VERSION +1 -1
- data/bin/rdf_context +1 -4
- data/lib/rdf_context.rb +55 -19
- data/lib/rdf_context/aggregate_graph.rb +0 -2
- data/lib/rdf_context/bnode.rb +14 -1
- data/lib/rdf_context/conjunctive_graph.rb +0 -2
- data/lib/rdf_context/graph.rb +9 -10
- data/lib/rdf_context/literal.rb +39 -56
- data/lib/rdf_context/n3_grammar.treetop +2 -2
- data/lib/rdf_context/n3parser.rb +7 -5
- data/lib/rdf_context/parser.rb +2 -3
- data/lib/rdf_context/quoted_graph.rb +0 -2
- data/lib/rdf_context/rdfaparser.rb +93 -68
- data/lib/rdf_context/rdfxmlparser.rb +1 -1
- data/lib/rdf_context/resource.rb +56 -0
- data/lib/rdf_context/serializer/abstract_serializer.rb +0 -2
- data/lib/rdf_context/serializer/nt_serializer.rb +0 -2
- data/lib/rdf_context/serializer/recursive_serializer.rb +0 -4
- data/lib/rdf_context/serializer/turtle_serializer.rb +0 -2
- data/lib/rdf_context/serializer/xml_serializer.rb +0 -2
- data/lib/rdf_context/store/abstract_sql_store.rb +3 -1
- data/lib/rdf_context/store/active_record_store.rb +272 -0
- data/lib/rdf_context/store/list_store.rb +2 -2
- data/lib/rdf_context/store/memory_store.rb +2 -2
- data/lib/rdf_context/store/sqlite3_store.rb +112 -48
- data/lib/rdf_context/term_utils.rb +0 -4
- data/lib/rdf_context/triple.rb +1 -3
- data/lib/rdf_context/uriref.rb +14 -1
- data/rdf_context.gemspec +872 -0
- data/script/tc +4 -4
- data/spec/active_record_store_spec.rb +61 -0
- data/spec/aggregate_graph_spec.rb +1 -1
- data/spec/bnode_spec.rb +37 -1
- data/spec/conjunctive_graph_spec.rb +1 -1
- data/spec/cwm_spec.rb +5 -5
- data/spec/duration_spec.rb +1 -1
- data/spec/graph_spec.rb +16 -2
- data/spec/list_store_spec.rb +1 -1
- data/spec/literal_spec.rb +47 -14
- data/spec/memory_store_spec.rb +1 -1
- data/spec/n3parser_spec.rb +19 -5
- data/spec/namespaces_spec.rb +1 -1
- data/spec/parser_spec.rb +1 -1
- data/spec/rdf_helper.rb +18 -15
- data/spec/rdfa_helper.rb +27 -14
- data/spec/rdfa_parser_spec.rb +28 -9
- data/spec/rdfxml_spec.rb +3 -3
- data/spec/spec_helper.rb +10 -5
- data/spec/sqlite3_store_spec.rb +1 -1
- data/spec/string_hacks_spec.rb +2 -1
- data/spec/swap_spec.rb +7 -7
- data/spec/swap_test/ref/contexts-1.n3 +12 -0
- data/spec/swap_test/ref/prefix2.rdf +33 -0
- data/spec/swap_test/ref/xmllit.nt +1 -1
- data/spec/swap_test/regression.n3 +18 -18
- data/spec/triple_spec.rb +1 -1
- data/spec/turtle_serializer_spec.rb +3 -3
- data/spec/turtle_spec.rb +3 -3
- data/spec/uriref_spec.rb +31 -1
- metadata +13 -15
@@ -1,6 +1,6 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
grammar N3Grammer
|
3
|
-
# Entry point to
|
3
|
+
# Entry point to grammar
|
4
4
|
rule document
|
5
5
|
statements
|
6
6
|
end
|
@@ -81,7 +81,7 @@ grammar N3Grammer
|
|
81
81
|
end
|
82
82
|
|
83
83
|
rule language
|
84
|
-
[a-
|
84
|
+
[a-zA-Z]+ ( "-" [a-zA-Z0-9]+ )*
|
85
85
|
end
|
86
86
|
|
87
87
|
rule literal
|
data/lib/rdf_context/n3parser.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'treetop'
|
2
|
-
require File.join(File.dirname(__FILE__), 'parser')
|
3
2
|
|
4
3
|
Treetop.load(File.join(File.dirname(__FILE__), "n3_grammar"))
|
5
4
|
|
@@ -270,7 +269,7 @@ module RdfContext
|
|
270
269
|
|
271
270
|
def process_uri(uri)
|
272
271
|
uri = uri.text_value if uri.respond_to?(:text_value)
|
273
|
-
URIRef.intern(uri, @uri, :normalize => false)
|
272
|
+
URIRef.intern(uri.to_s.rdf_unescape, @uri, :normalize => false)
|
274
273
|
end
|
275
274
|
|
276
275
|
def process_properties(properties)
|
@@ -338,15 +337,18 @@ module RdfContext
|
|
338
337
|
end
|
339
338
|
|
340
339
|
uri = if @graph.nsbinding[prefix]
|
341
|
-
@graph.nsbinding[prefix] + localname.to_s
|
340
|
+
@graph.nsbinding[prefix] + localname.to_s
|
342
341
|
elsif prefix == '_'
|
343
342
|
BNode.new(localname, @named_bnodes)
|
344
343
|
elsif prefix == "rdf"
|
345
344
|
# A special case
|
346
|
-
RDF_NS + localname.to_s
|
345
|
+
RDF_NS + localname.to_s
|
346
|
+
elsif prefix == "xsd"
|
347
|
+
# A special case
|
348
|
+
XSD_NS + localname.to_s
|
347
349
|
else
|
348
350
|
@default_ns ||= Namespace.new("#{@uri}#", "")
|
349
|
-
@default_ns + localname.to_s
|
351
|
+
@default_ns + localname.to_s
|
350
352
|
end
|
351
353
|
add_debug(*expression.info("build_uri: #{uri.inspect}")) if expression.respond_to?(:info)
|
352
354
|
uri
|
data/lib/rdf_context/parser.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'graph')
|
2
|
-
|
3
1
|
module RdfContext
|
4
2
|
# Generic RdfContext Parser class
|
5
3
|
class Parser
|
@@ -131,7 +129,7 @@ module RdfContext
|
|
131
129
|
when /\.(nt|n3|txt)$/ then :n3
|
132
130
|
else
|
133
131
|
# Got to look into the file to see
|
134
|
-
if stream.
|
132
|
+
if stream.respond_to?(:read)
|
135
133
|
stream.rewind
|
136
134
|
string = stream.read(1000)
|
137
135
|
stream.rewind
|
@@ -145,6 +143,7 @@ module RdfContext
|
|
145
143
|
else :n3
|
146
144
|
end
|
147
145
|
end
|
146
|
+
format
|
148
147
|
end
|
149
148
|
|
150
149
|
protected
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), "nokogiri_hacks")
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
4
|
module RdfContext
|
@@ -67,14 +67,15 @@ module RdfContext
|
|
67
67
|
#
|
68
68
|
# @return URIRef
|
69
69
|
attr :parent_object, true
|
70
|
-
# A list of current, in-scope profiles.
|
71
|
-
#
|
72
|
-
# @return [Array<URIRef>]
|
73
|
-
attr :profiles, true
|
74
70
|
# A list of current, in-scope URI mappings.
|
75
71
|
#
|
76
72
|
# @return [Hash{String => Namespace}]
|
77
73
|
attr :uri_mappings, true
|
74
|
+
# A list of current, in-scope Namespaces. This is the subset of uri_mappings
|
75
|
+
# which are defined using xmlns.
|
76
|
+
#
|
77
|
+
# @return [Hash{String => Namespace}]
|
78
|
+
attr :namespaces, true
|
78
79
|
# A list of incomplete triples.
|
79
80
|
#
|
80
81
|
# A triple can be incomplete when no object resource
|
@@ -114,8 +115,8 @@ module RdfContext
|
|
114
115
|
@base = base
|
115
116
|
@parent_subject = @base
|
116
117
|
@parent_object = nil
|
117
|
-
@profiles = []
|
118
118
|
@uri_mappings = host_defaults.fetch(:uri_mappings, {})
|
119
|
+
@namespaces = {}
|
119
120
|
@incomplete_triples = []
|
120
121
|
@language = nil
|
121
122
|
@term_mappings = host_defaults.fetch(:term_mappings, {})
|
@@ -129,7 +130,7 @@ module RdfContext
|
|
129
130
|
# clone the evaluation context correctly
|
130
131
|
@uri_mappings = from.uri_mappings.clone
|
131
132
|
@incomplete_triples = from.incomplete_triples.clone
|
132
|
-
@
|
133
|
+
@namespaces = from.namespaces.clone
|
133
134
|
end
|
134
135
|
|
135
136
|
def inspect
|
@@ -137,7 +138,6 @@ module RdfContext
|
|
137
138
|
v << "uri_mappings[#{uri_mappings.keys.length}]"
|
138
139
|
v << "incomplete_triples[#{incomplete_triples.length}]"
|
139
140
|
v << "term_mappings[#{term_mappings.keys.length}]"
|
140
|
-
v << "profiles[#{profiles.length}]"
|
141
141
|
v.join(",")
|
142
142
|
end
|
143
143
|
end
|
@@ -193,7 +193,11 @@ module RdfContext
|
|
193
193
|
@callback = block
|
194
194
|
|
195
195
|
@version = options[:version] ? options[:version].to_sym : :rdfa_1_1
|
196
|
-
@host_language = options[:host_language] ||
|
196
|
+
@host_language = options[:host_language] || case @doc.root.name.downcase.to_sym
|
197
|
+
when :html then :xhtml
|
198
|
+
when :svg then :svg
|
199
|
+
else :xhtml
|
200
|
+
end
|
197
201
|
|
198
202
|
# Section 4.2 RDFa Host Language Conformance
|
199
203
|
#
|
@@ -204,7 +208,7 @@ module RdfContext
|
|
204
208
|
when :xhtml
|
205
209
|
@graph.bind(XHV_NS)
|
206
210
|
{
|
207
|
-
:vocabulary =>
|
211
|
+
:vocabulary => nil,
|
208
212
|
:prefix => XHV_NS,
|
209
213
|
:uri_mappings => {"xhv" => XHV_NS}, # RDF::XHTML is wrong
|
210
214
|
:term_mappings => %w(
|
@@ -216,7 +220,6 @@ module RdfContext
|
|
216
220
|
{}
|
217
221
|
end
|
218
222
|
|
219
|
-
@host_defaults.delete(:vocabulary) if @version == :rdfa_1_0
|
220
223
|
@profile_graph ||= options[:profile_graph] if options.has_key?(:profile_graph)
|
221
224
|
|
222
225
|
add_debug(@doc.root, "version = #{@version.inspect}, host_language = #{@host_language}")
|
@@ -231,18 +234,21 @@ module RdfContext
|
|
231
234
|
# Parsing an RDFa document (this is *not* the recursive method)
|
232
235
|
def parse_whole_document(doc, base)
|
233
236
|
# find if the document has a base element
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
base = base_el.
|
237
|
+
case @host_language
|
238
|
+
when :xhtml
|
239
|
+
base_el = doc.at_css("html>head>base")
|
240
|
+
base = base_el.attribute("href").to_s.split("#").first if base_el
|
241
|
+
end
|
242
|
+
|
243
|
+
if (base)
|
238
244
|
# Strip any fragment from base
|
239
245
|
base = base.to_s.split("#").first
|
240
|
-
|
241
|
-
add_debug(
|
246
|
+
base = URIRef.intern(base, :normalize => false, :normalize => false)
|
247
|
+
add_debug("", "parse_whole_doc: base='#{base}'")
|
242
248
|
end
|
243
249
|
|
244
250
|
# initialize the evaluation context with the appropriate base
|
245
|
-
evaluation_context = EvaluationContext.new(
|
251
|
+
evaluation_context = EvaluationContext.new(base, @host_defaults)
|
246
252
|
|
247
253
|
traverse(doc.root, evaluation_context)
|
248
254
|
end
|
@@ -277,9 +283,10 @@ module RdfContext
|
|
277
283
|
|
278
284
|
::RdfContext::debug, $verbose = false, false
|
279
285
|
p_graph = Parser.parse(prof_body, profile, parse_options)
|
280
|
-
ttl = p_graph.serialize(:format => :ttl) if @debug || ::RdfContext::debug?
|
281
286
|
::RdfContext::debug, $verbose = old_debug, old_verbose
|
282
|
-
add_debug(element,
|
287
|
+
add_debug(element, "process_profile: extracted #{p_graph.size} statements")
|
288
|
+
#ttl = p_graph.serialize(:format => :ttl) if @debug || ::RdfContext::debug?
|
289
|
+
#add_debug(element, ttl) if ttl
|
283
290
|
end
|
284
291
|
|
285
292
|
add_debug(element, "process_profile: extract mappings from <#{profile}>")
|
@@ -343,7 +350,7 @@ module RdfContext
|
|
343
350
|
end
|
344
351
|
|
345
352
|
# Extract the XMLNS mappings from an element
|
346
|
-
def extract_mappings(element, uri_mappings)
|
353
|
+
def extract_mappings(element, uri_mappings, namespaces)
|
347
354
|
# look for xmlns
|
348
355
|
# (note, this may be dependent on @host_language)
|
349
356
|
# Regardless of how the mapping is declared, the value to be mapped must be converted to lower case,
|
@@ -358,8 +365,12 @@ module RdfContext
|
|
358
365
|
# Downcase prefix for RDFa 1.1
|
359
366
|
pfx_lc = (@version == :rdfa_1_0 || ns.prefix.nil?) ? ns.prefix : ns.prefix.to_s.downcase
|
360
367
|
if ns.prefix
|
361
|
-
|
368
|
+
namespace = Namespace.new(ns.href, ns.prefix.to_s)
|
369
|
+
uri_mappings[pfx_lc] = @graph.bind(namespace)
|
370
|
+
namespaces[pfx_lc] ||= ns.href.to_s
|
362
371
|
add_debug(element, "extract_mappings: xmlns:#{ns.prefix} => <#{ns.href}>")
|
372
|
+
else
|
373
|
+
namespaces[""] ||= ns.href.to_s
|
363
374
|
end
|
364
375
|
|
365
376
|
rescue RdfException => e
|
@@ -401,6 +412,7 @@ module RdfContext
|
|
401
412
|
new_subject = nil
|
402
413
|
current_object_resource = nil
|
403
414
|
uri_mappings = evaluation_context.uri_mappings.clone
|
415
|
+
namespaces = evaluation_context.namespaces.clone
|
404
416
|
incomplete_triples = []
|
405
417
|
language = evaluation_context.language
|
406
418
|
term_mappings = evaluation_context.term_mappings.clone
|
@@ -416,6 +428,9 @@ module RdfContext
|
|
416
428
|
resource = attrs['resource']
|
417
429
|
href = attrs['href']
|
418
430
|
vocab = attrs['vocab']
|
431
|
+
xml_base = element.attribute_with_ns("base", XML_NS.uri.to_s)
|
432
|
+
base = xml_base.to_s if xml_base && @host_language != :xhtml
|
433
|
+
base ||= evaluation_context.base
|
419
434
|
|
420
435
|
# Pull out the attributes needed for the skip test.
|
421
436
|
property = attrs['property'].to_s.strip if attrs['property']
|
@@ -426,6 +441,23 @@ module RdfContext
|
|
426
441
|
rev = attrs['rev'].to_s.strip if attrs['rev']
|
427
442
|
profiles = attrs['profile'].to_s.split(/\s/) # In-scope profiles in order for passing to XMLLiteral
|
428
443
|
|
444
|
+
attrs = {
|
445
|
+
:about => about,
|
446
|
+
:src => src,
|
447
|
+
:resource => resource,
|
448
|
+
:href => href,
|
449
|
+
:vocab => vocab,
|
450
|
+
:base => xml_base,
|
451
|
+
:property => property,
|
452
|
+
:typeof => typeof,
|
453
|
+
:daetatype => datatype,
|
454
|
+
:rel => rel,
|
455
|
+
:rev => rev,
|
456
|
+
:profiles => (profiles.empty? ? nil : profiles),
|
457
|
+
}.select{|k,v| v}
|
458
|
+
|
459
|
+
add_debug(element, "traverse " + attrs.map{|a| "#{a.first}: #{a.last}"}.join(", ")) unless attrs.empty?
|
460
|
+
|
429
461
|
# Local term mappings [7.5 Steps 2]
|
430
462
|
# Next the current element is parsed for any updates to the local term mappings and local list of URI mappings via @profile.
|
431
463
|
# If @profile is present, its value is processed as defined in RDFa Profiles.
|
@@ -447,10 +479,7 @@ module RdfContext
|
|
447
479
|
return
|
448
480
|
end
|
449
481
|
end
|
450
|
-
|
451
|
-
# Add on proviles from parent contexts to update new context
|
452
|
-
profiles += evaluation_context.profiles.clone
|
453
|
-
|
482
|
+
|
454
483
|
# Default vocabulary [7.5 Step 3]
|
455
484
|
# Next the current element is examined for any change to the default vocabulary via @vocab.
|
456
485
|
# If @vocab is present and contains a value, its value updates the local default vocabulary.
|
@@ -469,7 +498,7 @@ module RdfContext
|
|
469
498
|
# Local term mappings [7.5 Steps 4]
|
470
499
|
# Next, the current element is then examined for URI mapping s and these are added to the local list of URI mappings.
|
471
500
|
# Note that a URI mapping will simply overwrite any current mapping in the list that has the same name
|
472
|
-
extract_mappings(element, uri_mappings)
|
501
|
+
extract_mappings(element, uri_mappings, namespaces)
|
473
502
|
|
474
503
|
# Language information [7.5 Step 5]
|
475
504
|
# From HTML5 [3.2.3.3]
|
@@ -485,39 +514,37 @@ module RdfContext
|
|
485
514
|
else
|
486
515
|
language
|
487
516
|
end
|
488
|
-
add_debug(element, "HTML5 [3.2.3.3] traverse, lang: #{language}") if
|
517
|
+
add_debug(element, "HTML5 [3.2.3.3] traverse, lang: #{language}") if language
|
489
518
|
|
490
519
|
# rels and revs
|
491
|
-
rels = process_uris(element, rel, evaluation_context,
|
520
|
+
rels = process_uris(element, rel, evaluation_context, base,
|
492
521
|
:uri_mappings => uri_mappings,
|
493
522
|
:term_mappings => term_mappings,
|
494
523
|
:vocab => default_vocabulary,
|
495
524
|
:restrictions => TERMorCURIEorAbsURI[@version])
|
496
|
-
revs = process_uris(element, rev, evaluation_context,
|
525
|
+
revs = process_uris(element, rev, evaluation_context, base,
|
497
526
|
:uri_mappings => uri_mappings,
|
498
527
|
:term_mappings => term_mappings,
|
499
528
|
:vocab => default_vocabulary,
|
500
529
|
:restrictions => TERMorCURIEorAbsURI[@version])
|
501
530
|
|
502
|
-
add_debug(element, "traverse,
|
503
|
-
add_debug(element, "traverse, property: #{property.nil? ? 'nil' : property}, typeof: #{typeof.nil? ? 'nil' : typeof}, datatype: #{datatype.nil? ? 'nil' : datatype}, content: #{content.nil? ? 'nil' : content}")
|
504
|
-
add_debug(element, "traverse, rels: #{rels.join(" ")}, revs: #{revs.join(" ")}")
|
531
|
+
add_debug(element, "traverse, rels: #{rels.join(" ")}, revs: #{revs.join(" ")}") unless (rels + revs).empty?
|
505
532
|
|
506
533
|
if !(rel || rev)
|
507
534
|
# Establishing a new subject if no rel/rev [7.5 Step 6]
|
508
535
|
# May not be valid, but can exist
|
509
536
|
new_subject = if about
|
510
|
-
process_uri(element, about, evaluation_context,
|
537
|
+
process_uri(element, about, evaluation_context, base,
|
511
538
|
:uri_mappings => uri_mappings,
|
512
539
|
:restrictions => SafeCURIEorCURIEorURI[@version])
|
513
540
|
elsif src
|
514
|
-
process_uri(element, src, evaluation_context, :restrictions => [:uri])
|
541
|
+
process_uri(element, src, evaluation_context, base, :restrictions => [:uri])
|
515
542
|
elsif resource
|
516
|
-
process_uri(element, resource, evaluation_context,
|
543
|
+
process_uri(element, resource, evaluation_context, base,
|
517
544
|
:uri_mappings => uri_mappings,
|
518
545
|
:restrictions => SafeCURIEorCURIEorURI[@version])
|
519
546
|
elsif href
|
520
|
-
process_uri(element, href, evaluation_context, :restrictions => [:uri])
|
547
|
+
process_uri(element, href, evaluation_context, base, :restrictions => [:uri])
|
521
548
|
end
|
522
549
|
|
523
550
|
# If no URI is provided by a resource attribute, then the first match from the following rules
|
@@ -526,11 +553,14 @@ module RdfContext
|
|
526
553
|
# otherwise,
|
527
554
|
# if parent object is present, new subject is set to the value of parent object.
|
528
555
|
# Additionally, if @property is not present then the skip element flag is set to 'true';
|
529
|
-
new_subject ||= if @host_language == :xhtml && element.name =~ /^(head|body)$/ &&
|
556
|
+
new_subject ||= if @host_language == :xhtml && element.name =~ /^(head|body)$/ && base
|
530
557
|
# From XHTML+RDFa 1.1:
|
531
558
|
# if no URI is provided, then first check to see if the element is the head or body element.
|
532
559
|
# If it is, then act as if there is an empty @about present, and process it according to the rule for @about.
|
533
|
-
|
560
|
+
base
|
561
|
+
elsif @host_language != :xhtml && base
|
562
|
+
# XXX Spec confusion, assume that this is true
|
563
|
+
base
|
534
564
|
elsif element.attributes['typeof']
|
535
565
|
BNode.new
|
536
566
|
else
|
@@ -543,10 +573,10 @@ module RdfContext
|
|
543
573
|
# [7.5 Step 7]
|
544
574
|
# If the current element does contain a @rel or @rev attribute, then the next step is to
|
545
575
|
# establish both a value for new subject and a value for current object resource:
|
546
|
-
new_subject = process_uri(element, about, evaluation_context,
|
576
|
+
new_subject = process_uri(element, about, evaluation_context, base,
|
547
577
|
:uri_mappings => uri_mappings,
|
548
578
|
:restrictions => SafeCURIEorCURIEorURI[@version]) ||
|
549
|
-
process_uri(element, src, evaluation_context,
|
579
|
+
process_uri(element, src, evaluation_context, base,
|
550
580
|
:uri_mappings => uri_mappings,
|
551
581
|
:restrictions => [:uri])
|
552
582
|
|
@@ -555,7 +585,7 @@ module RdfContext
|
|
555
585
|
# From XHTML+RDFa 1.1:
|
556
586
|
# if no URI is provided, then first check to see if the element is the head or body element.
|
557
587
|
# If it is, then act as if there is an empty @about present, and process it according to the rule for @about.
|
558
|
-
|
588
|
+
base
|
559
589
|
elsif element.attributes['typeof']
|
560
590
|
BNode.new
|
561
591
|
else
|
@@ -566,11 +596,11 @@ module RdfContext
|
|
566
596
|
|
567
597
|
# Then the current object resource is set to the URI obtained from the first match from the following rules:
|
568
598
|
current_object_resource = if resource
|
569
|
-
process_uri(element, resource, evaluation_context,
|
599
|
+
process_uri(element, resource, evaluation_context, base,
|
570
600
|
:uri_mappings => uri_mappings,
|
571
601
|
:restrictions => SafeCURIEorCURIEorURI[@version])
|
572
602
|
elsif href
|
573
|
-
process_uri(element, href, evaluation_context,
|
603
|
+
process_uri(element, href, evaluation_context, base,
|
574
604
|
:restrictions => [:uri])
|
575
605
|
end
|
576
606
|
|
@@ -580,7 +610,7 @@ module RdfContext
|
|
580
610
|
# Process @typeof if there is a subject [Step 8]
|
581
611
|
if new_subject and typeof
|
582
612
|
# Typeof is TERMorCURIEorAbsURIs
|
583
|
-
types = process_uris(element, typeof, evaluation_context,
|
613
|
+
types = process_uris(element, typeof, evaluation_context, base,
|
584
614
|
:uri_mappings => uri_mappings,
|
585
615
|
:term_mappings => term_mappings,
|
586
616
|
:vocab => default_vocabulary,
|
@@ -616,7 +646,7 @@ module RdfContext
|
|
616
646
|
|
617
647
|
# Establish current object literal [Step 11]
|
618
648
|
if property
|
619
|
-
properties = process_uris(element, property, evaluation_context,
|
649
|
+
properties = process_uris(element, property, evaluation_context, base,
|
620
650
|
:uri_mappings => uri_mappings,
|
621
651
|
:term_mappings => term_mappings,
|
622
652
|
:vocab => default_vocabulary,
|
@@ -636,7 +666,7 @@ module RdfContext
|
|
636
666
|
children_node_types = element.children.collect{|c| c.class}.uniq
|
637
667
|
|
638
668
|
# the following 3 IF clauses should be mutually exclusive. Written as is to prevent extensive indentation.
|
639
|
-
datatype = process_uri(element, datatype, evaluation_context,
|
669
|
+
datatype = process_uri(element, datatype, evaluation_context, base,
|
640
670
|
:uri_mappings => uri_mappings,
|
641
671
|
:term_mappings => term_mappings,
|
642
672
|
:vocab => default_vocabulary,
|
@@ -651,18 +681,12 @@ module RdfContext
|
|
651
681
|
add_debug(element, "[Step 11(1.1)] XML Literal: #{element.inner_html}")
|
652
682
|
|
653
683
|
# In order to maintain maximum portability of this literal, any children of the current node that are
|
654
|
-
# elements must have the current in scope
|
655
|
-
#
|
656
|
-
#
|
657
|
-
#
|
658
|
-
#
|
659
|
-
|
660
|
-
Literal.typed(element.children, XML_LITERAL,
|
661
|
-
:language => language,
|
662
|
-
:namespaces => uri_mappings,
|
663
|
-
:profiles => profiles,
|
664
|
-
:prefixes => uri_mappings,
|
665
|
-
:default_vocabulary => default_vocabulary)
|
684
|
+
# elements must have the current in scope XML namespace declarations (if any) declared on the
|
685
|
+
# serialized element using their respective attributes. Since the child element node could also
|
686
|
+
# declare new XML namespaces, the RDFa Processor must be careful to merge these together when
|
687
|
+
# generating the serialized element definition. For avoidance of doubt, any re-declarations on the
|
688
|
+
# child node must take precedence over declarations that were active on the current node.
|
689
|
+
Literal.typed(element.children, XML_LITERAL, :language => language, :namespaces => namespaces)
|
666
690
|
else
|
667
691
|
# plain literal
|
668
692
|
add_debug(element, "[Step 11(1.1)] plain literal")
|
@@ -677,7 +701,7 @@ module RdfContext
|
|
677
701
|
# XML Literal
|
678
702
|
add_debug(element, "[Step 11 (1.0)] XML Literal: #{element.inner_html}")
|
679
703
|
recurse = false
|
680
|
-
Literal.typed(element.children, XML_LITERAL, :language => language, :namespaces =>
|
704
|
+
Literal.typed(element.children, XML_LITERAL, :language => language, :namespaces => namespaces)
|
681
705
|
end
|
682
706
|
end
|
683
707
|
|
@@ -706,29 +730,30 @@ module RdfContext
|
|
706
730
|
uri_mappings == evaluation_context.uri_mappings &&
|
707
731
|
term_mappings == evaluation_context.term_mappings &&
|
708
732
|
default_vocabulary == evaluation_context.default_vocabulary &&
|
709
|
-
|
733
|
+
base == evaluation_context.base
|
710
734
|
new_ec = evaluation_context
|
711
735
|
add_debug(element, "[Step 13] skip: reused ec")
|
712
736
|
else
|
713
737
|
new_ec = evaluation_context.clone
|
738
|
+
new_ec.base = base
|
714
739
|
new_ec.language = language
|
715
740
|
new_ec.uri_mappings = uri_mappings
|
741
|
+
new_ec.namespaces = namespaces
|
716
742
|
new_ec.term_mappings = term_mappings
|
717
743
|
new_ec.default_vocabulary = default_vocabulary
|
718
|
-
new_ec.profiles = profiles
|
719
744
|
add_debug(element, "[Step 13] skip: cloned ec")
|
720
745
|
end
|
721
746
|
else
|
722
747
|
# create a new evaluation context
|
723
|
-
new_ec = EvaluationContext.new(
|
748
|
+
new_ec = EvaluationContext.new(base, @host_defaults)
|
724
749
|
new_ec.parent_subject = new_subject || evaluation_context.parent_subject
|
725
750
|
new_ec.parent_object = current_object_resource || new_subject || evaluation_context.parent_subject
|
726
751
|
new_ec.uri_mappings = uri_mappings
|
752
|
+
new_ec.namespaces = namespaces
|
727
753
|
new_ec.incomplete_triples = incomplete_triples
|
728
754
|
new_ec.language = language
|
729
755
|
new_ec.term_mappings = term_mappings
|
730
756
|
new_ec.default_vocabulary = default_vocabulary
|
731
|
-
new_ec.profiles = profiles
|
732
757
|
add_debug(element, "[Step 13] new ec")
|
733
758
|
end
|
734
759
|
|
@@ -740,13 +765,13 @@ module RdfContext
|
|
740
765
|
end
|
741
766
|
|
742
767
|
# space-separated TERMorCURIEorAbsURI or SafeCURIEorCURIEorURI
|
743
|
-
def process_uris(element, value, evaluation_context, options)
|
768
|
+
def process_uris(element, value, evaluation_context, base, options)
|
744
769
|
return [] if value.to_s.empty?
|
745
770
|
add_debug(element, "process_uris: #{value}")
|
746
|
-
value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, options)}.compact
|
771
|
+
value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, base, options)}.compact
|
747
772
|
end
|
748
773
|
|
749
|
-
def process_uri(element, value, evaluation_context, options = {})
|
774
|
+
def process_uri(element, value, evaluation_context, base, options = {})
|
750
775
|
return if value.nil?
|
751
776
|
restrictions = options[:restrictions]
|
752
777
|
add_debug(element, "process_uri: #{value}, restrictions = #{restrictions.inspect}")
|
@@ -779,7 +804,7 @@ module RdfContext
|
|
779
804
|
elsif restrictions.include?(:absuri) || restrictions.include?(:uri)
|
780
805
|
begin
|
781
806
|
# AbsURI does not use xml:base
|
782
|
-
uri = URIRef.intern(value, restrictions.include?(:absuri) ? nil :
|
807
|
+
uri = URIRef.intern(value, restrictions.include?(:absuri) ? nil : base, :normalize => false)
|
783
808
|
rescue Addressable::URI::InvalidURIError => e
|
784
809
|
add_warning(element, "Malformed prefix #{value}", RDFA_NS.UnresolvedCURIE)
|
785
810
|
rescue ParserException => e
|