rdf-rdfa 0.3.1.2 → 0.3.3
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/.yardopts +2 -1
- data/Gemfile +18 -0
- data/History.md +14 -1
- data/README +291 -0
- data/README.md +236 -36
- data/Rakefile +7 -27
- data/UNLICENSE +24 -0
- data/VERSION +1 -1
- data/etc/basic.html +1 -1
- data/etc/profile.html +40 -0
- data/example-files/payswarm.html +449 -0
- data/example-files/payswarm.n3 +86 -0
- data/lib/rdf/rdfa.rb +5 -0
- data/lib/rdf/rdfa/format.rb +8 -4
- data/lib/rdf/rdfa/patches/graph_properties.rb +34 -0
- data/lib/rdf/rdfa/patches/nokogiri_hacks.rb +6 -0
- data/lib/rdf/rdfa/patches/string_hacks.rb +9 -0
- data/lib/rdf/rdfa/profile.rb +65 -41
- data/lib/rdf/rdfa/profile/xhtml.rb +36 -0
- data/lib/rdf/rdfa/profile/xml.rb +45 -0
- data/lib/rdf/rdfa/reader.rb +168 -92
- data/lib/rdf/rdfa/writer.rb +822 -0
- data/lib/rdf/rdfa/writer/haml_templates.rb +306 -0
- data/rdf-rdfa.gemspec +77 -23
- data/script/intern_vocabulary +83 -0
- data/script/parse +62 -27
- data/script/tc +87 -37
- data/spec/.gitignore +1 -0
- data/spec/matchers.rb +89 -154
- data/spec/profile_spec.rb +36 -21
- data/spec/{rdfa_reader_spec.rb → reader_spec.rb} +86 -159
- data/spec/spec_helper.rb +6 -29
- data/spec/test_helper.rb +97 -0
- data/spec/writer_spec.rb +385 -0
- metadata +203 -37
- data/spec/html4-manifest.yml +0 -1749
- data/spec/html5-manifest.yml +0 -1749
- data/spec/rdfa_helper.rb +0 -257
- data/spec/svgtiny-manifest.yml +0 -37
- data/spec/xhtml-manifest.yml +0 -1749
data/spec/profile_spec.rb
CHANGED
@@ -4,50 +4,65 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
4
4
|
describe RDF::RDFa::Profile do
|
5
5
|
describe ".new" do
|
6
6
|
describe "foaf" do
|
7
|
-
subject { RDF::RDFa::Profile.new("http://
|
7
|
+
subject { RDF::RDFa::Profile.new("http://example/") }
|
8
8
|
|
9
|
+
it "has a URI" do
|
10
|
+
subject.uri.should == RDF::URI("http://example/")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has no terms" do
|
14
|
+
subject.terms.should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has no vocabulary" do
|
18
|
+
subject.vocabulary.should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has no prefixes" do
|
22
|
+
subject.prefixes.should be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".find" do
|
28
|
+
describe "foaf" do
|
29
|
+
subject { RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf") }
|
30
|
+
|
9
31
|
it "has 74 terms" do
|
10
32
|
subject.terms.keys.length.should == 74
|
11
33
|
end
|
12
34
|
|
35
|
+
it "uses symbols for term lookup" do
|
36
|
+
subject.terms.keys.all? {|k| k.is_a?(Symbol)}.should be_true
|
37
|
+
end
|
38
|
+
|
13
39
|
it "has no vocabulary" do
|
14
40
|
subject.vocabulary.should be_nil
|
15
41
|
end
|
16
|
-
|
42
|
+
|
17
43
|
it "has no prefixes" do
|
18
44
|
subject.prefixes.should be_empty
|
19
45
|
end
|
20
46
|
end
|
21
47
|
|
22
48
|
describe "basic" do
|
23
|
-
subject { RDF::RDFa::Profile.
|
24
|
-
|
49
|
+
subject { RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/basic") }
|
50
|
+
|
25
51
|
it "has no terms" do
|
26
52
|
subject.terms.should be_empty
|
27
53
|
end
|
28
|
-
|
54
|
+
|
29
55
|
it "has no vocabulary" do
|
30
56
|
subject.vocabulary.should be_nil
|
31
57
|
end
|
32
|
-
|
58
|
+
|
33
59
|
it "has 6 prefixes" do
|
34
60
|
subject.prefixes.keys.length.should == 6
|
35
61
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
before(:all) do
|
41
|
-
RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/basic")
|
42
|
-
RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "cached basic" do
|
46
|
-
RDF::RDFa::Profile.cache[RDF::URI.intern("http://rdfa.digitalbazaar.com/test-suite/profiles/basic")].should be_a(RDF::RDFa::Profile)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "cached foaf" do
|
50
|
-
RDF::RDFa::Profile.cache[RDF::URI.intern("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf")].should be_a(RDF::RDFa::Profile)
|
62
|
+
|
63
|
+
it "uses symbols for prefix lookup" do
|
64
|
+
subject.prefixes.keys.all? {|k| k.is_a?(Symbol)}.should be_true
|
65
|
+
end
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
@@ -1,36 +1,38 @@
|
|
1
1
|
$:.unshift "."
|
2
2
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
-
require 'rdfa_helper'
|
4
3
|
|
5
4
|
describe RDF::RDFa::Format do
|
6
|
-
|
7
|
-
|
8
|
-
RDF::Format
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
]
|
18
|
-
|
5
|
+
context "should be discover 'rdfa'" do
|
6
|
+
[
|
7
|
+
[:rdfa, RDF::RDFa::Format],
|
8
|
+
["etc/foaf.html", RDF::RDFa::Format],
|
9
|
+
[{:file_name => "etc/foaf.html"}, RDF::RDFa::Format],
|
10
|
+
[{:file_extension => "html"}, RDF::RDFa::Format],
|
11
|
+
[{:file_extension => "xhtml"}, RDF::RDFa::XHTML],
|
12
|
+
[{:file_extension => "svg"}, RDF::RDFa::SVG],
|
13
|
+
[{:content_type => "text/html"}, RDF::RDFa::Format],
|
14
|
+
[{:content_type => "application/xhtml+xml"}, RDF::RDFa::XHTML],
|
15
|
+
[{:content_type => "image/svg+xml"}, RDF::RDFa::SVG],
|
16
|
+
].each do |(arg, format)|
|
17
|
+
it "returns #{format} for #{arg.inspect}" do
|
18
|
+
RDF::Format.for(arg).should == format
|
19
|
+
end
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it "should discover 'html'" do
|
22
24
|
RDF::Format.for(:html).reader.should == RDF::RDFa::Reader
|
23
|
-
|
25
|
+
RDF::Format.for(:html).writer.should == RDF::RDFa::Writer
|
24
26
|
end
|
25
27
|
|
26
28
|
it "should discover 'xhtml'" do
|
27
29
|
RDF::Format.for(:xhtml).reader.should == RDF::RDFa::Reader
|
28
|
-
|
30
|
+
RDF::Format.for(:xhtml).writer.should == RDF::RDFa::Writer
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should discover 'svg'" do
|
32
34
|
RDF::Format.for(:svg).reader.should == RDF::RDFa::Reader
|
33
|
-
|
35
|
+
RDF::Format.for(:svg).writer.should == RDF::RDFa::Writer
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -414,64 +416,59 @@ describe "RDF::RDFa::Reader" do
|
|
414
416
|
end
|
415
417
|
|
416
418
|
describe :profiles do
|
417
|
-
before(:
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
</
|
426
|
-
<
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
end
|
434
|
-
|
419
|
+
before(:each) do
|
420
|
+
@profile = StringIO.new(%q(<?xml version="1.0" encoding="UTF-8"?>
|
421
|
+
<!DOCTYPE html>
|
422
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
423
|
+
<head>
|
424
|
+
<title>Test mappings</title>
|
425
|
+
</head>
|
426
|
+
<body prefix="rdfa: http://www.w3.org/ns/rdfa#">
|
427
|
+
<p typeof=""><span property="rdfa:uri">http://example.org/</span><span property="rdfa:prefix">foo</span></p>
|
428
|
+
<p typeof=""><span property="rdfa:uri">http://example.org/title</span><span property="rdfa:term">title</span></p>
|
429
|
+
</body>
|
430
|
+
</html>
|
431
|
+
))
|
432
|
+
def @profile.content_type; "text/html"; end
|
433
|
+
def @profile.base_uri; "http://example.com/profile"; end
|
434
|
+
|
435
435
|
@doc = %(<?xml version="1.0" encoding="UTF-8"?>
|
436
436
|
<!DOCTYPE html>
|
437
437
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
438
438
|
<body profile="http://example.com/profile">
|
439
|
-
<div about
|
439
|
+
<div about="http://example.com/doc" typeof="foo:Agent">
|
440
440
|
<p property="title">A particular agent</p>
|
441
441
|
</div>
|
442
442
|
</body>
|
443
443
|
</html>
|
444
444
|
)
|
445
|
-
end
|
446
445
|
|
447
|
-
|
446
|
+
RDF::Util::File.stub!(:open_file).and_yield(@profile)
|
447
|
+
|
448
448
|
@profile_repository = RDF::Repository.new(:title => "Test Profile Repository")
|
449
449
|
@debug = []
|
450
450
|
@reader = RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository, :debug => @debug, :validate => true)
|
451
|
+
|
452
|
+
@expected = RDF::Graph.new
|
453
|
+
@expected << [RDF::URI("http://example.com/doc"), RDF.type, RDF::URI("http://example.org/Agent")]
|
454
|
+
@expected << [RDF::URI("http://example.com/doc"), RDF::URI("http://example.org/title"), "A particular agent"]
|
451
455
|
end
|
452
|
-
|
453
|
-
|
454
|
-
|
456
|
+
|
457
|
+
it "parses profile" do
|
458
|
+
RDF::Reader.should_receive(:for).at_least(1).times.and_return(RDF::RDFa::Reader)
|
459
|
+
g = RDF::Graph.load(@profile)
|
460
|
+
g.count.should == 4
|
455
461
|
end
|
456
|
-
|
462
|
+
|
457
463
|
describe "new profile" do
|
458
|
-
|
464
|
+
subject do
|
459
465
|
# Clear vocabulary cache
|
460
466
|
RDF::RDFa::Profile.cache.send(:initialize)
|
461
|
-
|
462
|
-
@reader.each do |statement|
|
463
|
-
@graph << statement
|
464
|
-
end
|
467
|
+
RDF::Graph.new << @reader
|
465
468
|
end
|
466
469
|
|
467
|
-
|
468
|
-
|
469
|
-
@graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF.type, RDF::DC.Agent))
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should have property dc:title" do
|
473
|
-
@graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF::DC.title, RDF::Literal.new("A particular agent")))
|
474
|
-
end
|
470
|
+
it "matches expected" do
|
471
|
+
subject.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
|
475
472
|
end
|
476
473
|
end
|
477
474
|
|
@@ -497,10 +494,11 @@ describe "RDF::RDFa::Reader" do
|
|
497
494
|
before(:each) do
|
498
495
|
bn_p = RDF::Node.new("prefix")
|
499
496
|
bn_t = RDF::Node.new("term")
|
500
|
-
|
501
|
-
@profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.
|
502
|
-
@profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.
|
503
|
-
@profile_repository << RDF::Statement.new(
|
497
|
+
ctx = RDF::URI("http://example.com/profile")
|
498
|
+
@profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.prefix, RDF::Literal.new("foo"), :context => ctx)
|
499
|
+
@profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.uri, RDF::Literal.new("http://example.org/"), :context => ctx)
|
500
|
+
@profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.term, RDF::Literal.new("title"), :context => ctx)
|
501
|
+
@profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.uri, RDF::Literal.new("http://example.org/title"), :context => ctx)
|
504
502
|
|
505
503
|
# Clear vocabulary cache
|
506
504
|
RDF::RDFa::Profile.cache.send(:initialize)
|
@@ -508,118 +506,47 @@ describe "RDF::RDFa::Reader" do
|
|
508
506
|
|
509
507
|
it "should not recieve RDF::Reader.open" do
|
510
508
|
RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
|
509
|
+
@reader.each {|s|}
|
511
510
|
end
|
512
511
|
|
513
|
-
it "
|
514
|
-
|
515
|
-
|
516
|
-
@graph << statement
|
517
|
-
end
|
518
|
-
|
519
|
-
@graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF.type, RDF::DC.Agent))
|
520
|
-
end
|
521
|
-
|
522
|
-
it "should have property dc:title" do
|
523
|
-
@graph = RDF::Graph.new
|
524
|
-
@reader.each do |statement|
|
525
|
-
@graph << statement
|
526
|
-
end
|
527
|
-
|
528
|
-
@graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF::DC.title, RDF::Literal.new("A particular agent")))
|
512
|
+
it "matches expected" do
|
513
|
+
graph = RDF::Graph.new << @reader
|
514
|
+
graph.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
|
529
515
|
end
|
530
516
|
end
|
531
517
|
end
|
532
518
|
|
533
|
-
def self.test_cases(suite)
|
534
|
-
RdfaHelper::TestCase.test_cases(suite)
|
535
|
-
end
|
536
|
-
|
537
519
|
# W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
rescue SparqlException => e
|
562
|
-
pending(e.message) { raise }
|
563
|
-
end
|
564
|
-
end
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
describe "that are optional" do
|
569
|
-
test_cases(suite).each do |t|
|
570
|
-
next unless t.classification =~ /optional/
|
571
|
-
#next unless t.name =~ /0185/
|
572
|
-
#puts t.inspect
|
573
|
-
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
574
|
-
begin
|
575
|
-
t.run_test do |rdfa_string|
|
576
|
-
t.debug = []
|
577
|
-
parse(rdfa_string,
|
578
|
-
:base_uri => t.informationResourceInput,
|
579
|
-
:debug => t.debug,
|
580
|
-
:version => t.version)
|
581
|
-
end
|
582
|
-
rescue SparqlException => e
|
583
|
-
pending(e.message) { raise }
|
584
|
-
rescue RSpec::Expectations::ExpectationNotMetError => e
|
585
|
-
if t.name =~ /01[789]\d/
|
586
|
-
raise
|
587
|
-
else
|
588
|
-
pending() { raise }
|
589
|
-
end
|
590
|
-
end
|
591
|
-
end
|
592
|
-
end
|
593
|
-
end
|
594
|
-
|
595
|
-
describe "that are buggy" do
|
596
|
-
test_cases(suite).each do |t|
|
597
|
-
next unless t.classification =~ /buggy/
|
598
|
-
#next unless t.name =~ /0185/
|
599
|
-
#puts t.inspect
|
600
|
-
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
601
|
-
begin
|
602
|
-
t.run_test do |rdfa_string|
|
603
|
-
t.debug = []
|
604
|
-
parse(rdfa_string,
|
605
|
-
:base_uri => t.informationResourceInput,
|
606
|
-
:debug => t.debug,
|
607
|
-
:version => t.version)
|
608
|
-
end
|
609
|
-
rescue SparqlException => e
|
610
|
-
pending(e.message) { raise }
|
611
|
-
rescue RSpec::Expectations::ExpectationNotMetError => e
|
612
|
-
if t.name =~ /01[789]\d/
|
613
|
-
raise
|
614
|
-
else
|
615
|
-
pending() { raise }
|
520
|
+
describe "w3c test cases" do
|
521
|
+
require 'test_helper'
|
522
|
+
|
523
|
+
Fixtures::TestCase::HOST_LANGUAGE_VERSION_SETS.each do |(host_language, version)|
|
524
|
+
describe "for #{host_language} #{version}" do
|
525
|
+
%w(required optional buggy).each do |classification|
|
526
|
+
describe "that are #{classification}" do
|
527
|
+
Fixtures::TestCase.for_specific(host_language, version, Fixtures::TestCase::Test.send(classification)) do |t|
|
528
|
+
specify "test #{t.name}: #{t.title}#{", (negative test)" if t.expectedResults.false?}" do
|
529
|
+
begin
|
530
|
+
t.debug = []
|
531
|
+
graph = RDF::Graph.load(t.input(host_language, version), :debug => t.debug, :format => :rdfa)
|
532
|
+
query = Kernel.open(t.results(host_language, version))
|
533
|
+
graph.should pass_query(query, t)
|
534
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
535
|
+
if %w(0198).include?(t.name) || query =~ /XMLLiteral/m
|
536
|
+
pending("XMLLiteral canonicalization not implemented yet")
|
537
|
+
elsif classification != "required"
|
538
|
+
pending("#{classification} test") { raise }
|
539
|
+
else
|
540
|
+
raise
|
541
|
+
end
|
542
|
+
end
|
616
543
|
end
|
617
544
|
end
|
618
545
|
end
|
619
546
|
end
|
620
547
|
end
|
621
|
-
|
622
|
-
|
548
|
+
end
|
549
|
+
end
|
623
550
|
|
624
551
|
def parse(input, options)
|
625
552
|
@debug = options[:debug] || []
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$:.unshift File.dirname(__FILE__)
|
3
3
|
|
4
|
+
require "bundler/setup"
|
4
5
|
require 'rubygems'
|
5
6
|
require 'rspec'
|
6
7
|
require 'bigdecimal' # XXX Remove Me
|
@@ -8,34 +9,13 @@ require 'rdf/rdfa'
|
|
8
9
|
require 'rdf/spec'
|
9
10
|
require 'rdf/spec/matchers'
|
10
11
|
require 'rdf/isomorphic'
|
11
|
-
|
12
|
-
begin
|
13
|
-
require 'rdf/redland'
|
14
|
-
$redland_enabled = true
|
15
|
-
rescue LoadError
|
16
|
-
end
|
12
|
+
require 'open-uri/cached'
|
17
13
|
require 'matchers'
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
alias_method :==, :isomorphic_with?
|
24
|
-
end
|
25
|
-
class Graph
|
26
|
-
def to_ntriples
|
27
|
-
RDF::Writer.for(:ntriples).buffer do |writer|
|
28
|
-
writer << self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_rdfxml
|
33
|
-
RDF::Writer.for(:rdfxml).buffer do |writer|
|
34
|
-
writer << self
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
15
|
+
# Create and maintain a cache of downloaded URIs
|
16
|
+
URI_CACHE = File.expand_path(File.join(File.dirname(__FILE__), "uri-cache"))
|
17
|
+
Dir.mkdir(URI_CACHE) unless File.directory?(URI_CACHE)
|
18
|
+
OpenURI::Cache.class_eval { @cache_path = URI_CACHE }
|
39
19
|
|
40
20
|
::RSpec.configure do |c|
|
41
21
|
c.filter_run :focus => true
|
@@ -43,7 +23,6 @@ end
|
|
43
23
|
c.exclusion_filter = {
|
44
24
|
:ruby => lambda { |version| !(RUBY_VERSION.to_s =~ /^#{version.to_s}/) },
|
45
25
|
}
|
46
|
-
c.include(Matchers)
|
47
26
|
c.include(RDF::Spec::Matchers)
|
48
27
|
end
|
49
28
|
|
@@ -60,8 +39,6 @@ def detect_format(stream)
|
|
60
39
|
string = stream.to_s
|
61
40
|
end
|
62
41
|
case string
|
63
|
-
when /<\w+:RDF/ then RDF::RDFXML::Reader
|
64
|
-
when /<RDF/ then RDF::RDFXML::Reader
|
65
42
|
when /<html/i then RDF::RDFa::Reader
|
66
43
|
when /@prefix/i then RDF::N3::Reader
|
67
44
|
else RDF::NTriples::Reader
|