rdf-n3 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/matchers.rb CHANGED
@@ -1,17 +1,40 @@
1
+ require 'rdf/isomorphic'
2
+
1
3
  module Matchers
2
4
  class BeEquivalentGraph
3
5
  Info = Struct.new(:about, :information, :trace, :compare, :inputDocument, :outputDocument)
4
6
  def normalize(graph)
5
- case graph
6
- when RDF::Graph then graph
7
- when IO, StringIO
8
- RDF::Graph.new.load(graph, :base_uri => @info.about)
7
+ case @info.compare
8
+ when :array
9
+ array = case graph
10
+ when RDF::Graph
11
+ raise ":compare => :array used with Graph"
12
+ when Array
13
+ graph.sort
14
+ else
15
+ graph.to_s.split("\n").
16
+ map {|t| t.gsub(/^\s*(.*)\s*$/, '\1')}.
17
+ reject {|t2| t2.match(/^\s*$/)}.
18
+ compact.
19
+ sort.
20
+ uniq
21
+ end
22
+
23
+ # Implement to_ntriples on array, to simplify logic later
24
+ def array.to_ntriples; self.join("\n") + "\n"; end
25
+ array
9
26
  else
10
- # Figure out which parser to use
11
- g = RDF::Graph.new
12
- reader_class = RDF::Reader.for(detect_format(graph))
13
- reader_class.new(graph, :base_uri => @info.about).each {|s| g << s}
14
- g
27
+ case graph
28
+ when RDF::Graph then graph
29
+ when IO, StringIO
30
+ RDF::Graph.new.load(graph, :base_uri => @info.about)
31
+ else
32
+ # Figure out which parser to use
33
+ g = RDF::Graph.new
34
+ reader_class = RDF::Reader.for(detect_format(graph))
35
+ reader_class.new(graph, :base_uri => @info.about).each {|s| g << s}
36
+ g
37
+ end
15
38
  end
16
39
  end
17
40
 
@@ -31,7 +54,11 @@ module Matchers
31
54
 
32
55
  def matches?(actual)
33
56
  @actual = normalize(actual)
34
- @actual == @expected
57
+ if @info.compare == :array
58
+ @actual == @expected
59
+ else
60
+ @actual.isomorphic_with?(@expected)
61
+ end
35
62
  end
36
63
 
37
64
  def failure_message_for_should
@@ -48,6 +75,8 @@ module Matchers
48
75
  (@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") +
49
76
  "Unsorted Expected:\n#{@expected.to_ntriples}" +
50
77
  "Unsorted Results:\n#{@actual.to_ntriples}" +
78
+ # "Unsorted Expected Dump:\n#{@expected.dump}\n" +
79
+ # "Unsorted Results Dump:\n#{@actual.dump}" +
51
80
  (@info.trace ? "\nDebug:\n#{@info.trace}" : "")
52
81
  end
53
82
  def negative_failure_message
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ $:.unshift "."
2
3
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
4
 
4
5
  describe "RDF::N3::Reader" do
@@ -148,7 +149,6 @@ describe "RDF::N3::Reader" do
148
149
  statement = parse(n3).statements.first
149
150
  statement.object.value.should == "\u{15678}another"
150
151
  else
151
- lambda { parse(n3) }.should raise_error(RDF::ReaderError, "Long Unicode escapes no supported in Ruby 1.8")
152
152
  pending("Not supported in Ruby 1.8")
153
153
  end
154
154
  end
@@ -267,17 +267,17 @@ describe "RDF::N3::Reader" do
267
267
  %(<#D%C3%BCrst> a "URI percent ^encoded as C3, BC".) => %(<http://a/b#D%C3%BCrst> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "URI percent ^encoded as C3, BC" .),
268
268
  }.each_pair do |n3, nt|
269
269
  it "for '#{n3}'" do
270
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
270
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
271
271
  end
272
272
  end
273
273
 
274
274
  {
275
275
  %(<#Dürst> a "URI straight in UTF8".) => %(<http://a/b#D\\u00FCrst> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "URI straight in UTF8" .),
276
- %(:a :related :\u3072\u3089\u304C\u306A.) => %(<http://a/b#a> <http://a/b#related> <http://a/b#\\u3072\\u3089\\u304C\\u306A> .),
276
+ #%(:a :related :ひらがな .) => %(<http://a/b#a> <http://a/b#related> <http://a/b#\\u3072\\u3089\\u304C\\u306A> .),
277
277
  }.each_pair do |n3, nt|
278
278
  it "for '#{n3}'" do
279
279
  begin
280
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
280
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
281
281
  rescue
282
282
  if defined?(::Encoding)
283
283
  raise
@@ -289,7 +289,7 @@ describe "RDF::N3::Reader" do
289
289
  end
290
290
  end
291
291
 
292
- it "should create URIRefs" do
292
+ it "should create URIs" do
293
293
  n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> ."
294
294
  statement = parse(n3doc).statements.first
295
295
  statement.subject.class.should == RDF::URI
@@ -338,9 +338,9 @@ describe "RDF::N3::Reader" do
338
338
  it "should use <> as a prefix and as a triple node" do
339
339
  n3 = %(@prefix : <> . <> a :a.)
340
340
  nt = %(
341
- <http://a/b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
341
+ <http://a/b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/ba> .
342
342
  )
343
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
343
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
344
344
  end
345
345
 
346
346
  it "should use <#> as a prefix and as a triple node" do
@@ -348,31 +348,31 @@ describe "RDF::N3::Reader" do
348
348
  nt = %(
349
349
  <http://a/b#> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
350
350
  )
351
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
351
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
352
352
  end
353
353
 
354
354
  it "should generate rdf:type for 'a'" do
355
355
  n3 = %(@prefix a: <http://foo/a#> . a:b a <http://www.w3.org/2000/01/rdf-schema#resource> .)
356
356
  nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
357
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
357
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
358
358
  end
359
359
 
360
360
  it "should generate rdf:type for '@a'" do
361
361
  n3 = %(@prefix a: <http://foo/a#> . a:b @a <http://www.w3.org/2000/01/rdf-schema#resource> .)
362
362
  nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
363
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
363
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
364
364
  end
365
365
 
366
366
  it "should generate inverse predicate for 'is xxx of'" do
367
367
  n3 = %("value" is :prop of :b . :b :prop "value" .)
368
368
  nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
369
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
369
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
370
370
  end
371
371
 
372
372
  it "should generate inverse predicate for '@is xxx @of'" do
373
373
  n3 = %("value" @is :prop @of :b . :b :prop "value" .)
374
374
  nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
375
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
375
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
376
376
  end
377
377
 
378
378
  it "should generate inverse predicate for 'is xxx of' with object list" do
@@ -381,19 +381,19 @@ describe "RDF::N3::Reader" do
381
381
  <http://a/b#b> <http://a/b#prop> "value" .
382
382
  <http://a/b#c> <http://a/b#prop> "value" .
383
383
  )
384
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
384
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
385
385
  end
386
386
 
387
387
  it "should generate predicate for 'has xxx'" do
388
388
  n3 = %(@prefix a: <http://foo/a#> . a:b has :pred a:c .)
389
389
  nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
390
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
390
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
391
391
  end
392
392
 
393
393
  it "should generate predicate for '@has xxx'" do
394
394
  n3 = %(@prefix a: <http://foo/a#> . a:b @has :pred a:c .)
395
395
  nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
396
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
396
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
397
397
  end
398
398
 
399
399
  it "should create log:implies predicate for '=>'" do
@@ -433,13 +433,13 @@ describe "RDF::N3::Reader" do
433
433
  it "should accept empty localname" do
434
434
  n3 = %(: : : .)
435
435
  nt = %(<http://a/b#> <http://a/b#> <http://a/b#> .)
436
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
436
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
437
437
  end
438
438
 
439
439
  it "should accept prefix with empty local name" do
440
440
  n3 = %(@prefix foo: <http://foo/bar#> . foo: foo: foo: .)
441
441
  nt = %(<http://foo/bar#> <http://foo/bar#> <http://foo/bar#> .)
442
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
442
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
443
443
  end
444
444
 
445
445
  it "should do something for @forAll"
@@ -448,13 +448,37 @@ describe "RDF::N3::Reader" do
448
448
  end
449
449
 
450
450
  describe "namespaces" do
451
+ it "should not append # for http://foo/bar" do
452
+ n3 = %(@prefix : <http://foo/bar> . :a : :b .)
453
+ nt = %(
454
+ <http://foo/bara> <http://foo/bar> <http://foo/barb> .
455
+ )
456
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
457
+ end
458
+
459
+ it "should not append # for http://foo/bar/" do
460
+ n3 = %(@prefix : <http://foo/bar/> . :a : :b .)
461
+ nt = %(
462
+ <http://foo/bar/a> <http://foo/bar/> <http://foo/bar/b> .
463
+ )
464
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
465
+ end
466
+
467
+ it "should not append # for http://foo/bar#" do
468
+ n3 = %(@prefix : <http://foo/bar#> . :a : :b .)
469
+ nt = %(
470
+ <http://foo/bar#a> <http://foo/bar#> <http://foo/bar#b> .
471
+ )
472
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
473
+ end
474
+
451
475
  it "should set absolute base" do
452
476
  n3 = %(@base <http://foo/bar> . <> :a <b> . <#c> :d </e>.)
453
477
  nt = %(
454
- <http://foo/bar> <http://foo/bara> <http://foo/b> .
455
- <http://foo/bar#c> <http://foo/bard> <http://foo/e> .
478
+ <http://foo/bar> <http://foo/bar#a> <http://foo/b> .
479
+ <http://foo/bar#c> <http://foo/bar#d> <http://foo/e> .
456
480
  )
457
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
481
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
458
482
  end
459
483
 
460
484
  it "should set absolute base (trailing /)" do
@@ -463,16 +487,16 @@ describe "RDF::N3::Reader" do
463
487
  <http://foo/bar/> <http://foo/bar/a> <http://foo/bar/b> .
464
488
  <http://foo/bar/#c> <http://foo/bar/d> <http://foo/e> .
465
489
  )
466
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
490
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
467
491
  end
468
492
 
469
493
  it "should set absolute base (trailing #)" do
470
494
  n3 = %(@base <http://foo/bar#> . <> :a <b> . <#c> :d </e>.)
471
495
  nt = %(
472
- <http://foo/bar> <http://foo/bar#a> <http://foo/b> .
496
+ <http://foo/bar#> <http://foo/bar#a> <http://foo/b> .
473
497
  <http://foo/bar#c> <http://foo/bar#d> <http://foo/e> .
474
498
  )
475
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
499
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
476
500
  end
477
501
 
478
502
  it "should set relative base" do
@@ -492,7 +516,7 @@ describe "RDF::N3::Reader" do
492
516
  <http://example.org/products/> <http://example.org/products/a> <http://example.org/products/d> .
493
517
  <http://example.org/products/> <http://example.org/products/a> <http://example.org/products/#e> .
494
518
  )
495
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
519
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
496
520
  end
497
521
  end
498
522
 
@@ -522,7 +546,7 @@ describe "RDF::N3::Reader" do
522
546
  %(:c :a t) => %(<http://a/b#c> <http://a/b#a> <http://a/b#t> .),
523
547
  }.each_pair do |n3, nt|
524
548
  it "should use default_ns for '#{n3}'" do
525
- parse("@keywords . #{n3}", :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
549
+ parse("@keywords . #{n3}", :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
526
550
  end
527
551
  end
528
552
 
@@ -535,7 +559,7 @@ describe "RDF::N3::Reader" do
535
559
  %(@keywords has. :a has :b :c.) => %(<http://a/b#a> <http://a/b#b> <http://a/b#c> .),
536
560
  } .each_pair do |n3, nt|
537
561
  it "should use keyword for '#{n3}'" do
538
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
562
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
539
563
  end
540
564
  end
541
565
 
@@ -573,7 +597,7 @@ describe "RDF::N3::Reader" do
573
597
  <http://host/A#b> <http://host/A#p> <http://host/A#v> .
574
598
  <http://host/Z#b> <http://host/Z#p> <http://host/Z#v> .
575
599
  )
576
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
600
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
577
601
  end
578
602
 
579
603
  it "should process sequential @base declarations (swap base.n3)" do
@@ -583,11 +607,11 @@ describe "RDF::N3::Reader" do
583
607
  @prefix : <#>. <d3> :b3 <e3>.
584
608
  )
585
609
  nt = %(
586
- <http://example.com/a> <http://example.com/ontolgiesb> <http://example.com/foo/bar#baz> .
610
+ <http://example.com/a> <http://example.com/ontolgies#b> <http://example.com/foo/bar#baz> .
587
611
  <http://example.com/path/DFFERENT/a2> <http://example.com/path/DFFERENT/b2> <http://example.com/path/DFFERENT/foo/bar#baz2> .
588
612
  <http://example.com/path/DFFERENT/d3> <http://example.com/path/DFFERENT/#b3> <http://example.com/path/DFFERENT/e3> .
589
613
  )
590
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
614
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
591
615
  end
592
616
  end
593
617
 
@@ -600,13 +624,15 @@ describe "RDF::N3::Reader" do
600
624
  it "should create BNode for [] as subject" do
601
625
  n3 = %(@prefix a: <http://foo/a#> . [] a:p a:v .)
602
626
  nt = %(_:bnode0 <http://foo/a#p> <http://foo/a#v> .)
603
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
627
+ g = parse(n3, :base_uri => "http://a/b")
628
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
604
629
  end
605
630
 
606
631
  it "should create BNode for [] as predicate" do
607
632
  n3 = %(@prefix a: <http://foo/a#> . a:s [] a:o .)
608
633
  nt = %(<http://foo/a#s> _:bnode0 <http://foo/a#o> .)
609
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
634
+ g = parse(n3, :base_uri => "http://a/b")
635
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array, :anon => "bnode")
610
636
  end
611
637
 
612
638
  it "should create BNode for [] as object" do
@@ -785,7 +811,7 @@ describe "RDF::N3::Reader" do
785
811
  <http://foo/a#b> <http://foo/a#p2> <http://foo/a#v1> .
786
812
  <http://foo/a#b> <http://foo/a#p3> <http://foo/a#v2> .
787
813
  )
788
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
814
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
789
815
  end
790
816
  end
791
817
 
@@ -794,7 +820,7 @@ describe "RDF::N3::Reader" do
794
820
  n3 = %(@prefix :<http://example.com/>. :empty :set ().)
795
821
  nt = %(
796
822
  <http://example.com/empty> <http://example.com/set> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .)
797
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
823
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
798
824
  end
799
825
 
800
826
  it "should parse list with single element" do
@@ -843,7 +869,7 @@ describe "RDF::N3::Reader" do
843
869
  it "should add property to nil list" do
844
870
  n3 = %(@prefix a: <http://foo/a#> . () a:prop "nilProp" .)
845
871
  nt = %(<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://foo/a#prop> "nilProp" .)
846
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
872
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
847
873
  end
848
874
  it "should parse with compound items" do
849
875
  n3 = %(
@@ -857,21 +883,22 @@ describe "RDF::N3::Reader" do
857
883
  <http://resource1> a:p "value" .
858
884
  )
859
885
  nt = %(
860
- _:bnode0 <http://foo/a#p2> "v1" .
861
- _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode0 .
862
- _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode2 .
863
- _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource1> .
864
- _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode3 .
865
- _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource2> .
866
- _:bnode4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "inner list" .
867
- _:bnode4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
868
- _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode5 .
886
+ <http://foo/a#a> <http://foo/a#p> _:bnode5 .
869
887
  _:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode4 .
870
- _:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
871
- <http://foo/a#a> <http://foo/a#p> _:bnode1 .
888
+ _:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode2 .
889
+ _:bnode4 <http://foo/a#p2> "v1" .
890
+ _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource1> .
872
891
  <http://resource1> <http://foo/a#p> "value" .
892
+ _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode1 .
893
+ _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource2> .
894
+ _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode0 .
895
+ _:bnode0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode3 .
896
+ _:bnode0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
897
+ _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "inner list" .
898
+ _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
873
899
  )
874
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
900
+ g = parse(n3, :base_uri => "http://a/b")
901
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
875
902
  end
876
903
 
877
904
  end
@@ -971,7 +998,7 @@ EOF
971
998
 
972
999
  graph.should be_equivalent_graph(sampledoc,
973
1000
  :about => "http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/Manifest.rdf",
974
- :trace => @debug, :compare => :array
1001
+ :trace => @debug
975
1002
  )
976
1003
  end
977
1004
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'rdf-rdfxml', 'lib'))
2
3
  $:.unshift File.dirname(__FILE__)
3
4
 
4
5
  require 'rubygems'
@@ -24,6 +25,13 @@ module RDF
24
25
  end
25
26
  end
26
27
  end
28
+ def dump
29
+ b = []
30
+ self.each_statement do |statement|
31
+ b << statement.to_triple.inspect
32
+ end
33
+ b.join("\n")
34
+ end
27
35
  end
28
36
  end
29
37
 
@@ -31,6 +39,21 @@ Spec::Runner.configure do |config|
31
39
  config.include(RDF::Spec::Matchers)
32
40
  end
33
41
 
42
+
43
+ # Serialize graph and replace bnodes with predictable versions, return as sorted array
44
+ def normalize_bnodes(graph, anon = "a")
45
+ anon_ctx = {}
46
+ # Find and replace all BNodes within graph string
47
+ g_str = graph.to_ntriples
48
+ anon_entries = g_str.scan(/_:g\d+/).sort.uniq
49
+ anon_entries.each do |a|
50
+ anon_ctx[a] = "_:#{anon}"
51
+ anon = anon.succ
52
+ end
53
+
54
+ g_str.gsub(/_:g\d+/) { |bn| anon_ctx[bn] }.split("\n").sort
55
+ end
56
+
34
57
  # Heuristically detect the input stream
35
58
  def detect_format(stream)
36
59
  # Got to look into the file to see
data/spec/swap_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ $:.unshift "."
1
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
3
 
3
4
  describe RDF::N3::Reader do
@@ -42,6 +43,10 @@ describe RDF::N3::Reader do
42
43
  pending("check visually, graph compare times too long")
43
44
  elsif %w(n3_10010).include?(t.name)
44
45
  pending("Not supported in Ruby 1.8")
46
+ elsif %w(n3_10008 n3_10013).include?(t.name)
47
+ pending("Isomorphic compare issue")
48
+ elsif %w(n3_10016).include?(t.name)
49
+ pending("RDF.rb allows literal as predicate")
45
50
  else
46
51
  raise
47
52
  end
@@ -79,6 +84,8 @@ describe RDF::N3::Reader do
79
84
  pending("formulae not yet implemented")
80
85
  elsif %w(n3_20000).include?(t.name)
81
86
  pending("figure out how to tell that these are errors")
87
+ elsif %w(n3_20004).include?(t.name)
88
+ pending("RDF.rb allows literal as predicate")
82
89
  else
83
90
  raise
84
91
  end