rdf-rdfxml 0.3.2 → 0.3.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 0.3.2.1
2
+ * Fix collection serialization bug
3
+ * Assert :xml as a format type (by creating RDF::RDFXML::XML as a sub-class of Format that uses RDFXML::Reader/Writer)
4
+
1
5
  === 0.3.2
2
6
  * Refactor rdfcore tests using Spira and open-uri-cached.
3
7
  * Improve detection and reporting of attempts to write illegal values.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.2.1
@@ -27,4 +27,17 @@ module RDF::RDFXML
27
27
  reader { RDF::RDFXML::Reader }
28
28
  writer { RDF::RDFXML::Writer }
29
29
  end
30
+
31
+ # Aliases for this format
32
+ #
33
+ # This allows the following:
34
+ #
35
+ # @example Obtaining an RDFXML format class
36
+ # RDF::Format.for(:xml) # RDF::RDFXML::XML::Format
37
+ # RDF::Format.for(:xml).reader # RDF::RDFXML::Reader
38
+ # RDF::Format.for(:xml).writer # RDF::RDFXML::Writer
39
+ class XML < RDF::Format
40
+ reader { RDF::RDFXML::Reader }
41
+ writer { RDF::RDFXML::Writer }
42
+ end
30
43
  end
@@ -308,7 +308,7 @@ module RDF::RDFXML
308
308
 
309
309
  rdf_type, *rest = properties.fetch(RDF.type.to_s, [])
310
310
  qname = get_qname_string(rdf_type, :with_default => true)
311
- add_debug "subject: #{subject.inspect}, qname: #{qname.inspect}"
311
+ add_debug "=> qname: #{qname.inspect}"
312
312
  if rdf_type.is_a?(RDF::Node)
313
313
  # Must serialize with an element
314
314
  rdf_type = nil
@@ -318,6 +318,8 @@ module RDF::RDFXML
318
318
  properties[RDF.type.to_s] = [rest].flatten.compact
319
319
  end
320
320
  prop_list = order_properties(properties)
321
+ add_debug "=> property order: #{prop_list.to_sentence}"
322
+
321
323
 
322
324
  if qname
323
325
  rdf_type = nil
@@ -332,7 +334,11 @@ module RDF::RDFXML
332
334
 
333
335
  if subject.is_a?(RDF::Node)
334
336
  # Only need nodeID if it's referenced elsewhere
335
- node["rdf:nodeID"] = subject.id if ref_count(subject) > (@depth == 0 ? 0 : 1)
337
+ if ref_count(subject) > (@depth == 0 ? 0 : 1)
338
+ node["rdf:nodeID"] = subject.id
339
+ else
340
+ node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{subject}")) if RDF::RDFXML::debug?
341
+ end
336
342
  else
337
343
  node["rdf:about"] = relativize(subject)
338
344
  end
@@ -351,7 +357,11 @@ module RDF::RDFXML
351
357
  elsif @force_RDF_about.include?(subject)
352
358
  add_debug "subject: #{subject.inspect}, force about"
353
359
  node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
354
- node["rdf:about"] = relativize(subject)
360
+ if subject.is_a?(RDF::Node)
361
+ node["rdf:nodeID"] = subject.id
362
+ else
363
+ node["rdf:about"] = relativize(subject)
364
+ end
355
365
  end
356
366
  @force_RDF_about.delete(subject)
357
367
 
@@ -371,22 +381,26 @@ module RDF::RDFXML
371
381
  #qname = "rdf:li" if qname.match(/rdf:_\d+/)
372
382
  pred_node = Nokogiri::XML::Element.new(qname, node.document)
373
383
 
374
- col = RDF::List.new(object, @graph).to_a
375
- conformant_list = col.all? {|item| !item.literal?}
376
384
  o_props = @graph.properties(object)
385
+
386
+ col = RDF::List.new(object, @graph).to_a
387
+ conformant_list = col.all? {|item| !item.literal?} && o_props[RDF.first.to_s]
377
388
  args = xml_args(object)
378
389
  attrs = args.pop
379
390
 
380
391
  # Check to see if it can be serialized as a collection
381
- if conformant_list && o_props[RDF.first.to_s]
382
- add_debug("predicate as collection")
392
+ if conformant_list
393
+ add_debug("=> as collection: [#{col.map(&:to_s).join(", ")}]")
383
394
  # Serialize list as parseType="Collection"
395
+ pred_node.add_child(Nokogiri::XML::Comment.new(node.document, "Serialization for #{object}")) if RDF::RDFXML::debug?
384
396
  pred_node["rdf:parseType"] = "Collection"
385
- col.each do |item|
386
- # Mark the BNode subject of each item as being complete, so that it is not serialized elsewhere
387
- @graph.query(:predicate => RDF.first, :object => item) do |statement|
388
- subject_done(statement.subject)
389
- end
397
+ while o_props[RDF.first.to_s]
398
+ # Object is used only for referencing collection item and next
399
+ subject_done(object)
400
+ item = o_props[RDF.first.to_s].first
401
+ object = o_props[RDF.rest.to_s].first
402
+ o_props = @graph.properties(object)
403
+ add_debug("=> li first: #{item}, rest: #{object}")
390
404
  @force_RDF_about[item] = true
391
405
  subject(item, pred_node)
392
406
  end
@@ -395,31 +409,31 @@ module RDF::RDFXML
395
409
  pred_node.unlink
396
410
  pred_node = nil
397
411
  node[qname] = object.is_a?(RDF::URI) ? relativize(object) : object.value
398
- add_debug("predicate as attribute: node[#{qname}]=#{node[qname]}, #{object.class}")
412
+ add_debug("=> as attribute: node[#{qname}]=#{node[qname]}, #{object.class}")
399
413
  elsif object.literal?
400
414
  # Serialize as element
401
415
  add_debug("predicate as element: #{attrs.inspect}")
402
416
  attrs.each_pair do |a, av|
403
417
  next if a.to_s == "xml:lang" && av.to_s == @lang # Lang already specified, don't repeat
404
- add_debug " elt attr #{a}=#{av}"
418
+ add_debug "=> elt attr #{a}=#{av}"
405
419
  pred_node[a] = av.to_s
406
420
  end
407
- add_debug " elt #{'xmllit ' if object.literal? && object.datatype == RDF.XMLLiteral}content=#{args.first}" if !args.empty?
421
+ add_debug "=> elt #{'xmllit ' if object.literal? && object.datatype == RDF.XMLLiteral}content=#{args.first}" if !args.empty?
408
422
  if object.datatype == RDF.XMLLiteral
409
423
  pred_node.inner_html = args.first.to_s
410
424
  elsif args.first
411
425
  pred_node.content = args.first
412
426
  end
413
427
  elsif @depth < @max_depth && !is_done?(object) && @subjects.include?(object)
414
- add_debug("predicate as element (recurse)")
428
+ add_debug(" as element (recurse)")
415
429
  @depth += 1
416
430
  subject(object, pred_node)
417
431
  @depth -= 1
418
432
  elsif object.is_a?(RDF::Node)
419
- add_debug("predicate as element (nodeID)")
433
+ add_debug("=> as element (nodeID)")
420
434
  pred_node["rdf:nodeID"] = object.id
421
435
  else
422
- add_debug("predicate as element (resource)")
436
+ add_debug("=> as element (resource)")
423
437
  pred_node["rdf:resource"] = relativize(object)
424
438
  end
425
439
 
@@ -428,7 +442,7 @@ module RDF::RDFXML
428
442
 
429
443
  # Mark a subject as done.
430
444
  def subject_done(subject)
431
- #add_debug("subject_done: #{subject}")
445
+ add_debug("subject_done: #{subject}")
432
446
  @serialized[subject] = true
433
447
  end
434
448
 
@@ -481,7 +495,6 @@ module RDF::RDFXML
481
495
  prop_list << prop.to_s
482
496
  end
483
497
 
484
- add_debug "order_properties: #{prop_list.to_sentence}"
485
498
  prop_list
486
499
  end
487
500
 
@@ -512,7 +525,7 @@ module RDF::RDFXML
512
525
  #
513
526
  # @param [String] message::
514
527
  def add_debug(message)
515
- STDERR.puts message if ::RDF::RDFXML.debug?
528
+ STDERR.puts (" " * @depth) + message if ::RDF::RDFXML.debug?
516
529
  @debug << message if @debug.is_a?(Array)
517
530
  end
518
531
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdf-rdfxml}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gregg Kellogg"]
12
- s.date = %q{2011-02-13}
12
+ s.date = %q{2011-02-18}
13
13
  s.description = %q{RDF::RDFXML is an RDF/XML reader and writer for Ruby using the RDF.rb library suite.}
14
14
  s.email = %q{gregg@kellogg-assoc.com}
15
15
  s.extra_rdoc_files = [
@@ -19,5 +19,10 @@ describe RDF::RDFXML::Format do
19
19
  format.should == RDF::RDFXML::Format
20
20
  end
21
21
  end
22
+
23
+ it "should discover 'xml'" do
24
+ RDF::Format.for(:xml).reader.should == RDF::RDFXML::Reader
25
+ RDF::Format.for(:xml).writer.should == RDF::RDFXML::Writer
26
+ end
22
27
  end
23
28
  end
@@ -361,6 +361,15 @@ describe "RDF::RDFXML::Writer" do
361
361
  "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
362
362
  )
363
363
  end
364
+
365
+ it "should use rdf::nodeID for forced BNode generation" do
366
+ @graph = parse(%(
367
+ @prefix : <http://example/> .
368
+ _:bar :list (_:foo (_:foo)).
369
+ ))
370
+
371
+ graph_check = parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
372
+ end
364
373
 
365
374
  it "should replicate rdfcore/rdfms-seq-representation" do
366
375
  @graph = parse(%(
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rdf-rdfxml
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.3.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gregg Kellogg
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-13 00:00:00 -08:00
13
+ date: 2011-02-18 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency