rdf-rdfxml 0.3.2.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +2 -1
- data/History.rdoc +5 -0
- data/README +95 -0
- data/README.md +31 -11
- data/Rakefile +5 -7
- data/VERSION +1 -1
- data/lib/rdf/rdfxml/format.rb +1 -1
- data/lib/rdf/rdfxml/reader.rb +0 -13
- data/lib/rdf/rdfxml/writer.rb +67 -56
- data/lib/rdf/rdfxml.rb +15 -1
- data/rdf-rdfxml.gemspec +13 -11
- data/script/tc +1 -1
- data/spec/format_spec.rb +9 -9
- data/spec/matchers.rb +72 -54
- data/spec/rdf_test.rb +1 -22
- data/spec/reader_spec.rb +17 -23
- data/spec/spec_helper.rb +6 -18
- data/spec/writer_spec.rb +448 -238
- metadata +8 -6
data/spec/writer_spec.rb
CHANGED
@@ -14,368 +14,576 @@ describe "RDF::RDFXML::Writer" do
|
|
14
14
|
it_should_behave_like RDF_Writer
|
15
15
|
|
16
16
|
describe "#buffer" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
serialize(:max_depth => 1, :attributes => :untyped)
|
17
|
+
context "typed resources" do
|
18
|
+
context "resource without type" do
|
19
|
+
subject do
|
20
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
21
|
+
serialize(:max_depth => 1, :attributes => :untyped)
|
22
|
+
end
|
23
|
+
|
24
|
+
{
|
22
25
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
23
26
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
24
|
-
|
27
|
+
}.each do |path, value|
|
28
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
29
|
+
subject.should have_xpath(path, value)
|
30
|
+
end
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
serialize(:max_depth => 1, :attributes => :untyped)
|
34
|
+
context "resource with type" do
|
35
|
+
subject do
|
36
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
37
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
38
|
+
serialize(:max_depth => 1, :attributes => :untyped)
|
39
|
+
end
|
40
|
+
|
41
|
+
{
|
32
42
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
33
43
|
"/rdf:RDF/foo:Release/@dc:title" =>"foo",
|
34
44
|
"/rdf:RDF/foo:Release/rdf:type" => ""
|
35
|
-
|
45
|
+
}.each do |path, value|
|
46
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
47
|
+
subject.should have_xpath(path, value)
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
serialize(:max_depth => 1, :attributes => :untyped)
|
52
|
+
context "resource with two types as attribute" do
|
53
|
+
subject do
|
54
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
55
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
56
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
57
|
+
serialize(:max_depth => 1, :attributes => :untyped)
|
58
|
+
end
|
59
|
+
|
60
|
+
{
|
44
61
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
45
62
|
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
46
63
|
"/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
|
47
|
-
|
64
|
+
}.each do |path, value|
|
65
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
66
|
+
subject.should have_xpath(path, value)
|
67
|
+
end
|
68
|
+
end
|
48
69
|
end
|
49
70
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
serialize(:max_depth => 1, :attributes => :none)
|
71
|
+
context "resource with two types as element" do
|
72
|
+
subject do
|
73
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
74
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
75
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
76
|
+
serialize(:max_depth => 1, :attributes => :none)
|
77
|
+
end
|
78
|
+
|
79
|
+
{
|
56
80
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
57
|
-
"/rdf:RDF/foo:Release/dc:title" =>
|
58
|
-
%(/rdf:RDF/foo:Release/rdf:type
|
81
|
+
"/rdf:RDF/foo:Release/dc:title/text()" => "foo",
|
82
|
+
%(/rdf:RDF/foo:Release/rdf:type/@rdf:resource) => FOO.XtraRelease.to_s,
|
59
83
|
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.Release}"]) => false
|
60
|
-
|
84
|
+
}.each do |path, value|
|
85
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
86
|
+
subject.should have_xpath(path, value)
|
87
|
+
end
|
88
|
+
end
|
61
89
|
end
|
62
90
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
serialize(:max_depth => 1, :attributes => :typed)
|
91
|
+
context "resource with three types as element" do
|
92
|
+
subject do
|
93
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
94
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
95
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
|
96
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
97
|
+
serialize(:max_depth => 1, :attributes => :typed)
|
98
|
+
end
|
99
|
+
|
100
|
+
{
|
70
101
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
71
|
-
"/rdf:RDF/foo:Release/@dc:title" =>
|
72
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) =>
|
73
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) =>
|
74
|
-
|
102
|
+
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
103
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => %r(#{FOO.XtraRelease}),
|
104
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => %r(#{FOO.XXtraRelease})
|
105
|
+
}.each do |path, value|
|
106
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
107
|
+
subject.should have_xpath(path, value)
|
108
|
+
end
|
109
|
+
end
|
75
110
|
end
|
76
111
|
end
|
77
112
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
serialize(:max_depth => 1, :attributes => :untyped)
|
113
|
+
context "with children" do
|
114
|
+
context "referenced resource by ref" do
|
115
|
+
subject do
|
116
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
117
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
118
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
119
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
120
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
121
|
+
serialize(:max_depth => 1, :attributes => :untyped)
|
122
|
+
end
|
123
|
+
|
124
|
+
{
|
87
125
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
88
126
|
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
89
127
|
"/rdf:RDF/foo:Release/foo:releaseContributor/@rdf:resource" => "http://release/contributor",
|
90
128
|
"/rdf:RDF/foo:Contributor/@rdf:about" => "http://release/contributor",
|
91
129
|
"/rdf:RDF/foo:Contributor/@dc:title" => "bar"
|
92
|
-
|
130
|
+
}.each do |path, value|
|
131
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
132
|
+
subject.should have_xpath(path, value)
|
133
|
+
end
|
134
|
+
end
|
93
135
|
end
|
94
136
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
serialize(:max_depth => 3, :attributes => :untyped)
|
137
|
+
context "referenced resource by inclusion" do
|
138
|
+
subject do
|
139
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
140
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
141
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
142
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
143
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
144
|
+
serialize(:max_depth => 3, :attributes => :untyped)
|
145
|
+
end
|
146
|
+
|
147
|
+
{
|
103
148
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
104
149
|
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
105
150
|
"/rdf:RDF/foo:Release/foo:releaseContributor/foo:Contributor/@rdf:about" => "http://release/contributor"
|
106
|
-
|
151
|
+
}.each do |path, value|
|
152
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
153
|
+
subject.should have_xpath(path, value)
|
154
|
+
end
|
155
|
+
end
|
107
156
|
end
|
108
157
|
end
|
109
158
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
serialize(:max_depth => 1, :attributes => :none)
|
159
|
+
context "with sequences" do
|
160
|
+
context "rdf:Seq with rdf:_n" do
|
161
|
+
subject do
|
162
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
163
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
164
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
165
|
+
serialize(:max_depth => 1, :attributes => :none)
|
166
|
+
end
|
167
|
+
|
168
|
+
{
|
117
169
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
118
|
-
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) =>
|
119
|
-
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) =>
|
120
|
-
|
170
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
|
171
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /second/
|
172
|
+
}.each do |path, value|
|
173
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
174
|
+
subject.should have_xpath(path, value)
|
175
|
+
end
|
176
|
+
end
|
121
177
|
end
|
122
178
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
serialize(:max_depth => 1, :attributes => :none)
|
179
|
+
context "rdf:Seq with rdf:_n in proper sequence" do
|
180
|
+
subject do
|
181
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
182
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
183
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
184
|
+
serialize(:max_depth => 1, :attributes => :none)
|
185
|
+
end
|
186
|
+
|
187
|
+
{
|
129
188
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
130
|
-
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) =>
|
131
|
-
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) =>
|
132
|
-
|
189
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
|
190
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
|
191
|
+
}.each do |path, value|
|
192
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
193
|
+
subject.should have_xpath(path, value)
|
194
|
+
end
|
195
|
+
end
|
133
196
|
end
|
134
197
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
serialize(:max_depth => 1, :attributes => :none)
|
198
|
+
context "rdf:Bag with rdf:_n" do
|
199
|
+
subject do
|
200
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
|
201
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
202
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
203
|
+
serialize(:max_depth => 1, :attributes => :none)
|
204
|
+
end
|
205
|
+
|
206
|
+
{
|
141
207
|
"/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
|
142
|
-
%(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) =>
|
143
|
-
%(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) =>
|
144
|
-
|
208
|
+
%(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
|
209
|
+
%(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
|
210
|
+
}.each do |path, value|
|
211
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
212
|
+
subject.should have_xpath(path, value)
|
213
|
+
end
|
214
|
+
end
|
145
215
|
end
|
146
216
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
serialize(:max_depth => 1, :attributes => :none)
|
217
|
+
context "rdf:Alt with rdf:_n" do
|
218
|
+
subject do
|
219
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
|
220
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
221
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
222
|
+
serialize(:max_depth => 1, :attributes => :none)
|
223
|
+
end
|
224
|
+
|
225
|
+
{
|
153
226
|
"/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
|
154
|
-
%(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) =>
|
155
|
-
%(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) =>
|
156
|
-
|
227
|
+
%(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
|
228
|
+
%(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
|
229
|
+
}.each do |path, value|
|
230
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
231
|
+
subject.should have_xpath(path, value)
|
232
|
+
end
|
233
|
+
end
|
157
234
|
end
|
158
235
|
end
|
159
236
|
|
160
237
|
describe "with lists" do
|
161
|
-
|
162
|
-
|
163
|
-
@
|
164
|
-
|
165
|
-
|
166
|
-
serialize({})
|
238
|
+
context "List rdf:first/rdf:rest" do
|
239
|
+
subject do
|
240
|
+
@graph = parse(%(
|
241
|
+
@prefix foo: <http://foo/> . foo:author foo:is (:Gregg :Barnum :Kellogg) .
|
242
|
+
), :base_uri => "http://foo/", :reader => RDF::N3::Reader)
|
243
|
+
serialize({})
|
244
|
+
end
|
245
|
+
|
246
|
+
{
|
167
247
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
|
168
248
|
"/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
|
169
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) =>
|
170
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) =>
|
171
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) =>
|
249
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => /Gregg/,
|
250
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => /Barnum/,
|
251
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => /Kellogg/,
|
172
252
|
%(//rdf:first) => false
|
173
|
-
|
253
|
+
}.each do |path, value|
|
254
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
255
|
+
subject.should have_xpath(path, value)
|
256
|
+
end
|
257
|
+
end
|
174
258
|
end
|
175
259
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
serialize(:max_depth => 1, :attributes => :none)
|
260
|
+
context "resource with rdf:_n in proper sequence" do
|
261
|
+
subject do
|
262
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
263
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
264
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
265
|
+
serialize(:max_depth => 1, :attributes => :none)
|
266
|
+
end
|
267
|
+
|
268
|
+
{
|
182
269
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
183
|
-
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) =>
|
184
|
-
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) =>
|
185
|
-
|
270
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
|
271
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /second/
|
272
|
+
}.each do |path, value|
|
273
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
274
|
+
subject.should have_xpath(path, value)
|
275
|
+
end
|
276
|
+
end
|
186
277
|
end
|
187
278
|
end
|
188
279
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
serialize(:attributes => :none)
|
280
|
+
context "with untyped literals" do
|
281
|
+
context ":attributes == :none" do
|
282
|
+
subject do
|
283
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
284
|
+
serialize(:attributes => :none)
|
285
|
+
end
|
286
|
+
|
287
|
+
{
|
194
288
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
195
|
-
"/rdf:RDF/rdf:Description/dc:title" => "
|
196
|
-
|
289
|
+
"/rdf:RDF/rdf:Description/dc:title/text()" => "foo"
|
290
|
+
}.each do |path, value|
|
291
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
292
|
+
subject.should have_xpath(path, value)
|
293
|
+
end
|
294
|
+
end
|
197
295
|
end
|
198
296
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
297
|
+
[:untyped, :typed].each do |opt|
|
298
|
+
context ":attributes == #{opt}" do
|
299
|
+
subject do
|
300
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
301
|
+
serialize(:attributes => opt)
|
302
|
+
end
|
303
|
+
|
304
|
+
{
|
305
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
306
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
307
|
+
}.each do |path, value|
|
308
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
309
|
+
subject.should have_xpath(path, value)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
211
313
|
end
|
212
314
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
serialize(:attributes => :untyped, :lang => "de")
|
315
|
+
context "untyped without lang if attribute lang set" do
|
316
|
+
subject do
|
317
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
318
|
+
serialize(:attributes => :untyped, :lang => "de")
|
319
|
+
end
|
320
|
+
|
321
|
+
{
|
217
322
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
218
323
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
219
|
-
|
324
|
+
}.each do |path, value|
|
325
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
326
|
+
subject.should have_xpath(path, value)
|
327
|
+
end
|
328
|
+
end
|
220
329
|
end
|
221
330
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
serialize(:attributes => :untyped, :lang => "de")
|
331
|
+
context "with language" do
|
332
|
+
context "property for title" do
|
333
|
+
subject do
|
334
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
335
|
+
serialize(:attributes => :untyped, :lang => "de")
|
336
|
+
end
|
337
|
+
|
338
|
+
{
|
227
339
|
"/rdf:RDF/@xml:lang" => "de",
|
228
340
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
229
341
|
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="en-us">foo</dc:title>)
|
230
|
-
|
342
|
+
}.each do |path, value|
|
343
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
344
|
+
subject.should have_xpath(path, value)
|
345
|
+
end
|
346
|
+
end
|
231
347
|
end
|
232
348
|
end
|
233
349
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
serialize(:attributes => :untyped, :lang => "de")
|
350
|
+
context "attribute if lang is default" do
|
351
|
+
subject do
|
352
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
353
|
+
serialize(:attributes => :untyped, :lang => "de")
|
354
|
+
end
|
355
|
+
|
356
|
+
{
|
238
357
|
"/rdf:RDF/@xml:lang" => "de",
|
239
358
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
240
359
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
241
|
-
|
360
|
+
}.each do |path, value|
|
361
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
362
|
+
subject.should have_xpath(path, value)
|
363
|
+
end
|
364
|
+
end
|
242
365
|
end
|
243
366
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
serialize(:attributes => :untyped)
|
367
|
+
context "untyped as property if lang set and no default" do
|
368
|
+
subject do
|
369
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
370
|
+
serialize(:attributes => :untyped)
|
371
|
+
end
|
372
|
+
|
373
|
+
{
|
248
374
|
"/rdf:RDF/@xml:lang" => false,
|
249
375
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
250
376
|
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
251
|
-
|
377
|
+
}.each do |path, value|
|
378
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
379
|
+
subject.should have_xpath(path, value)
|
380
|
+
end
|
381
|
+
end
|
252
382
|
end
|
253
383
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
serialize(:attributes => :untyped, :lang => "en-us")
|
384
|
+
context "untyped as property if lang set and not default" do
|
385
|
+
subject do
|
386
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
387
|
+
serialize(:attributes => :untyped, :lang => "en-us")
|
388
|
+
end
|
389
|
+
|
390
|
+
{
|
258
391
|
"/rdf:RDF/@xml:lang" => "en-us",
|
259
392
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
260
393
|
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
261
|
-
|
394
|
+
}.each do |path, value|
|
395
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
396
|
+
subject.should have_xpath(path, value)
|
397
|
+
end
|
398
|
+
end
|
262
399
|
end
|
263
400
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
serialize(:attributes => :untyped, :lang => "en-us")
|
401
|
+
context "multiple untyped attributes values through properties" do
|
402
|
+
subject do
|
403
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
404
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
405
|
+
serialize(:attributes => :untyped, :lang => "en-us")
|
406
|
+
end
|
407
|
+
|
408
|
+
{
|
269
409
|
"/rdf:RDF/@xml:lang" => "en-us",
|
270
410
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
271
|
-
"/rdf:RDF/rdf:Description/dc:title
|
272
|
-
|
273
|
-
|
411
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
412
|
+
}.each do |path, value|
|
413
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
414
|
+
subject.should have_xpath(path, value)
|
415
|
+
end
|
416
|
+
end
|
274
417
|
end
|
275
418
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
serialize(:attributes => :untyped)
|
419
|
+
context "typed node as element if :untyped" do
|
420
|
+
subject do
|
421
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
422
|
+
serialize(:attributes => :untyped)
|
423
|
+
end
|
424
|
+
|
425
|
+
{
|
280
426
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
281
427
|
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
|
282
|
-
|
283
|
-
|
284
|
-
|
428
|
+
}.each do |path, value|
|
429
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
430
|
+
subject.should have_xpath(path, value)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
context "typed node as attribute if :typed" do
|
436
|
+
subject do
|
437
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
438
|
+
serialize(:attributes => :typed)
|
439
|
+
end
|
440
|
+
|
441
|
+
{
|
285
442
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
286
443
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
287
|
-
|
288
|
-
|
444
|
+
}.each do |path, value|
|
445
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
446
|
+
subject.should have_xpath(path, value)
|
447
|
+
end
|
448
|
+
end
|
289
449
|
end
|
290
450
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
451
|
+
context "multiple typed values through properties" do
|
452
|
+
subject do
|
453
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
454
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
|
455
|
+
serialize(:attributes => :untyped)
|
456
|
+
end
|
457
|
+
|
458
|
+
{
|
459
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
460
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
|
461
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
|
462
|
+
}.each do |path, value|
|
463
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
464
|
+
subject.should have_xpath(path, value)
|
465
|
+
end
|
466
|
+
end
|
300
467
|
end
|
301
468
|
end
|
302
469
|
|
303
|
-
|
304
|
-
|
470
|
+
context "with namespace" do
|
471
|
+
before(:each) do
|
305
472
|
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
306
473
|
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
307
474
|
@graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
|
308
|
-
|
309
|
-
xml = serialize(:max_depth => 1, :attributes => :none,
|
310
|
-
:default_namespace => FOO.to_s,
|
311
|
-
:prefixes => {:foo => FOO.to_s})
|
312
|
-
xml.should =~ /<Release/
|
313
|
-
xml.should =~ /<pred/
|
314
|
-
doc = Nokogiri::XML.parse(xml)
|
315
|
-
doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
|
316
475
|
end
|
317
476
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
477
|
+
context "default namespace" do
|
478
|
+
subject do
|
479
|
+
serialize(:max_depth => 1, :attributes => :none,
|
480
|
+
:default_namespace => FOO.to_s,
|
481
|
+
:prefixes => {:foo => FOO.to_s})
|
482
|
+
end
|
483
|
+
|
484
|
+
{
|
485
|
+
"/rdf:RDF/foo:Release/foo:pred/@rdf:resource" => FOO.obj.to_s,
|
486
|
+
}.each do |path, value|
|
487
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
488
|
+
subject.should have_xpath(path, value, {"foo" => FOO.to_s})
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
specify { subject.should =~ /<Release/ }
|
493
|
+
specify { subject.should =~ /<pred/ }
|
494
|
+
end
|
495
|
+
|
496
|
+
context "nil namespace" do
|
497
|
+
subject do
|
498
|
+
serialize(:max_depth => 1, :attributes => :none,
|
499
|
+
:prefixes => {nil => FOO.to_s, :foo => FOO.to_s})
|
500
|
+
end
|
501
|
+
|
502
|
+
{
|
503
|
+
"/rdf:RDF/foo:Release/foo:pred/@rdf:resource" => FOO.obj.to_s,
|
504
|
+
}.each do |path, value|
|
505
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
506
|
+
subject.should have_xpath(path, value, {"foo" => FOO.to_s})
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
specify { subject.should =~ /<Release/ }
|
511
|
+
specify { subject.should =~ /<pred/ }
|
329
512
|
end
|
330
513
|
end
|
331
514
|
|
332
515
|
describe "with base" do
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
serialize(:attributes => :untyped, :base_uri => "http://release/")
|
516
|
+
context "relative about URI" do
|
517
|
+
subject do
|
518
|
+
@graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
|
519
|
+
serialize(:attributes => :untyped, :base_uri => "http://release/")
|
520
|
+
end
|
521
|
+
|
522
|
+
{
|
337
523
|
"/rdf:RDF/rdf:Description/@rdf:about" => "a",
|
338
524
|
"/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
|
339
|
-
|
525
|
+
}.each do |path, value|
|
526
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
527
|
+
subject.should have_xpath(path, value)
|
528
|
+
end
|
529
|
+
end
|
340
530
|
end
|
341
531
|
end
|
342
532
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
serialize(:attributes => :untyped, :
|
533
|
+
context "with bnodes" do
|
534
|
+
context "no nodeID attribute unless node is referenced as an object" do
|
535
|
+
subject do
|
536
|
+
@graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
|
537
|
+
serialize(:attributes => :untyped, :base_uri => "http://release/")
|
538
|
+
end
|
539
|
+
|
540
|
+
{
|
348
541
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
349
542
|
"/rdf:RDF/rdf:Description/@rdf:nodeID" => false
|
350
|
-
|
543
|
+
}.each do |path, value|
|
544
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
545
|
+
subject.should have_xpath(path, value)
|
546
|
+
end
|
547
|
+
end
|
351
548
|
end
|
352
549
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
serialize(:attributes => :untyped, :
|
550
|
+
context "nodeID attribute if node is referenced as an object" do
|
551
|
+
subject do
|
552
|
+
bn = RDF::Node.new("a")
|
553
|
+
@graph << [bn, RDF::DC.title, "foo"]
|
554
|
+
@graph << [bn, RDF::OWL.equals, bn]
|
555
|
+
serialize(:attributes => :untyped, :base_uri => "http://release/")
|
556
|
+
end
|
557
|
+
|
558
|
+
{
|
359
559
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
360
560
|
"/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
|
361
561
|
"/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
|
362
|
-
|
562
|
+
}.each do |path, value|
|
563
|
+
it "returns #{value.inspect} for xpath #{path}" do
|
564
|
+
subject.should have_xpath(path, value)
|
565
|
+
end
|
566
|
+
end
|
363
567
|
end
|
364
568
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
569
|
+
context "rdf:nodeID for forced BNode generation" do
|
570
|
+
subject do
|
571
|
+
bn = RDF::Node.new("a")
|
572
|
+
@graph = parse(%(
|
573
|
+
@prefix : <http://example/> .
|
574
|
+
_:bar :list (_:foo (_:foo)).
|
575
|
+
))
|
576
|
+
serialize
|
577
|
+
end
|
370
578
|
|
371
|
-
|
579
|
+
specify { parse(subject).should be_equivalent_graph(@graph, :trace => @debug.join("\n")) }
|
372
580
|
end
|
373
581
|
|
374
582
|
it "should replicate rdfcore/rdfms-seq-representation" do
|
375
583
|
@graph = parse(%(
|
376
584
|
<http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
|
377
585
|
), :reader => RDF::N3::Reader)
|
378
|
-
|
586
|
+
parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
|
379
587
|
end
|
380
588
|
|
381
589
|
it "should not generate extraneous BNode" do
|
@@ -391,7 +599,7 @@ describe "RDF::RDFXML::Writer" do
|
|
391
599
|
[ a <http://www.w3.org/2002/07/owl#Class>;
|
392
600
|
<http://www.w3.org/2002/07/owl#intersectionOf> (<a> <b>)] .
|
393
601
|
), :reader => RDF::N3::Reader)
|
394
|
-
|
602
|
+
parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
|
395
603
|
end
|
396
604
|
end
|
397
605
|
|
@@ -467,7 +675,7 @@ describe "RDF::RDFXML::Writer" do
|
|
467
675
|
|
468
676
|
require 'rdf/n3'
|
469
677
|
def parse(input, options = {})
|
470
|
-
reader_class = options.fetch(:reader, detect_format(input))
|
678
|
+
reader_class = options.fetch(:reader, RDF::Reader.for(detect_format(input)))
|
471
679
|
|
472
680
|
graph = RDF::Graph.new
|
473
681
|
reader_class.new(input, options).each do |statement|
|
@@ -489,14 +697,16 @@ describe "RDF::RDFXML::Writer" do
|
|
489
697
|
end
|
490
698
|
|
491
699
|
describe "#get_qname" do
|
492
|
-
subject { RDF::RDFXML::Writer.new }
|
493
|
-
|
700
|
+
subject { RDF::RDFXML::Writer.new(StringIO.new, :prefixes => {:foo => "http://foo/"}) }
|
701
|
+
context "with undefined predicate URIs" do
|
494
702
|
{
|
495
|
-
"http://a/b"
|
496
|
-
"dc:title"
|
703
|
+
"http://a/b" => "ns0:b",
|
704
|
+
"dc:title" => "ns0:title",
|
705
|
+
"http://a/%b" => "ns0:b",
|
706
|
+
"http://foo/%bar" => "ns0:bar"
|
497
707
|
}.each_pair do |uri, qname|
|
498
708
|
it "returns #{qname.inspect} given #{uri}" do
|
499
|
-
subject.get_qname(uri).should == qname
|
709
|
+
subject.get_qname(RDF::URI(uri)).should == qname
|
500
710
|
end
|
501
711
|
end
|
502
712
|
end
|