rdf-rdfa 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/History.txt +6 -1
- data/README.rdoc +5 -3
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/etc/foaf.html +83 -0
- data/etc/xhv.html +459 -0
- data/lib/rdf/rdfa.rb +38 -0
- data/lib/rdf/rdfa/format.rb +28 -0
- data/lib/{rdfa → rdf/rdfa}/reader.rb +36 -89
- data/lib/{rdfa → rdf/rdfa}/reader/exceptions.rb +0 -0
- data/lib/{rdfa/reader → rdf/rdfa}/version.rb +2 -2
- data/lib/rdf/rdfa/vocab.rb +7 -0
- data/pkg/.gitignore +1 -0
- data/rdf-rdfa.gemspec +195 -0
- data/script/console +10 -0
- data/spec/rdfa_reader_spec.rb +173 -0
- data/spec/spec_helper.rb +5 -2
- metadata +74 -25
- data/lib/rdfa/format.rb +0 -19
- data/lib/rdfa/reader/namespace.rb +0 -72
- data/spec/namespaces_spec.rb +0 -112
- data/spec/rdfa_parser_spec.rb +0 -146
data/spec/namespaces_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe RDFa::Reader::Namespace do
|
4
|
-
subject { RDFa::Reader::Namespace.new("http://xmlns.com/foaf/0.1/", "foaf") }
|
5
|
-
|
6
|
-
describe "method_missing" do
|
7
|
-
it "should create URI" do
|
8
|
-
subject.knows.to_s.should == "http://xmlns.com/foaf/0.1/knows"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should create URI for frag" do
|
12
|
-
foaf_frag = RDFa::Reader::Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
|
13
|
-
foaf_frag.knows.to_s.should == "http://xmlns.com/foaf/0.1/knows"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have a URI" do
|
18
|
-
lambda do
|
19
|
-
test = RDFa::Reader::Namespace.new(prefix='foaf')
|
20
|
-
end.should raise_error
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have equality with URIs" do
|
24
|
-
foaf_name = RDF::URI.new("http://xmlns.com/foaf/0.1/name")
|
25
|
-
subject.name.should == foaf_name
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have an XML and N3-friendly prefix" do
|
29
|
-
lambda do
|
30
|
-
test = RDFa::Reader::Namespace.new('http://xmlns.com/foaf/0.1/', '*~{')
|
31
|
-
end.should raise_error
|
32
|
-
end
|
33
|
-
|
34
|
-
# it "should be able to attach to the graph for substitution" do
|
35
|
-
# # rdflib does this using graph.bind('prefix', namespace)
|
36
|
-
# g = RDF::Graph.new
|
37
|
-
# subject.bind(g)
|
38
|
-
# #puts g.nsbinding.inspect
|
39
|
-
# should == g.nsbinding["foaf"]
|
40
|
-
# end
|
41
|
-
|
42
|
-
it "should not allow you to attach to non-graphs" do
|
43
|
-
lambda do
|
44
|
-
subject.bind("cheese")
|
45
|
-
end.should raise_error
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should construct URI" do
|
49
|
-
subject.foo.class.should == RDF::URI
|
50
|
-
subject.foo.to_s.should == "http://xmlns.com/foaf/0.1/foo"
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "no URI normalization" do
|
54
|
-
specify {RDFa::Reader::Namespace.new("http://foo", "foo").uri.to_s.should == "http://foo"}
|
55
|
-
specify {RDFa::Reader::Namespace.new("http://foo#", "foo").uri.to_s.should == "http://foo#"}
|
56
|
-
specify {RDFa::Reader::Namespace.new("http://foo/", "foo").uri.to_s.should == "http://foo/"}
|
57
|
-
specify {RDFa::Reader::Namespace.new("xyz:foo", "foo").uri.to_s.should == "xyz:foo"}
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should not normalize URI" do
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "serialization" do
|
64
|
-
specify {subject.to_s.should == "foaf: http://xmlns.com/foaf/0.1/"}
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#+' do
|
68
|
-
it "should construct URI with +" do
|
69
|
-
(subject + "foo").class.should == RDF::URI
|
70
|
-
(subject + "foo").to_s.should == "http://xmlns.com/foaf/0.1/foo"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should strip trailing _ (used to work around reserved method names)" do
|
74
|
-
(subject + "type_").to_s.should == "http://xmlns.com/foaf/0.1/type"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "will cause method conflict" do
|
78
|
-
(subject + "class").to_s.should == "http://xmlns.com/foaf/0.1/class"
|
79
|
-
subject.class.should == RDFa::Reader::Namespace
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "normalization" do
|
84
|
-
{
|
85
|
-
%w(http://foo ) => "http://foo",
|
86
|
-
%w(http://foo a) => "http://fooa",
|
87
|
-
|
88
|
-
%w(http://foo/ ) => "http://foo/",
|
89
|
-
%w(http://foo/ a) => "http://foo/a",
|
90
|
-
|
91
|
-
%w(http://foo# ) => "http://foo#",
|
92
|
-
%w(http://foo# a) => "http://foo#a",
|
93
|
-
|
94
|
-
%w(http://foo/bar ) => "http://foo/bar",
|
95
|
-
%w(http://foo/bar a) => "http://foo/bara",
|
96
|
-
|
97
|
-
%w(http://foo/bar/ ) => "http://foo/bar/",
|
98
|
-
%w(http://foo/bar/ a) => "http://foo/bar/a",
|
99
|
-
|
100
|
-
%w(http://foo/bar# ) => "http://foo/bar#",
|
101
|
-
%w(http://foo/bar# a) => "http://foo/bar#a",
|
102
|
-
}.each_pair do |input, result|
|
103
|
-
it "should create <#{result}> from <#{input[0]}> and '#{input[1]}'" do
|
104
|
-
(RDFa::Reader::Namespace.new(input[0], "test") + input[1].to_s).to_s.should == result
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should be be equivalent" do
|
110
|
-
RDFa::Reader::Namespace.new("http://a", "aa").should == RDFa::Reader::Namespace.new("http://a", "aa")
|
111
|
-
end
|
112
|
-
end
|
data/spec/rdfa_parser_spec.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe "RDFa parser" do
|
4
|
-
it "should parse simple doc" do
|
5
|
-
sampledoc = <<-EOF;
|
6
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
7
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
8
|
-
<html xmlns="http://www.w3.org/1999/xhtml"
|
9
|
-
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
10
|
-
<head>
|
11
|
-
<title>Test 0001</title>
|
12
|
-
</head>
|
13
|
-
<body>
|
14
|
-
<p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
|
15
|
-
</body>
|
16
|
-
</html>
|
17
|
-
EOF
|
18
|
-
|
19
|
-
# FIXME: base URIs arn't working
|
20
|
-
reader = RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :strict => true)
|
21
|
-
reader.graph.size.should == 1
|
22
|
-
reader.graph.should have_object("Mark Birbeck")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should parse simple doc without a base URI" do
|
26
|
-
sampledoc = <<-EOF;
|
27
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
28
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
29
|
-
<html xmlns="http://www.w3.org/1999/xhtml"
|
30
|
-
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
31
|
-
<body>
|
32
|
-
<p>This photo was taken by <span class="author" about="_:photo" property="dc:creator">Mark Birbeck</span>.</p>
|
33
|
-
</body>
|
34
|
-
</html>
|
35
|
-
EOF
|
36
|
-
|
37
|
-
reader = RDFa::Reader.new(sampledoc, :strict => true)
|
38
|
-
reader.graph.size.should == 1
|
39
|
-
reader.graph.should have_triple([RDF::Node('photo'), RDF::DC11.creator, "Mark Birbeck"])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should parse an XML Literal" do
|
43
|
-
sampledoc = <<-EOF
|
44
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
45
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
46
|
-
<html xmlns="http://www.w3.org/1999/xhtml"
|
47
|
-
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
48
|
-
<head>
|
49
|
-
<title>Test 0011</title>
|
50
|
-
</head>
|
51
|
-
<body>
|
52
|
-
<div about="">
|
53
|
-
Author: <span property="dc:creator">Albert Einstein</span>
|
54
|
-
<h2 property="dc:title">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
|
55
|
-
</div>
|
56
|
-
</body>
|
57
|
-
</html>
|
58
|
-
EOF
|
59
|
-
|
60
|
-
reader = RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :strict => true)
|
61
|
-
reader.graph.size.should == 2
|
62
|
-
|
63
|
-
reader.graph.should have_object("Albert Einstein")
|
64
|
-
reader.graph.should have_object(
|
65
|
-
RDF::Literal("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
|
66
|
-
:datatype => RDF::URI('http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral'))
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
it "should parse BNodes" do
|
72
|
-
sampledoc = <<-EOF
|
73
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
74
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
75
|
-
<html xmlns="http://www.w3.org/1999/xhtml"
|
76
|
-
xmlns:foaf="http://xmlns.com/foaf/0.1/">
|
77
|
-
<head>
|
78
|
-
<title>Test 0017</title>
|
79
|
-
</head>
|
80
|
-
<body>
|
81
|
-
<p>
|
82
|
-
<span about="[_:a]" property="foaf:name">Manu Sporny</span>
|
83
|
-
<span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
|
84
|
-
<span about="[_:b]" property="foaf:name">Ralph Swick</span>.
|
85
|
-
</p>
|
86
|
-
</body>
|
87
|
-
</html>
|
88
|
-
EOF
|
89
|
-
|
90
|
-
reader = RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :strict => true)
|
91
|
-
|
92
|
-
reader.graph.size.should == 3
|
93
|
-
reader.graph.should have_object("Ralph Swick")
|
94
|
-
reader.graph.should have_object("Manu Sporny")
|
95
|
-
end
|
96
|
-
|
97
|
-
# def self.test_cases(suite)
|
98
|
-
# RdfaHelper::TestCase.test_cases(suite)
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
# # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
|
102
|
-
# %w(xhtml html4 html5).each do |suite|
|
103
|
-
# describe "w3c #{suite} testcases" do
|
104
|
-
# describe "that are approved" do
|
105
|
-
# test_cases(suite).each do |t|
|
106
|
-
# puts t.inspect
|
107
|
-
# next unless t.status == "approved"
|
108
|
-
# #next unless t.name =~ /0140/
|
109
|
-
# specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
110
|
-
# #puts t.input
|
111
|
-
# #puts t.results
|
112
|
-
# begin
|
113
|
-
# t.run_test do |rdfa_string, rdfa_parser|
|
114
|
-
# rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
|
115
|
-
# end
|
116
|
-
# rescue SparqlException => e
|
117
|
-
# pending(e.message) { raise }
|
118
|
-
# end
|
119
|
-
# end
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
# describe "that are unreviewed" do
|
123
|
-
# test_cases(suite).each do |t|
|
124
|
-
# next unless t.status == "unreviewed"
|
125
|
-
# #next unless t.name =~ /0185/
|
126
|
-
# #puts t.inspect
|
127
|
-
# specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
128
|
-
# begin
|
129
|
-
# t.run_test do |rdfa_string, rdfa_parser|
|
130
|
-
# rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
|
131
|
-
# end
|
132
|
-
# rescue SparqlException => e
|
133
|
-
# pending(e.message) { raise }
|
134
|
-
# rescue Spec::Expectations::ExpectationNotMetError => e
|
135
|
-
# if t.name =~ /01[789]\d/
|
136
|
-
# raise
|
137
|
-
# else
|
138
|
-
# pending() { raise }
|
139
|
-
# end
|
140
|
-
# end
|
141
|
-
# end
|
142
|
-
# end
|
143
|
-
# end
|
144
|
-
# end
|
145
|
-
# end
|
146
|
-
end
|