rdf-rdfa 0.3.18 → 0.3.19

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.18
1
+ 0.3.19
@@ -76,6 +76,23 @@ module RDF::RDFa
76
76
  graph
77
77
  end
78
78
 
79
+ ##
80
+ # Perform reference folding on the resulting default graph.
81
+ #
82
+ # For all objects of type rdfa:Prototype that are the target of an rdfa:ref property, load the IRI into a repository.
83
+ #
84
+ # Subsequently, remove reference rdfa:Prototype objects.
85
+ #
86
+ # @return [RDF::Graph]
87
+ # @see [HTML+RDFa](http://www.w3.org/TR/rdfa-in-html/#rdfa-reference-folding)
88
+ def fold_references
89
+ graph = RDF::Graph.new << self
90
+
91
+ add_debug("fold") {"Loaded #{graph.size} triples into default graph"}
92
+
93
+ fold(graph)
94
+ end
95
+
79
96
  def rule(name, &block)
80
97
  Rule.new(name, block)
81
98
  end
@@ -192,6 +209,9 @@ module RDF::RDFa
192
209
  antecedent :x, RDF.type, :c2
193
210
  consequent :x, RDF.type, :c1
194
211
  end,
212
+ ]
213
+
214
+ FOLDING_RULES = [
195
215
  Rule.new("rdfa-ref") do
196
216
  antecedent :x, RDF::RDFA.ref, :PR
197
217
  antecedent :PR, RDF.type, RDF::RDFA.Prototype
@@ -210,6 +230,7 @@ module RDF::RDFa
210
230
  consequent :PR, :p, :y
211
231
  end,
212
232
  ]
233
+
213
234
  ##
214
235
  # Perform OWL entailment rules on repository
215
236
  # @param [RDF::Repository] repo
@@ -233,18 +254,37 @@ module RDF::RDFa
233
254
  repo.insert(*to_add)
234
255
  end
235
256
 
257
+ add_debug("entailment", "final count: #{count}")
258
+ repo
259
+ end
260
+
261
+ ##
262
+ # Perform RDFa folding rules on repository
263
+ # @param [RDF::Graph] graph
264
+ # @return [RDF::Graph]
265
+ def fold(graph)
266
+ to_add = []
267
+
268
+ FOLDING_RULES.each do |rule|
269
+ rule.execute(graph) do |statement|
270
+ add_debug("fold(#{rule.name})") {statement.inspect}
271
+ to_add << statement
272
+ end
273
+ end
274
+
275
+ graph.insert(*to_add)
276
+
236
277
  # Remove statements matched by removal rules
237
278
  to_remove = []
238
279
  REMOVAL_RULES.each do |rule|
239
- rule.execute(repo) do |statement|
280
+ rule.execute(graph) do |statement|
240
281
  add_debug("removal(#{rule.name})") {statement.inspect}
241
282
  to_remove << statement
242
283
  end
243
284
  end
244
- repo.delete(*to_remove)
285
+ graph.delete(*to_remove)
245
286
 
246
- add_debug("entailment", "final count: #{count}")
247
- repo
287
+ graph
248
288
  end
249
289
  end
250
290
  end
@@ -249,6 +249,8 @@ module RDF::RDFa
249
249
  # One of :nokogiri or :rexml. If nil/unspecified uses :nokogiri if available, :rexml otherwise.
250
250
  # @option options [Boolean] :vocab_expansion (false)
251
251
  # whether to perform OWL2 expansion on the resulting graph
252
+ # @option options [Boolean] :reference_folding (true)
253
+ # whether to perform RDFa reference folding on the resulting graph
252
254
  # @option options [:xml, :xhtml1, :xhtml5, :html4, :html5, :svg] :host_language (:html5)
253
255
  # Host Language
254
256
  # @option options [:"rdfa1.0", :"rdfa1.1"] :version (:"rdfa1.1")
@@ -270,6 +272,7 @@ module RDF::RDFa
270
272
  def initialize(input = $stdin, options = {}, &block)
271
273
  super do
272
274
  @debug = options[:debug]
275
+ @options = {:reference_folding => true}.merge(@options)
273
276
 
274
277
  @options[:rdfagraph] = case @options[:rdfagraph]
275
278
  when String, Symbol then @options[:rdfagraph].to_s.split(',').map(&:strip).map(&:to_sym)
@@ -348,9 +351,15 @@ module RDF::RDFa
348
351
  def each_statement(&block)
349
352
 
350
353
  if @options[:vocab_expansion]
354
+ # Process vocabulary expansion after normal processing
351
355
  @options[:vocab_expansion] = false
352
356
  expand.each_statement(&block)
353
357
  @options[:vocab_expansion] = true
358
+ elsif @options[:reference_folding]
359
+ # Process reference folding after normal processing
360
+ @options[:reference_folding] = false
361
+ fold_references.each_statement(&block)
362
+ @options[:reference_folding] = true
354
363
  else
355
364
  @callback = block
356
365
 
@@ -512,8 +521,10 @@ module RDF::RDFa
512
521
  def add_triple(node, subject, predicate, object, context = nil)
513
522
  statement = RDF::Statement.new(subject, predicate, object)
514
523
  add_error(node, "statement #{RDF::NTriples.serialize(statement)} is invalid") unless statement.valid?
515
- add_info(node, "statement: #{RDF::NTriples.serialize(statement)}")
516
- @callback.call(statement) if @options[:rdfagraph].include?(:output)
524
+ if subject && predicate && object # Basic sanity checking
525
+ add_info(node, "statement: #{RDF::NTriples.serialize(statement)}")
526
+ @callback.call(statement) if @options[:rdfagraph].include?(:output)
527
+ end
517
528
  end
518
529
 
519
530
  # Parsing an RDFa document (this is *not* the recursive method)
@@ -752,7 +763,22 @@ module RDF::RDFa
752
763
  language = element.language || language
753
764
  language = nil if language.to_s.empty?
754
765
  add_debug(element) {"HTML5 [3.2.3.3] lang: #{language.inspect}"} if language
755
-
766
+
767
+ # From HTML5, if the property attribute and the rel and/or rev attribute exists on the same element, the non-CURIE and non-URI rel and rev values are ignored. If, after this, the value of rel and/or rev becomes empty, then the processor must act as if the respective attribute is not present.
768
+ if [:html5, :xhtml5].include?(@host_language) && attrs[:property] && (attrs[:rel] || attrs[:rev])
769
+ old_rel, old_rev = attrs[:rel], attrs[:rev]
770
+ if old_rel
771
+ attrs[:rel] = (attrs[:rel]).split(/\s+/m).select {|r| !r.index(':').nil?}.join(" ")
772
+ attrs.delete(:rel) if attrs[:rel].empty?
773
+ add_debug(element) {"HTML5: @rel was #{old_rel}, now #{attrs[:rel]}"}
774
+ end
775
+ if old_rev
776
+ attrs[:rev] = (attrs[:rev]).split(/\s+/m).select {|r| !r.index(':').nil?}.join(" ")
777
+ attrs.delete(:rev) if attrs[:rev].empty?
778
+ add_debug(element) {"HTML5: @rev was #{old_rev}, now #{attrs[:rev]}"}
779
+ end
780
+ end
781
+
756
782
  # rels and revs
757
783
  rels = process_uris(element, attrs[:rel], evaluation_context, base,
758
784
  :uri_mappings => uri_mappings,
@@ -806,7 +832,7 @@ module RDF::RDFa
806
832
 
807
833
  # if the @typeof attribute is present, set typed resource to new subject
808
834
  typed_resource = new_subject if attrs[:typeof]
809
- else
835
+ else # rdfa1.1
810
836
  # If the current element contains no @rel or @rev attribute, then the next step is to establish a value for new subject.
811
837
  # This step has two possible alternatives.
812
838
  # 1. If the current element contains the @property attribute, but does not contain the @content or the @datatype attributes, then
@@ -875,7 +901,7 @@ module RDF::RDFa
875
901
  # if no URI is provided, then first check to see if the element is the head or body element.
876
902
  # If it is, then act as if the new subject is set to the parent object.
877
903
  evaluation_context.parent_object
878
- elsif element == root && base
904
+ elsif element == root
879
905
  # if the element is the root element of the document, then act as if there is an empty @about present,
880
906
  # and process it according to the rule for @about, above;
881
907
  uri(base)
@@ -888,8 +914,8 @@ module RDF::RDFa
888
914
  evaluation_context.parent_object
889
915
  end
890
916
 
891
- # if @typeof is present, set the typed resource to the value of new subject</code>
892
- typed_resource ||= new_subject if attrs[:typeof]
917
+ # If @typeof is present then typed resource is set to the resource obtained from the first match from the following rules:
918
+ typed_resource = new_subject if attrs[:typeof]
893
919
  end
894
920
  end
895
921
 
@@ -1315,7 +1341,7 @@ module RDF::RDFa
1315
1341
  if uri
1316
1342
  add_debug(element) {"process_uri: #{value} => safeCURIE => <#{uri}>"}
1317
1343
  else
1318
- add_warning(element, "#{value} not matched as a safeCURIE")
1344
+ add_warning(element, "#{value} not matched as a safeCURIE", RDF::RDFA.UnresolvedCURIE)
1319
1345
  end
1320
1346
  uri
1321
1347
  elsif options[:term_mappings] && TERM_REGEXP.match(value.to_s) && restrictions.include?(:term)
@@ -1378,7 +1404,7 @@ module RDF::RDFa
1378
1404
  end
1379
1405
 
1380
1406
  # Finally, if there is no local default vocabulary, the term has no associated URI and must be ignored.
1381
- add_warning(element, "Term #{value} is not defined")
1407
+ add_warning(element, "Term #{value} is not defined", RDF::RDFA.UnresolvedTerm)
1382
1408
  nil
1383
1409
  end
1384
1410
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18
4
+ version: 0.3.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-07 00:00:00.000000000 Z
13
+ date: 2012-12-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
@@ -125,13 +125,13 @@ dependencies:
125
125
  - !ruby/object:Gem::Version
126
126
  version: 0.0.5
127
127
  - !ruby/object:Gem::Dependency
128
- name: spira
128
+ name: json-ld
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
132
132
  - - ! '>='
133
133
  - !ruby/object:Gem::Version
134
- version: 0.0.12
134
+ version: 0.3.2
135
135
  type: :development
136
136
  prerelease: false
137
137
  version_requirements: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ dependencies:
139
139
  requirements:
140
140
  - - ! '>='
141
141
  - !ruby/object:Gem::Version
142
- version: 0.0.12
142
+ version: 0.3.2
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rspec
145
145
  requirement: !ruby/object:Gem::Requirement