rdf-rdfa 0.3.19 → 0.3.19.1

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.19
1
+ 0.3.19.1
@@ -34,21 +34,18 @@ module RDF::RDFa
34
34
  # scm-sco
35
35
  # {c1 rdfs:subClassOf c2 . c2 rdfs:subClassOf c3} => {c1 rdfs:subClassOf c3}
36
36
  #
37
- # @return [RDF::Graph]
37
+ # @param [RDF::Repository] repository
38
38
  # @see [OWL2 PROFILES](http://www.w3.org/TR/2009/REC-owl2-profiles-20091027/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules)
39
- def expand
40
- repo = RDF::Repository.new
41
- repo << self # Add default graph
42
-
43
- count = repo.count
44
- add_debug("expand") {"Loaded #{repo.size} triples into default graph"}
39
+ def expand(repository)
40
+ count = repository.count
41
+ add_debug("expand") {"Repository has #{repository.size} statements"}
45
42
 
46
43
  # Vocabularies managed in vocab_repo, and copied to repo for processing.
47
44
  # This allows for persistent storage of vocabularies
48
45
  @@vocab_repo = @options[:vocab_repository] if @options.has_key?(:vocab_repository)
49
46
  @@vocab_repo ||= RDF::Repository.new.insert(*COOKED_VOCAB_STATEMENTS)
50
47
 
51
- vocabs = repo.query(:predicate => RDF::RDFA.usesVocabulary).to_a.map(&:object)
48
+ vocabs = repository.query(:predicate => RDF::RDFA.usesVocabulary).to_a.map(&:object)
52
49
  vocabs.each do |vocab|
53
50
  begin
54
51
  unless @@vocab_repo.has_context?(vocab)
@@ -63,17 +60,11 @@ module RDF::RDFa
63
60
 
64
61
  @@vocab_repo.each do |statement|
65
62
  if vocabs.include?(statement.context)
66
- repo << statement
63
+ repository << statement
67
64
  end
68
65
  end
69
66
 
70
- repo = entailment(repo)
71
-
72
- # Return graph with default context
73
- graph = RDF::Graph.new
74
- repo.statements.each {|st| graph << st if st.context.nil?}
75
-
76
- graph
67
+ entailment(repository)
77
68
  end
78
69
 
79
70
  ##
@@ -83,14 +74,11 @@ module RDF::RDFa
83
74
  #
84
75
  # Subsequently, remove reference rdfa:Prototype objects.
85
76
  #
86
- # @return [RDF::Graph]
77
+ # @param [RDF::Repository] repository
87
78
  # @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)
79
+ def fold_references(repository)
80
+ add_debug("expand") {"Repository has #{repository.size} statements"}
81
+ fold(repository)
94
82
  end
95
83
 
96
84
  def rule(name, &block)
@@ -233,58 +221,63 @@ module RDF::RDFa
233
221
 
234
222
  ##
235
223
  # Perform OWL entailment rules on repository
236
- # @param [RDF::Repository] repo
224
+ # @param [RDF::Repository] repository
237
225
  # @return [RDF::Repository]
238
- def entailment(repo)
226
+ def entailment(repository)
239
227
  old_count = 0
240
228
 
241
- # Continue as long as new statements are added to repo
242
- while old_count < (count = repo.count)
243
- add_debug("entailment", "old: #{old_count} count: #{count}")
229
+ # Continue as long as new statements are added to repository
230
+ while old_count < (count = repository.count)
231
+ #add_debug("entailment") {"old: #{old_count} count: #{count}"}
244
232
  old_count = count
245
233
  to_add = []
246
234
 
247
235
  RULES.each do |rule|
248
- rule.execute(repo) do |statement|
249
- add_debug("entailment(#{rule.name})") {statement.inspect}
236
+ rule.execute(repository) do |statement|
237
+ #add_debug("entailment(#{rule.name})") {statement.inspect}
250
238
  to_add << statement
251
239
  end
252
240
  end
253
241
 
254
- repo.insert(*to_add)
242
+ repository.insert(*to_add)
255
243
  end
256
244
 
257
245
  add_debug("entailment", "final count: #{count}")
258
- repo
259
246
  end
260
247
 
261
248
  ##
262
249
  # Perform RDFa folding rules on repository
263
- # @param [RDF::Graph] graph
264
- # @return [RDF::Graph]
265
- def fold(graph)
266
- to_add = []
250
+ # @param [RDF::Repository] repository
251
+ def fold(repository)
252
+ old_count = 0
267
253
 
268
- FOLDING_RULES.each do |rule|
269
- rule.execute(graph) do |statement|
270
- add_debug("fold(#{rule.name})") {statement.inspect}
271
- to_add << statement
254
+ # Continue as long as new statements are added to repository
255
+ while old_count < (count = repository.count)
256
+ #add_debug("fold") {"old: #{old_count} count: #{count}"}
257
+ old_count = count
258
+ to_add = []
259
+
260
+ FOLDING_RULES.each do |rule|
261
+ rule.execute(repository) do |statement|
262
+ #add_debug("fold(#{rule.name})") {statement.inspect}
263
+ to_add << statement
264
+ end
272
265
  end
273
- end
274
266
 
275
- graph.insert(*to_add)
267
+ repository.insert(*to_add)
268
+ end
276
269
 
277
270
  # Remove statements matched by removal rules
278
271
  to_remove = []
279
272
  REMOVAL_RULES.each do |rule|
280
- rule.execute(graph) do |statement|
281
- add_debug("removal(#{rule.name})") {statement.inspect}
273
+ rule.execute(repository) do |statement|
274
+ #add_debug("removal(#{rule.name})") {statement.inspect}
282
275
  to_remove << statement
283
276
  end
284
277
  end
285
- graph.delete(*to_remove)
278
+ repository.delete(*to_remove)
286
279
 
287
- graph
280
+ add_debug("fold", "final count: #{count}")
288
281
  end
289
282
  end
290
283
  end
@@ -89,6 +89,17 @@ module RDF::RDFa
89
89
  # @return [:"rdfa1.0", :"rdfa1.1"]
90
90
  attr_reader :version
91
91
 
92
+ # Repository used for collecting triples.
93
+ # @!attribute [r] repository
94
+ # @return [RDF::Repository]
95
+ attr_reader :repository
96
+
97
+ # Returns the XML implementation module for this reader instance.
98
+ #
99
+ # @!attribute [rw] implementation
100
+ # @return [Module]
101
+ attr_reader :implementation
102
+
92
103
  # The Recursive Baggage
93
104
  # @private
94
105
  class EvaluationContext # :nodoc:
@@ -232,12 +243,6 @@ module RDF::RDFa
232
243
  end
233
244
  end
234
245
 
235
- # Returns the XML implementation module for this reader instance.
236
- #
237
- # @!attribute [rw] implementation
238
- # @return [Module]
239
- attr_reader :implementation
240
-
241
246
  ##
242
247
  # Initializes the RDFa reader instance.
243
248
  #
@@ -273,7 +278,8 @@ module RDF::RDFa
273
278
  super do
274
279
  @debug = options[:debug]
275
280
  @options = {:reference_folding => true}.merge(@options)
276
-
281
+ @repository = RDF::Repository.new
282
+
277
283
  @options[:rdfagraph] = case @options[:rdfagraph]
278
284
  when String, Symbol then @options[:rdfagraph].to_s.split(',').map(&:strip).map(&:to_sym)
279
285
  when Array then @options[:rdfagraph].map {|o| o.to_s.to_sym}
@@ -349,30 +355,13 @@ module RDF::RDFa
349
355
  # @yieldparam [RDF::Statement] statement
350
356
  # @return [void]
351
357
  def each_statement(&block)
352
-
353
- if @options[:vocab_expansion]
354
- # Process vocabulary expansion after normal processing
355
- @options[:vocab_expansion] = false
356
- expand.each_statement(&block)
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
363
- else
364
- @callback = block
365
-
366
- # Process any saved callbacks (processor graph issues)
367
- @saved_callbacks.each {|s| @callback.call(s) } if @saved_callbacks
368
-
358
+ unless @processed || @root.nil?
369
359
  # Add prefix definitions from host defaults
370
360
  @host_defaults[:uri_mappings].each_pair do |prefix, value|
371
361
  prefix(prefix, value)
372
362
  end
373
363
 
374
364
  # parse
375
- return unless @root
376
365
  parse_whole_document(@doc, RDF::URI(base_uri))
377
366
 
378
367
  def extract_script(el, input, type, options, &block)
@@ -396,7 +385,7 @@ module RDF::RDFa
396
385
  # Look for Embedded Turtle and RDF/XML
397
386
  unless @root.xpath("//rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
398
387
  extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
399
- block.call(statement)
388
+ @repository << statement
400
389
  end
401
390
  end
402
391
 
@@ -405,7 +394,7 @@ module RDF::RDFa
405
394
  type = el.attribute("type")
406
395
 
407
396
  extract_script(el, el.inner_text, type, @options) do |statement|
408
- block.call(statement)
397
+ @repository << statement
409
398
  end
410
399
  end
411
400
 
@@ -414,11 +403,31 @@ module RDF::RDFa
414
403
  begin
415
404
  require 'rdf/microdata'
416
405
  add_debug(@doc, "process microdata")
417
- RDF::Microdata::Reader.new(@doc, options).each(&block)
406
+ @repository << RDF::Microdata::Reader.new(@doc, options)
418
407
  rescue
419
408
  add_debug(@doc, "microdata detected, not processed")
420
409
  end
421
410
  end
411
+
412
+ # Perform reference folding
413
+ fold_references(@repository) if @options[:reference_folding]
414
+
415
+ # Perform vocabulary expansion
416
+ expand(@repository) if @options[:vocab_expansion]
417
+
418
+ @processed = true
419
+ end
420
+
421
+ # Return statements in the default graph for
422
+ # statements in the associated named or default graph from the
423
+ # processed repository
424
+ @repository.each do |statement|
425
+ case statement.context
426
+ when nil
427
+ yield statement if @options[:rdfagraph].include?(:output)
428
+ when RDF::RDFA.ProcessorGraph
429
+ yield RDF::Statement.new(*statement.to_triple) if @options[:rdfagraph].include?(:processor)
430
+ end
422
431
  end
423
432
  end
424
433
 
@@ -477,33 +486,25 @@ module RDF::RDFa
477
486
  puts "#{node_path(node)}: #{message}" if ::RDF::RDFa.debug?
478
487
  @debug << "#{node_path(node)}: #{message}" if @debug.is_a?(Array)
479
488
  if @options[:processor_callback] || @options[:rdfagraph].include?(:processor)
480
- g = RDF::Graph.new
481
489
  n = RDF::Node.new
482
- g << RDF::Statement.new(n, RDF["type"], process_class)
483
- g << RDF::Statement.new(n, RDF::DC.description, message)
484
- g << RDF::Statement.new(n, RDF::DC.date, RDF::Literal::Date.new(DateTime.now))
485
- g << RDF::Statement.new(n, RDF::RDFA.context, base_uri) if base_uri
490
+ processor_statements = [
491
+ RDF::Statement.new(n, RDF["type"], process_class, :context => RDF::RDFA.ProcessorGraph),
492
+ RDF::Statement.new(n, RDF::DC.description, message, :context => RDF::RDFA.ProcessorGraph),
493
+ RDF::Statement.new(n, RDF::DC.date, RDF::Literal::Date.new(DateTime.now), :context => RDF::RDFA.ProcessorGraph)
494
+ ]
495
+ processor_statements << RDF::Statement.new(n, RDF::RDFA.context, base_uri, :context => RDF::RDFA.ProcessorGraph) if base_uri
486
496
  if node.respond_to?(:path)
487
497
  nc = RDF::Node.new
488
- g << RDF::Statement.new(n, RDF::RDFA.context, nc)
489
- g << RDF::Statement.new(nc, RDF["type"], RDF::PTR.XPathPointer)
490
- g << RDF::Statement.new(nc, RDF::PTR.expression, node.path)
498
+ processor_statements += [
499
+ RDF::Statement.new(n, RDF::RDFA.context, nc, :context => RDF::RDFA.ProcessorGraph),
500
+ RDF::Statement.new(nc, RDF["type"], RDF::PTR.XPathPointer, :context => RDF::RDFA.ProcessorGraph),
501
+ RDF::Statement.new(nc, RDF::PTR.expression, node.path, :context => RDF::RDFA.ProcessorGraph)
502
+ ]
491
503
  end
492
504
 
493
- g.each do |s|
494
- # Provide as callback
495
- @options[:processor_callback].call(s) if @options[:processor_callback]
496
-
497
- # Yield as result
498
- if @options[:rdfagraph].include?(:processor)
499
- if @callback
500
- @callback.call(s)
501
- else
502
- # Save messages for later callback
503
- @saved_callbacks ||= []
504
- @saved_callbacks << s
505
- end
506
- end
505
+ @repository.insert(*processor_statements)
506
+ if cb = @options[:processor_callback]
507
+ processor_statements.each {|s| cb.call(s)}
507
508
  end
508
509
  end
509
510
  end
@@ -523,7 +524,7 @@ module RDF::RDFa
523
524
  add_error(node, "statement #{RDF::NTriples.serialize(statement)} is invalid") unless statement.valid?
524
525
  if subject && predicate && object # Basic sanity checking
525
526
  add_info(node, "statement: #{RDF::NTriples.serialize(statement)}")
526
- @callback.call(statement) if @options[:rdfagraph].include?(:output)
527
+ repository << statement
527
528
  end
528
529
  end
529
530
 
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.19
4
+ version: 0.3.19.1
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-29 00:00:00.000000000 Z
13
+ date: 2012-12-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf