rdf-rdfa 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -45,13 +45,13 @@ One significant RDF feature missing from RDFa was support for ordered collection
45
45
  )
46
46
  ]
47
47
 
48
- defines a playlist with an ordered set of tracks. RDFa adds the @member attribute, which is used to identify values (object or literal) that are to be placed in a list. The same playlist might be defined in RDFa as follows:
48
+ defines a playlist with an ordered set of tracks. RDFa adds the @inlist attribute, which is used to identify values (object or literal) that are to be placed in a list. The same playlist might be defined in RDFa as follows:
49
49
 
50
50
  <div vocab="http://schema.org/" typeof="MusicPlaylist">
51
51
  <span property="name">Classic Rock Playlist</span>
52
52
  <meta property="numTracks" content="5"/>
53
53
 
54
- <div rel="tracks" member="">
54
+ <div rel="tracks" inlist="">
55
55
  <div typeof="MusicRecording">
56
56
  1.<span property="name">Sweet Home Alabama</span> -
57
57
  <span property="byArtist">Lynard Skynard</span>
@@ -160,27 +160,27 @@ The template hash defines four Haml templates:
160
160
  as those provided by a previous Reader. _title_ is taken from the first top-level subject
161
161
  having an appropriate title property (as defined by the _heading_predicates_ option).
162
162
 
163
- * _subject_: Subject Template, take a _subject_ and an order list of _predicate_s and yields
163
+ * _subject_: Subject Template, take a _subject_ and an ordered list of _predicate_s and yields
164
164
  each _predicate_ to be rendered. Described further in {RDF::RDFa::Writer#render_subject}.
165
165
 
166
166
  - if element == :li
167
- %li{:about => get_curie(subject), :typeof => typeof}
167
+ %li{:rel => rel, :resource => resource, :inlist => inlist}
168
168
  - if typeof
169
- %span.type!= typeof
169
+ %span{:rel => 'rdf:type', :resource => typeof}.type!= typeof
170
170
  - predicates.each do |predicate|
171
171
  != yield(predicate)
172
172
  - elsif rel && typeof
173
- %div{:rel => get_curie(rel)}
174
- %div{:about => get_curie(subject), :typeof => typeof}
173
+ %div{:rel => rel}
174
+ %div{:about => resource, :typeof => typeof}
175
175
  %span.type!= typeof
176
176
  - predicates.each do |predicate|
177
177
  != yield(predicate)
178
178
  - elsif rel
179
- %div{:rel => get_curie(rel), :resource => get_curie(subject)}
179
+ %div{:rel => rel, :resource => resource}
180
180
  - predicates.each do |predicate|
181
181
  != yield(predicate)
182
182
  - else
183
- %div{:about => get_curie(subject), :typeof => typeof}
183
+ %div{:about => about, :typeof => typeof}
184
184
  - if typeof
185
185
  %span.type!= typeof
186
186
  - predicates.each do |predicate|
@@ -198,27 +198,27 @@ The template hash defines four Haml templates:
198
198
  * _property\_value_: Property Value Template, used for predicates having a single value; takes
199
199
  a _predicate_, and a single-valued Array of _objects_. Described further in {RDF::RDFa::Writer#render\_property}.
200
200
 
201
- - object = objects.first
202
201
  - if heading_predicates.include?(predicate) && object.literal?
203
- %h1{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object)}&= get_value(object)
202
+ %h1{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}= escape_entities(get_value(object))
204
203
  - else
205
204
  %div.property
206
205
  %span.label
207
206
  = get_predicate_name(predicate)
208
207
  - if res = yield(object)
209
208
  != res
209
+ - elsif get_curie(object) == 'rdf:nil'
210
+ %span{:rel => get_curie(predicate), :inlist => ''}
210
211
  - elsif object.node?
211
- %span{:resource => get_curie(object), :rel => get_curie(predicate)}= get_curie(object)
212
+ %span{:resource => get_curie(object), :rel => get_curie(predicate), :inlist => inlist}= get_curie(object)
212
213
  - elsif object.uri?
213
- %a{:href => object.to_s, :rel => get_curie(predicate)}= object.to_s
214
+ %a{:href => object.to_s, :rel => get_curie(predicate), :inlist => inlist}= object.to_s
214
215
  - elsif object.datatype == RDF.XMLLiteral
215
- %span{:property => get_curie(predicate), :lang => get_lang(object), :datatype => get_dt_curie(object)}<!= get_value(object)
216
+ %span{:property => get_curie(predicate), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}<!= get_value(object)
216
217
  - else
217
- %span{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object)}&= get_value(object)
218
+ %span{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}= escape_entities(get_value(object))
218
219
 
219
- In addition to _predicate_ and _objects_, the template takes locals _property_ and/or _rel_, which are
220
- copies of _predicate_ and indicate use in the @property or @rel attributes. Either or both may be
221
- specified, as the conditions dictate.
220
+ In addition to _predicate_ and _objects_, the template takes _inlist_ to indicate that the
221
+ property is part of an rdf:List.
222
222
 
223
223
  Also, if the predicate is identified as a _heading predicate_ (via _:heading\_predicates_ option),
224
224
  it will generate a heading element, and may use the value as the document title.
@@ -244,19 +244,19 @@ The template hash defines four Haml templates:
244
244
  %div.property
245
245
  %span.label
246
246
  = get_predicate_name(predicate)
247
- %ul{:rel => (get_curie(rel) if rel), :property => (get_curie(property) if property)}
247
+ %ul
248
248
  - objects.each do |object|
249
249
  - if res = yield(object)
250
250
  != res
251
251
  - elsif object.node?
252
- %li{:resource => get_curie(object)}= get_curie(object)
252
+ %li{:rel => get_curie(predicate), :resource => get_curie(object), :inlist => inlist}= get_curie(object)
253
253
  - elsif object.uri?
254
254
  %li
255
- %a{:href => object.to_s}= object.to_s
255
+ %a{:rel => get_curie(predicate), :href => object.to_s, :inlist => inlist}= object.to_s
256
256
  - elsif object.datatype == RDF.XMLLiteral
257
- %li{:lang => get_lang(object), :datatype => get_curie(object.datatype)}<!= get_value(object)
257
+ %li{:property => get_curie(predicate), :lang => get_lang(object), :datatype => get_curie(object.datatype), :inlist => inlist}<!= get_value(object)
258
258
  - else
259
- %li{:content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object)}&= get_value(object)
259
+ %li{:property => get_curie(predicate), :content => get_content(object), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}= escape_entities(get_value(object))
260
260
 
261
261
  In this case, and unordered list is used for output. Creates output similar to the following:
262
262
 
@@ -330,7 +330,7 @@ Full documentation available on [Rubydoc.info][RDFa doc]
330
330
  ## Resources
331
331
  * [RDF.rb][RDF.rb]
332
332
  * [Distiller](http://rdf.greggkellogg.net/distiller)
333
- * [Documentation](http://rdf.rubyforge.org/rdfa)
333
+ * [Documentation][RDFa doc]
334
334
  * [History](file:file.History.html)
335
335
  * [RDFa 1.1 Core][RDFa 1.1 Core]
336
336
  * [XHTML+RDFa 1.1][XHTML+RDFa 1.1]
@@ -375,6 +375,6 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
375
375
  [RDFa 1.1 Core]: http://www.w3.org/TR/2011/WD-rdfa-core-20110331/ "RDFa 1.1 Core"
376
376
  [XHTML+RDFa 1.1]: http://www.w3.org/TR/2011/WD-xhtml-rdfa-20110331/ "XHTML+RDFa 1.1"
377
377
  [RDFa-test-suite]: http://rdfa.digitalbazaar.com/test-suite/ "RDFa test suite"
378
- [RDFa doc]: http://rubydoc.info/github/gkellogg/rdf-rdfa/master/file/README.markdown
378
+ [RDFa doc]: http://rubydoc.info/github/gkellogg/rdf-rdfa/frames
379
379
  [Haml]: http://haml-lang.com/
380
380
  [Turtle]: http://www.w3.org/TR/2011/WD-turtle-20110809/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
@@ -19,17 +19,18 @@ module RDF::RDFa
19
19
  # Subsequently, perform RDFS expansion using rules rdfs5, rdfs7, rdfs9, and rdfs11 placing
20
20
  # resulting triples into the default graph. Iterate on this step until no more triples are added.
21
21
  #
22
+ # @example
22
23
  # rdfs5
23
- # {uuu rdfs:subPropertyOf vvv . vvv rdfs:subPropertyOf xxx} => { uuu rdfs:subPropertyOf xxx}
24
+ # {uuu rdfs:subPropertyOf vvv . vvv rdfs:subPropertyOf xxx} => {uuu rdfs:subPropertyOf xxx}
24
25
  #
25
26
  # rdfs7
26
- # {aaa rdfs:subPropertyOf bbb . uuu aaa yyy} => { uuu bbb yyy}
27
+ # {aaa rdfs:subPropertyOf bbb . uuu aaa yyy} => {uuu bbb yyy}
27
28
  #
28
29
  # rdfs9
29
- # {uuu rdfs:subClassOf xxx . vvv rdf:type uuu} => { vvv rdf:type xxx}
30
+ # {uuu rdfs:subClassOf xxx . vvv rdf:type uuu} => {vvv rdf:type xxx}
30
31
  #
31
32
  # rdfs11
32
- # {uuu rdfs:subClassOf vvv . vvv rdfs:subClassOf xxx} => { uuu rdfs:subClassOf xxx}
33
+ # {uuu rdfs:subClassOf vvv . vvv rdfs:subClassOf xxx} => {uuu rdfs:subClassOf xxx}
33
34
  #
34
35
  # @return [RDF::Graph]
35
36
  def expand
@@ -41,9 +42,8 @@ module RDF::RDFa
41
42
 
42
43
  # Vocabularies managed in vocab_repo, and copied to repo for processing.
43
44
  # This allows for persistent storage of vocabularies
44
- @@vocab_repo ||= @options[:vocab_repository] || begin
45
- RDF::Repository.new.insert(*COOKED_VOCAB_STATEMENTS)
46
- end
45
+ @@vocab_repo = @options[:vocab_repository] if @options.has_key?(:vocab_repository)
46
+ @@vocab_repo ||= RDF::Repository.new.insert(*COOKED_VOCAB_STATEMENTS)
47
47
 
48
48
  vocabs = repo.query(:predicate => RDF::RDFA.hasVocabulary).to_a.map(&:object)
49
49
  vocabs.each do |vocab|
@@ -22,6 +22,21 @@ module RDF::RDFa
22
22
  content_type 'text/html', :extension => :html
23
23
  reader { RDF::RDFa::Reader }
24
24
  writer { RDF::RDFa::Writer }
25
+
26
+ ##
27
+ # Sample detection to see if it matches RDFa (not RDF/XML or Microdata)
28
+ #
29
+ # Use a text sample to detect the format of an input file. Sub-classes implement
30
+ # a matcher sufficient to detect probably format matches, including disambiguating
31
+ # between other similar formats.
32
+ #
33
+ # @param [String] sample Beginning several bytes (~ 1K) of input.
34
+ # @return [Boolean]
35
+ def self.detect(sample)
36
+ (sample.match(/<[^>]*(about|resource|prefix|typeof|property|vocab)\s*="[^>]*>/m) ||
37
+ sample.match(/<[^>]*DOCTYPE\s+html[^>]*>.*xmlns:/im)
38
+ ) && !sample.match(/<(\w+:)?(RDF)/)
39
+ end
25
40
  end
26
41
 
27
42
  # Aliases for RDFa::Format
@@ -34,7 +49,6 @@ module RDF::RDFa
34
49
  # RDF::Format.for(:html).writer # RDF::RDFa::Writer
35
50
  class HTML < RDF::Format
36
51
  content_encoding 'utf-8'
37
- content_type 'text/html', :extension => :html
38
52
  reader { RDF::RDFa::Reader }
39
53
  writer { RDF::RDFa::Writer }
40
54
  end
@@ -1,4 +1,5 @@
1
1
  require 'nokogiri' # FIXME: Implement using different modules as in RDF::TriX
2
+ require 'rdf/ntriples'
2
3
 
3
4
  module RDF::RDFa
4
5
  ##
@@ -50,12 +51,6 @@ module RDF::RDFa
50
51
  # @attr [:"rdfa1.0", :"rdfa1.1"]
51
52
  attr_reader :version
52
53
 
53
- ##
54
- # Returns the base URI determined by this reader.
55
- #
56
- # @attr [RDF::URI]
57
- attr_reader :base_uri
58
-
59
54
  # The Recursive Baggage
60
55
  # @private
61
56
  class EvaluationContext # :nodoc:
@@ -143,11 +138,11 @@ module RDF::RDFa
143
138
  attr :default_vocabulary, true
144
139
 
145
140
  ##
146
- # collections
141
+ # lists
147
142
  #
148
- # A hash associating collections with properties.
143
+ # A hash associating lists with properties.
149
144
  # @attr [Hash{RDF::URI => Array<RDF::Resource>}]
150
- attr :collection_mappings, true
145
+ attr :list_mapping, true
151
146
 
152
147
  # @param [RDF::URI] base
153
148
  # @param [Hash] host_defaults
@@ -174,7 +169,7 @@ module RDF::RDFa
174
169
  @uri_mappings = from.uri_mappings.clone
175
170
  @incomplete_triples = from.incomplete_triples.clone
176
171
  @namespaces = from.namespaces.clone
177
- @collection_mappings = from.collection_mappings # Don't clone
172
+ @list_mapping = from.list_mapping # Don't clone
178
173
  end
179
174
 
180
175
  def inspect
@@ -184,7 +179,7 @@ module RDF::RDFa
184
179
  v << "uri_mappings[#{uri_mappings.keys.length}]"
185
180
  v << "incomplete_triples[#{incomplete_triples.length}]"
186
181
  v << "term_mappings[#{term_mappings.keys.length}]"
187
- v << "collections[#{collection_mappings.keys.length}]" if collection_mappings
182
+ v << "lists[#{list_mapping.keys.length}]" if list_mapping
188
183
  v.join(", ")
189
184
  end
190
185
  end
@@ -228,7 +223,6 @@ module RDF::RDFa
228
223
  def initialize(input = $stdin, options = {}, &block)
229
224
  super do
230
225
  @debug = options[:debug]
231
- @base_uri = uri(options[:base_uri])
232
226
 
233
227
  detect_host_language_version(input, options)
234
228
 
@@ -246,17 +240,17 @@ module RDF::RDFa
246
240
 
247
241
  case @host_language
248
242
  when :html4, :html5
249
- Nokogiri::HTML.parse(input, @base_uri.to_s, options[:encoding])
243
+ Nokogiri::HTML.parse(input, base_uri.to_s, options[:encoding])
250
244
  else
251
- Nokogiri::XML.parse(input, @base_uri.to_s, options[:encoding])
245
+ Nokogiri::XML.parse(input, base_uri.to_s, options[:encoding])
252
246
  end
253
247
  end
254
248
 
255
- if (@doc.nil? || @doc.root.nil?)
249
+ if ((@doc.nil? || @doc.root.nil?) && validate?)
256
250
  add_error(nil, "Empty document", RDF::RDFA.DocumentError)
257
251
  raise RDF::ReaderError, "Empty Document"
258
252
  end
259
- add_warning(nil, "Synax errors:\n#{@doc.errors}", RDF::RDFA.DocumentError) if !@doc.errors.empty? && validate?
253
+ add_warning(nil, "Syntax errors:\n#{@doc.errors}", RDF::RDFA.DocumentError) if !@doc.errors.empty? && validate?
260
254
 
261
255
  # Section 4.2 RDFa Host Language Conformance
262
256
  #
@@ -316,7 +310,7 @@ module RDF::RDFa
316
310
  input.rewind
317
311
  string = input.read(1000)
318
312
  input.rewind
319
- string
313
+ string.to_s
320
314
  else
321
315
  input.to_s[0..1000]
322
316
  end
@@ -394,7 +388,7 @@ module RDF::RDFa
394
388
  end
395
389
 
396
390
  # parse
397
- parse_whole_document(@doc, @base_uri)
391
+ parse_whole_document(@doc, RDF::URI(base_uri))
398
392
  end
399
393
  end
400
394
 
@@ -422,7 +416,7 @@ module RDF::RDFa
422
416
 
423
417
  # Figure out the document path, if it is a Nokogiri::XML::Element or Attribute
424
418
  def node_path(node)
425
- "<#{@base_uri}>" + case node
419
+ "<#{base_uri}>" + case node
426
420
  when Nokogiri::XML::Node then node.display_path
427
421
  else node.to_s
428
422
  end
@@ -460,7 +454,7 @@ module RDF::RDFa
460
454
  @processor_graph << RDF::Statement.new(n, RDF["type"], process_class)
461
455
  @processor_graph << RDF::Statement.new(n, RDF::DC.description, message)
462
456
  @processor_graph << RDF::Statement.new(n, RDF::DC.date, RDF::Literal::Date.new(DateTime.now))
463
- @processor_graph << RDF::Statement.new(n, RDF::RDFA.context, @base_uri)
457
+ @processor_graph << RDF::Statement.new(n, RDF::RDFA.context, base_uri)
464
458
  nc = RDF::Node.new
465
459
  @processor_graph << RDF::Statement.new(nc, RDF["type"], RDF::PTR.XPathPointer)
466
460
  @processor_graph << RDF::Statement.new(nc, RDF::PTR.expression, node.path) if node.respond_to?(:path)
@@ -528,7 +522,7 @@ module RDF::RDFa
528
522
  map {|uri| uri(uri).normalize}.
529
523
  each do |uri|
530
524
  # Don't try to open ourselves!
531
- if @base_uri == uri
525
+ if base_uri == uri
532
526
  add_debug(element, "process_profile: skip recursive profile <#{uri}>")
533
527
  next
534
528
  end
@@ -637,7 +631,7 @@ module RDF::RDFa
637
631
  language = evaluation_context.language
638
632
  term_mappings = evaluation_context.term_mappings.clone
639
633
  default_vocabulary = evaluation_context.default_vocabulary
640
- collection_mappings = evaluation_context.collection_mappings
634
+ list_mapping = evaluation_context.list_mapping
641
635
 
642
636
  # shortcut
643
637
  attrs = element.attributes
@@ -659,12 +653,12 @@ module RDF::RDFa
659
653
  rel = attrs['rel'].to_s.strip if attrs['rel']
660
654
  rev = attrs['rev'].to_s.strip if attrs['rev']
661
655
 
662
- # Collections:
663
- # @member
656
+ # Lists:
657
+ # @inlist
664
658
  # an attribute (value ignored) used to indicate that the object associated with a
665
- # @rel or @property attribute on the same element is to be added to the collection
666
- # for that property. Causes a collection to be created if it does not already exist.
667
- member = attrs['member'].to_s.strip if attrs.has_key?('member')
659
+ # @rel or @property attribute on the same element is to be added to the list
660
+ # for that property. Causes a list to be created if it does not already exist.
661
+ inlist = attrs['inlist'].to_s.strip if attrs.has_key?('inlist')
668
662
 
669
663
  add_debug(element) do
670
664
  attrs = {
@@ -679,7 +673,7 @@ module RDF::RDFa
679
673
  :datatype => datatype,
680
674
  :rel => rel,
681
675
  :rev => rev,
682
- :member => member,
676
+ :inlist => inlist,
683
677
  }.select {|k,v| v}
684
678
 
685
679
  "attrs " + attrs.map {|a| "#{a.first}: #{a.last}"}.join(", ")
@@ -738,12 +732,12 @@ module RDF::RDFa
738
732
  :uri_mappings => uri_mappings,
739
733
  :term_mappings => term_mappings,
740
734
  :vocab => default_vocabulary,
741
- :restrictions => TERMorCURIEorAbsURI[@version])
735
+ :restrictions => TERMorCURIEorAbsURI.fetch(@version, []))
742
736
  revs = process_uris(element, rev, evaluation_context, base,
743
737
  :uri_mappings => uri_mappings,
744
738
  :term_mappings => term_mappings,
745
739
  :vocab => default_vocabulary,
746
- :restrictions => TERMorCURIEorAbsURI[@version])
740
+ :restrictions => TERMorCURIEorAbsURI.fetch(@version, []))
747
741
 
748
742
  add_debug(element) do
749
743
  "rels: #{rels.join(" ")}, revs: #{revs.join(" ")}"
@@ -755,15 +749,15 @@ module RDF::RDFa
755
749
  new_subject = if about
756
750
  process_uri(element, about, evaluation_context, base,
757
751
  :uri_mappings => uri_mappings,
758
- :restrictions => SafeCURIEorCURIEorURI[@version])
759
- elsif src
760
- process_uri(element, src, evaluation_context, base, :restrictions => [:uri])
752
+ :restrictions => SafeCURIEorCURIEorURI.fetch(@version, []))
761
753
  elsif resource
762
754
  process_uri(element, resource, evaluation_context, base,
763
755
  :uri_mappings => uri_mappings,
764
- :restrictions => SafeCURIEorCURIEorURI[@version])
756
+ :restrictions => SafeCURIEorCURIEorURI.fetch(@version, []))
765
757
  elsif href
766
758
  process_uri(element, href, evaluation_context, base, :restrictions => [:uri])
759
+ elsif src
760
+ process_uri(element, src, evaluation_context, base, :restrictions => [:uri])
767
761
  end
768
762
 
769
763
  # If no URI is provided by a resource attribute, then the first match from the following rules
@@ -786,17 +780,17 @@ module RDF::RDFa
786
780
  skip = true unless property
787
781
  evaluation_context.parent_object
788
782
  end
789
- add_debug(element, "[Step 5] new_subject: #{new_subject}, skip = #{skip}")
783
+ add_debug(element, "[Step 5] new_subject: #{new_subject.to_ntriples rescue 'nil'}, skip = #{skip}")
790
784
  else
791
785
  # [7.5 Step 6]
792
786
  # If the current element does contain a @rel or @rev attribute, then the next step is to
793
787
  # establish both a value for new subject and a value for current object resource:
794
788
  new_subject = process_uri(element, about, evaluation_context, base,
795
789
  :uri_mappings => uri_mappings,
796
- :restrictions => SafeCURIEorCURIEorURI[@version]) ||
797
- process_uri(element, src, evaluation_context, base,
790
+ :restrictions => SafeCURIEorCURIEorURI.fetch(@version, []))
791
+ new_subject ||= process_uri(element, src, evaluation_context, base,
798
792
  :uri_mappings => uri_mappings,
799
- :restrictions => [:uri])
793
+ :restrictions => [:uri]) if @version == :"rdfa1.0"
800
794
 
801
795
  # If no URI is provided then the first match from the following rules will apply
802
796
  new_subject ||= if element == @doc.root && base
@@ -818,10 +812,13 @@ module RDF::RDFa
818
812
  current_object_resource = if resource
819
813
  process_uri(element, resource, evaluation_context, base,
820
814
  :uri_mappings => uri_mappings,
821
- :restrictions => SafeCURIEorCURIEorURI[@version])
815
+ :restrictions => SafeCURIEorCURIEorURI.fetch(@version, []))
822
816
  elsif href
823
817
  process_uri(element, href, evaluation_context, base,
824
818
  :restrictions => [:uri])
819
+ elsif src && @version != :"rdfa1.0"
820
+ process_uri(element, src, evaluation_context, base,
821
+ :restrictions => [:uri])
825
822
  end
826
823
 
827
824
  add_debug(element, "[Step 6] new_subject: #{new_subject}, current_object_resource = #{current_object_resource.nil? ? 'nil' : current_object_resource}")
@@ -834,40 +831,41 @@ module RDF::RDFa
834
831
  :uri_mappings => uri_mappings,
835
832
  :term_mappings => term_mappings,
836
833
  :vocab => default_vocabulary,
837
- :restrictions => TERMorCURIEorAbsURI[@version])
834
+ :restrictions => TERMorCURIEorAbsURI.fetch(@version, []))
838
835
  add_debug(element, "typeof: #{typeof}")
839
836
  types.each do |one_type|
840
837
  add_triple(element, new_subject, RDF["type"], one_type)
841
838
  end
842
839
  end
843
840
 
844
- # Collections: If new subject is set and is not the same as parent subject,
845
- # replace the collection mappings taken from
846
- # the evaluation context with a new empty mappings.
847
- if (new_subject && new_subject != evaluation_context.parent_subject) || collection_mappings.nil?
848
- collection_mappings = {}
841
+ # Create new List mapping [step 8]
842
+ #
843
+ # If in any of the previous steps a new subject was set to a non-null value different from the parent object;
844
+ # The list mapping taken from the evaluation context is set to a new, empty mapping.
845
+ if (new_subject && (new_subject != evaluation_context.parent_subject || list_mapping.nil?))
846
+ list_mapping = {}
849
847
  add_debug(element) do
850
- "collections: create new collection mappings(#{collection_mappings.object_id}) " +
851
- "ns: #{new_subject}, " +
852
- "ps: #{evaluation_context.parent_subject}"
848
+ "[Step 8]: create new list mapping(#{list_mapping.object_id}) " +
849
+ "ns: #{new_subject.to_ntriples}, " +
850
+ "ps: #{evaluation_context.parent_subject.to_ntriples rescue 'nil'}"
853
851
  end
854
852
  end
855
853
 
856
- # Generate triples with given object [Step 8]
854
+ # Generate triples with given object [Step 9]
857
855
  #
858
- # Collections: if the current element has a @member attribute, add the property to the
859
- # collection associated with that property, creating a new collection if necessary.
856
+ # If the current element has a @inlist attribute, add the property to the
857
+ # list associated with that property, creating a new list if necessary.
860
858
  if new_subject and current_object_resource
861
859
  rels.each do |r|
862
- if member
863
- # If the current collection mappings does not contain a collection associated with this IRI,
864
- # instantiate a new collection
865
- unless collection_mappings[r]
866
- collection_mappings[r] = RDF::List.new
867
- add_debug(element) {"collections(#{r}): create #{collection_mappings[r]}"}
860
+ if inlist
861
+ # If the current list mapping does not contain a list associated with this IRI,
862
+ # instantiate a new list
863
+ unless list_mapping[r]
864
+ list_mapping[r] = RDF::List.new
865
+ add_debug(element) {"list(#{r}): create #{list_mapping[r].inspect}"}
868
866
  end
869
- add_debug(element, "member: add #{current_object_resource} to #{r} collection")
870
- collection_mappings[r] << current_object_resource
867
+ add_debug(element, "[Step 9] add #{current_object_resource.to_ntriples} to #{r} #{list_mapping[r].inspect}")
868
+ list_mapping[r] << current_object_resource
871
869
  else
872
870
  add_triple(element, new_subject, r, current_object_resource)
873
871
  end
@@ -877,23 +875,23 @@ module RDF::RDFa
877
875
  add_triple(element, current_object_resource, r, new_subject)
878
876
  end
879
877
  elsif rel || rev
880
- # Incomplete triples and bnode creation [Step 9]
881
- add_debug(element) {"[Step 9] incompletes: rels: #{rels}, revs: #{revs}"}
878
+ # Incomplete triples and bnode creation [Step 10]
879
+ add_debug(element) {"[Step 10] incompletes: rels: #{rels}, revs: #{revs}"}
882
880
  current_object_resource = RDF::Node.new
883
881
 
884
882
  # predicate: full IRI
885
883
  # direction: forward/reverse
886
- # collection: Save into collection, don't generate triple
884
+ # lists: Save into list, don't generate triple
887
885
 
888
886
  rels.each do |r|
889
- if member
890
- # If the current collection mappings does not contain a collection associated with this IRI,
891
- # instantiate a new collection
892
- unless collection_mappings[r]
893
- collection_mappings[r] = RDF::List.new
894
- add_debug(element) {"collections(#{r}): create #{collection_mappings[r]}"}
887
+ if inlist
888
+ # If the current list mapping does not contain a list associated with this IRI,
889
+ # instantiate a new list
890
+ unless list_mapping[r]
891
+ list_mapping[r] = RDF::List.new
892
+ add_debug(element) {"[Step 10] list(#{r}): create #{list_mapping[r].inspect}"}
895
893
  end
896
- incomplete_triples << {:collection => collection_mappings[r]}
894
+ incomplete_triples << {:list => list_mapping[r], :direction => :none}
897
895
  else
898
896
  incomplete_triples << {:predicate => r, :direction => :forward}
899
897
  end
@@ -904,22 +902,22 @@ module RDF::RDFa
904
902
  end
905
903
  end
906
904
 
907
- # Establish current object literal [Step 10]
905
+ # Establish current object literal [Step 11]
908
906
  #
909
- # Collections: if the current element has a @member attribute, add the property to the
910
- # collection associated with that property, creating a new collection if necessary.
907
+ # If the current element has a @inlist attribute, add the property to the
908
+ # list associated with that property, creating a new list if necessary.
911
909
  if property
912
910
  properties = process_uris(element, property, evaluation_context, base,
913
911
  :uri_mappings => uri_mappings,
914
912
  :term_mappings => term_mappings,
915
913
  :vocab => default_vocabulary,
916
- :restrictions => TERMorCURIEorAbsURIprop[@version])
914
+ :restrictions => TERMorCURIEorAbsURIprop.fetch(@version, []))
917
915
 
918
916
  properties.reject! do |p|
919
917
  if p.is_a?(RDF::URI)
920
918
  false
921
919
  else
922
- add_debug(element, "predicate #{p.inspect} must be a URI")
920
+ add_debug(element, "[Step 11] predicate #{p.to_ntriples} must be a URI")
923
921
  true
924
922
  end
925
923
  end
@@ -932,16 +930,16 @@ module RDF::RDFa
932
930
  :uri_mappings => uri_mappings,
933
931
  :term_mappings => term_mappings,
934
932
  :vocab => default_vocabulary,
935
- :restrictions => TERMorCURIEorAbsURI[@version]) unless datatype.to_s.empty?
933
+ :restrictions => TERMorCURIEorAbsURI.fetch(@version, [])) unless datatype.to_s.empty?
936
934
  begin
937
935
  current_object_literal = if !datatype.to_s.empty? && datatype.to_s != RDF.XMLLiteral.to_s
938
936
  # typed literal
939
- add_debug(element, "[Step 10] typed literal (#{datatype})")
937
+ add_debug(element, "[Step 11] typed literal (#{datatype})")
940
938
  RDF::Literal.new(content || element.inner_text.to_s, :datatype => datatype, :language => language, :validate => validate?, :canonicalize => canonicalize?)
941
939
  elsif @version == :"rdfa1.1"
942
940
  if datatype.to_s == RDF.XMLLiteral.to_s
943
941
  # XML Literal
944
- add_debug(element) {"[Step 10(1.1)] XML Literal: #{element.inner_html}"}
942
+ add_debug(element) {"[Step 11(1.1)] XML Literal: #{element.inner_html}"}
945
943
 
946
944
  # In order to maintain maximum portability of this literal, any children of the current node that are
947
945
  # elements must have the current in scope XML namespace declarations (if any) declared on the
@@ -961,17 +959,17 @@ module RDF::RDFa
961
959
  end
962
960
  else
963
961
  # plain literal
964
- add_debug(element, "[Step 10(1.1)] plain literal")
962
+ add_debug(element, "[Step 11(1.1)] plain literal")
965
963
  RDF::Literal.new(content || element.inner_text.to_s, :language => language, :validate => validate?, :canonicalize => canonicalize?)
966
964
  end
967
965
  else
968
966
  if content || (children_node_types == [Nokogiri::XML::Text]) || (element.children.length == 0) || datatype == ""
969
967
  # plain literal
970
- add_debug(element, "[Step 10 (1.0)] plain literal")
968
+ add_debug(element, "[Step 11 (1.0)] plain literal")
971
969
  RDF::Literal.new(content || element.inner_text.to_s, :language => language, :validate => validate?, :canonicalize => canonicalize?)
972
970
  elsif children_node_types != [Nokogiri::XML::Text] and (datatype == nil or datatype.to_s == RDF.XMLLiteral.to_s)
973
971
  # XML Literal
974
- add_debug(element) {"[Step 10 (1.0)] XML Literal: #{element.inner_html}"}
972
+ add_debug(element) {"[Step 11 (1.0)] XML Literal: #{element.inner_html}"}
975
973
  recurse = false
976
974
  RDF::Literal.new(element.inner_html,
977
975
  :datatype => RDF.XMLLiteral,
@@ -987,16 +985,16 @@ module RDF::RDFa
987
985
 
988
986
  # add each property
989
987
  properties.each do |p|
990
- # Collections: If element has an @member attribute, add the value to a collection
991
- if member
992
- # If the current collection mappings does not contain a collection associated with this IRI,
993
- # instantiate a new collection
994
- unless collection_mappings[p]
995
- collection_mappings[p] = RDF::List.new
996
- add_debug(element) {"collections(#{p}): create #{collection_mappings[p]}"}
988
+ # Lists: If element has an @inlist attribute, add the value to a list
989
+ if inlist
990
+ # If the current list mapping does not contain a list associated with this IRI,
991
+ # instantiate a new list
992
+ unless list_mapping[p]
993
+ list_mapping[p] = RDF::List.new
994
+ add_debug(element) {"[Step 11] lists(#{p}): create #{list_mapping[p].inspect}"}
997
995
  end
998
- add_debug(element) {"member: add #{current_object_literal} to #{p} collection"}
999
- collection_mappings[p] << current_object_literal
996
+ add_debug(element) {"[Step 11] add #{current_object_literal.to_ntriples} to #{p.to_ntriples} #{list_mapping[p].inspect}"}
997
+ list_mapping[p] << current_object_literal
1000
998
  elsif new_subject
1001
999
  add_triple(element, new_subject, p, current_object_literal)
1002
1000
  end
@@ -1004,26 +1002,27 @@ module RDF::RDFa
1004
1002
  end
1005
1003
 
1006
1004
  if not skip and new_subject && !evaluation_context.incomplete_triples.empty?
1007
- # Complete the incomplete triples from the evaluation context [Step 11]
1005
+ # Complete the incomplete triples from the evaluation context [Step 12]
1008
1006
  add_debug(element) do
1009
- "[Step 11] complete incomplete triples: " +
1010
- "new_subject=#{new_subject.inspect}, " +
1007
+ "[Step 12] complete incomplete triples: " +
1008
+ "new_subject=#{new_subject.to_ntriples}, " +
1011
1009
  "completes=#{evaluation_context.incomplete_triples.inspect}"
1012
1010
  end
1013
1011
 
1014
1012
  evaluation_context.incomplete_triples.each do |trip|
1015
- if trip[:collection]
1016
- add_debug(element) {"member: add #{current_object_resource} to #{trip[:collection]} collection"}
1017
- trip[:collection] << new_subject
1018
- elsif trip[:direction] == :forward
1013
+ case trip[:direction]
1014
+ when :none
1015
+ add_debug(element) {"[Step 12] add #{new_subject.to_ntriples} to #{trip[:list].inspect}"}
1016
+ trip[:list] << new_subject
1017
+ when :forward
1019
1018
  add_triple(element, evaluation_context.parent_subject, trip[:predicate], new_subject)
1020
- elsif trip[:direction] == :reverse
1019
+ when :reverse
1021
1020
  add_triple(element, new_subject, trip[:predicate], evaluation_context.parent_subject)
1022
1021
  end
1023
1022
  end
1024
1023
  end
1025
1024
 
1026
- # Create a new evaluation context and proceed recursively [Step 12]
1025
+ # Create a new evaluation context and proceed recursively [Step 13]
1027
1026
  if recurse
1028
1027
  if skip
1029
1028
  if language == evaluation_context.language &&
@@ -1031,9 +1030,9 @@ module RDF::RDFa
1031
1030
  term_mappings == evaluation_context.term_mappings &&
1032
1031
  default_vocabulary == evaluation_context.default_vocabulary &&
1033
1032
  base == evaluation_context.base &&
1034
- collection_mappings == evaluation_context.collection_mappings
1033
+ list_mapping == evaluation_context.list_mapping
1035
1034
  new_ec = evaluation_context
1036
- add_debug(element, "[Step 12] skip: reused ec")
1035
+ add_debug(element, "[Step 13] skip: reused ec")
1037
1036
  else
1038
1037
  new_ec = evaluation_context.clone
1039
1038
  new_ec.base = base
@@ -1042,8 +1041,8 @@ module RDF::RDFa
1042
1041
  new_ec.namespaces = namespaces
1043
1042
  new_ec.term_mappings = term_mappings
1044
1043
  new_ec.default_vocabulary = default_vocabulary
1045
- new_ec.collection_mappings = collection_mappings
1046
- add_debug(element, "[Step 12] skip: cloned ec")
1044
+ new_ec.list_mapping = list_mapping
1045
+ add_debug(element, "[Step 13] skip: cloned ec")
1047
1046
  end
1048
1047
  else
1049
1048
  # create a new evaluation context
@@ -1056,8 +1055,8 @@ module RDF::RDFa
1056
1055
  new_ec.language = language
1057
1056
  new_ec.term_mappings = term_mappings
1058
1057
  new_ec.default_vocabulary = default_vocabulary
1059
- new_ec.collection_mappings = collection_mappings
1060
- add_debug(element, "[Step 12] new ec")
1058
+ new_ec.list_mapping = list_mapping
1059
+ add_debug(element, "[Step 13] new ec")
1061
1060
  end
1062
1061
 
1063
1062
  element.children.each do |child|
@@ -1065,25 +1064,25 @@ module RDF::RDFa
1065
1064
  traverse(child, new_ec) if child.class == Nokogiri::XML::Element
1066
1065
  end
1067
1066
 
1068
- # Collections: after traversing through child elements, for each collection associated with
1067
+ # Step 14: after traversing through child elements, for each list associated with
1069
1068
  # a property
1070
- collection_mappings.each do |p, c|
1071
- # if that collection is different from the evaluation context
1072
- ec_col = evaluation_context.collection_mappings[p] if evaluation_context.collection_mappings
1073
- add_debug(element) {"collections: time to create #{c}? #{(ec_col != c).inspect}"}
1074
- if ec_col != c
1075
- add_debug(element) {"collection(#{p}) create #{c}"}
1076
- # Generate an rdf:List with the elements of that collection.
1077
- c.each_statement do |st|
1069
+ (list_mapping || {}).each do |p, l|
1070
+ # if that list is different from the evaluation context
1071
+ ec_list = evaluation_context.list_mapping[p] if evaluation_context.list_mapping
1072
+ add_debug(element) {"[Step 14] time to create #{l.inspect}? #{(ec_list != l).inspect}"}
1073
+ if ec_list != l
1074
+ add_debug(element) {"[Step 14] list(#{p}) create #{l.inspect}"}
1075
+ # Generate an rdf:List with the elements of that list.
1076
+ l.each_statement do |st|
1078
1077
  add_triple(element, st.subject, st.predicate, st.object) unless st.object == RDF.List
1079
1078
  end
1080
1079
 
1081
- # Generate a triple relating new_subject, property and the collection BNode,
1082
- # or rdf:nil if the collection is empty.
1083
- if c.empty?
1080
+ # Generate a triple relating new_subject, property and the list BNode,
1081
+ # or rdf:nil if the list is empty.
1082
+ if l.empty?
1084
1083
  add_triple(element, new_subject, p, RDF.nil)
1085
1084
  else
1086
- add_triple(element, new_subject, p, c.subject)
1085
+ add_triple(element, new_subject, p, l.subject)
1087
1086
  end
1088
1087
  end
1089
1088
  end