rdf-rdfxml 0.0.2 → 0.0.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/History.txt +20 -0
- data/VERSION +1 -1
- data/lib/rdf/rdfxml/format.rb +2 -2
- data/lib/rdf/rdfxml/patches/graph_properties.rb +34 -0
- data/lib/rdf/rdfxml/patches/literal_hacks.rb +66 -0
- data/lib/rdf/rdfxml/patches/qname_hacks.rb +57 -0
- data/lib/rdf/rdfxml/patches/seq.rb +34 -0
- data/lib/rdf/rdfxml/patches/uri_hacks.rb +19 -0
- data/lib/rdf/rdfxml/reader.rb +10 -7
- data/lib/rdf/rdfxml/writer.rb +215 -114
- data/lib/rdf/rdfxml.rb +4 -0
- data/rdf-rdfxml.gemspec +17 -4
- data/spec/format_spec.rb +1 -1
- data/spec/graph_spec.rb +74 -0
- data/spec/literal_spec.rb +86 -0
- data/spec/rdf_escape_spec.rb +36 -0
- data/spec/rdf_helper.rb +2 -0
- data/spec/reader_spec.rb +7 -3
- data/spec/uri_spec.rb +61 -0
- data/spec/{xml_serializer_spec.rb → writer_spec.rb} +114 -110
- metadata +19 -6
@@ -1,16 +1,16 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
2
|
+
autoload :CGI, 'cgi'
|
3
3
|
|
4
|
-
|
4
|
+
class FOO < RDF::Vocabulary("http://foo/"); end
|
5
5
|
|
6
|
-
describe "
|
6
|
+
describe "RDF::RDFXML::Writer" do
|
7
7
|
before(:each) do
|
8
|
-
@graph = Graph.new
|
8
|
+
@graph = RDF::Graph.new
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "with types" do
|
12
12
|
it "should serialize resource without type" do
|
13
|
-
@graph.
|
13
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
14
14
|
check_xpaths(
|
15
15
|
serialize(:max_depth => 1, :attributes => :untyped),
|
16
16
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
@@ -19,8 +19,8 @@ describe "XML Serializer" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should serialize resource with type" do
|
22
|
-
@graph.
|
23
|
-
@graph.
|
22
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
23
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
24
24
|
check_xpaths(
|
25
25
|
serialize(:max_depth => 1, :attributes => :untyped),
|
26
26
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
@@ -30,51 +30,51 @@ describe "XML Serializer" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should serialize resource with two types as attribute" do
|
33
|
-
@graph.
|
34
|
-
@graph.
|
35
|
-
@graph.
|
33
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
34
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
35
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
36
36
|
check_xpaths(
|
37
37
|
serialize(:max_depth => 1, :attributes => :untyped),
|
38
38
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
39
39
|
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
40
|
-
"/rdf:RDF/foo:Release/@rdf:type" =>
|
40
|
+
"/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should serialize resource with two types as element" do
|
45
|
-
@graph.
|
46
|
-
@graph.
|
47
|
-
@graph.
|
45
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
46
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
47
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
48
48
|
check_xpaths(
|
49
49
|
serialize(:max_depth => 1, :attributes => :none),
|
50
50
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
51
51
|
"/rdf:RDF/foo:Release/dc:title" => true,
|
52
|
-
"/rdf:RDF/foo:Release/rdf:type" => %(<rdf:type rdf:resource="#{
|
52
|
+
"/rdf:RDF/foo:Release/rdf:type" => %(<rdf:type rdf:resource="#{FOO.XtraRelease}"/>)
|
53
53
|
)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should serialize resource with three types as element" do
|
57
|
-
@graph.
|
58
|
-
@graph.
|
59
|
-
@graph.
|
60
|
-
@graph.
|
57
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
58
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
59
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
|
60
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
61
61
|
check_xpaths(
|
62
62
|
serialize(:max_depth => 1, :attributes => :typed),
|
63
63
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
64
64
|
"/rdf:RDF/foo:Release/@dc:title" => true,
|
65
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{
|
66
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{
|
65
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
|
66
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
|
67
67
|
)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "with children" do
|
72
72
|
it "should serialize referenced resource by ref" do
|
73
|
-
@graph.
|
74
|
-
@graph.
|
75
|
-
@graph.
|
76
|
-
@graph.
|
77
|
-
@graph.
|
73
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
74
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
75
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
76
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
77
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
78
78
|
check_xpaths(
|
79
79
|
serialize(:max_depth => 1, :attributes => :untyped),
|
80
80
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
@@ -86,11 +86,11 @@ describe "XML Serializer" do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should serialize referenced resource by inclusion" do
|
89
|
-
@graph.
|
90
|
-
@graph.
|
91
|
-
@graph.
|
92
|
-
@graph.
|
93
|
-
@graph.
|
89
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
90
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
91
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
92
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
93
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
94
94
|
check_xpaths(
|
95
95
|
serialize(:max_depth => 3, :attributes => :untyped),
|
96
96
|
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
@@ -102,9 +102,9 @@ describe "XML Serializer" do
|
|
102
102
|
|
103
103
|
describe "with sequences" do
|
104
104
|
it "should serialize rdf:Seq with rdf:li" do
|
105
|
-
@graph.
|
106
|
-
@graph.
|
107
|
-
@graph.
|
105
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
106
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
107
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
108
108
|
check_xpaths(
|
109
109
|
serialize(:max_depth => 1, :attributes => :untyped),
|
110
110
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
@@ -114,9 +114,9 @@ describe "XML Serializer" do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should serialize rdf:Seq with multiple rdf:li in proper sequence" do
|
117
|
-
@graph.
|
118
|
-
@graph.
|
119
|
-
@graph.
|
117
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
118
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
119
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
120
120
|
check_xpaths(
|
121
121
|
serialize(:max_depth => 1, :attributes => :untyped),
|
122
122
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
@@ -126,9 +126,9 @@ describe "XML Serializer" do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should serialize rdf:Bag with multiple rdf:li" do
|
129
|
-
@graph.
|
130
|
-
@graph.
|
131
|
-
@graph.
|
129
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
|
130
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
131
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
132
132
|
check_xpaths(
|
133
133
|
serialize(:max_depth => 1, :attributes => :untyped),
|
134
134
|
"/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
|
@@ -138,9 +138,9 @@ describe "XML Serializer" do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should serialize rdf:Alt with multiple rdf:li" do
|
141
|
-
@graph.
|
142
|
-
@graph.
|
143
|
-
@graph.
|
141
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
|
142
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
143
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
144
144
|
check_xpaths(
|
145
145
|
serialize(:max_depth => 1, :attributes => :untyped),
|
146
146
|
"/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
|
@@ -151,23 +151,23 @@ describe "XML Serializer" do
|
|
151
151
|
end
|
152
152
|
|
153
153
|
describe "with lists" do
|
154
|
-
it "should serialize List rdf:first/rdf:rest" do
|
155
|
-
@graph.parse(%(@prefix foo: <http://foo/> . foo:author foo:is (Gregg Barnum Kellogg).), "http://foo/", :type => :ttl)
|
156
|
-
check_xpaths(
|
157
|
-
serialize({}),
|
158
|
-
"/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
|
159
|
-
"/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
|
160
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
|
161
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
|
162
|
-
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
|
163
|
-
%(//rdf:first) => false
|
164
|
-
)
|
165
|
-
end
|
154
|
+
# it "should serialize List rdf:first/rdf:rest" do
|
155
|
+
# @graph.parse(%(@prefix foo: <http://foo/> . foo:author foo:is (Gregg Barnum Kellogg).), "http://foo/", :type => :ttl)
|
156
|
+
# check_xpaths(
|
157
|
+
# serialize({}),
|
158
|
+
# "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
|
159
|
+
# "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
|
160
|
+
# %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
|
161
|
+
# %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
|
162
|
+
# %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
|
163
|
+
# %(//rdf:first) => false
|
164
|
+
# )
|
165
|
+
# end
|
166
166
|
|
167
167
|
it "should serialize resource with multiple rdf:li in proper sequence" do
|
168
|
-
@graph.
|
169
|
-
@graph.
|
170
|
-
@graph.
|
168
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
169
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
170
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
171
171
|
check_xpaths(
|
172
172
|
serialize(:max_depth => 1, :attributes => :untyped),
|
173
173
|
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
@@ -179,7 +179,7 @@ describe "XML Serializer" do
|
|
179
179
|
|
180
180
|
describe "with untyped literals" do
|
181
181
|
it "should seralize as element if :attributes == :none" do
|
182
|
-
@graph.
|
182
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
183
183
|
check_xpaths(
|
184
184
|
serialize(:attributes => :none),
|
185
185
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
@@ -188,7 +188,7 @@ describe "XML Serializer" do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should seralize as attribute if :attributes == :untyped or :typed" do
|
191
|
-
@graph.
|
191
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
192
192
|
check_xpaths(
|
193
193
|
serialize(:attributes => :untyped),
|
194
194
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
@@ -201,8 +201,8 @@ describe "XML Serializer" do
|
|
201
201
|
)
|
202
202
|
end
|
203
203
|
|
204
|
-
it "should output untyped without lang
|
205
|
-
@graph.
|
204
|
+
it "should output untyped without lang if attribute lang set" do
|
205
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
206
206
|
check_xpaths(
|
207
207
|
serialize(:attributes => :untyped, :lang => "de"),
|
208
208
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
@@ -212,7 +212,7 @@ describe "XML Serializer" do
|
|
212
212
|
|
213
213
|
describe "with language" do
|
214
214
|
it "should output property for title with language" do
|
215
|
-
@graph.
|
215
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
216
216
|
check_xpaths(
|
217
217
|
serialize(:attributes => :untyped, :lang => "de"),
|
218
218
|
"/rdf:RDF/@xml:lang" => "de",
|
@@ -223,7 +223,7 @@ describe "XML Serializer" do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should output untyped as attribute if lang is default" do
|
226
|
-
@graph.
|
226
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
227
227
|
check_xpaths(
|
228
228
|
serialize(:attributes => :untyped, :lang => "de"),
|
229
229
|
"/rdf:RDF/@xml:lang" => "de",
|
@@ -233,7 +233,7 @@ describe "XML Serializer" do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "should output untyped as property if lang set and no default" do
|
236
|
-
@graph.
|
236
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
237
237
|
check_xpaths(
|
238
238
|
serialize(:attributes => :untyped),
|
239
239
|
"/rdf:RDF/@xml:lang" => false,
|
@@ -243,7 +243,7 @@ describe "XML Serializer" do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should output untyped as property if lang set and not default" do
|
246
|
-
@graph.
|
246
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
247
247
|
check_xpaths(
|
248
248
|
serialize(:attributes => :untyped, :lang => "en-us"),
|
249
249
|
"/rdf:RDF/@xml:lang" => "en-us",
|
@@ -253,8 +253,8 @@ describe "XML Serializer" do
|
|
253
253
|
end
|
254
254
|
|
255
255
|
it "should output multiple untyped attributes values through properties" do
|
256
|
-
@graph.
|
257
|
-
@graph.
|
256
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
257
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
258
258
|
check_xpaths(
|
259
259
|
serialize(:attributes => :untyped, :lang => "en-us"),
|
260
260
|
"/rdf:RDF/@xml:lang" => "en-us",
|
@@ -265,11 +265,11 @@ describe "XML Serializer" do
|
|
265
265
|
end
|
266
266
|
|
267
267
|
it "should output typed node as attribute" do
|
268
|
-
@graph.
|
268
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
269
269
|
check_xpaths(
|
270
270
|
serialize(:attributes => :untyped),
|
271
271
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
272
|
-
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{
|
272
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
|
273
273
|
)
|
274
274
|
check_xpaths(
|
275
275
|
serialize(:attributes => :typed),
|
@@ -279,48 +279,46 @@ describe "XML Serializer" do
|
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should output multiple typed values through properties" do
|
282
|
-
@graph.
|
283
|
-
@graph.
|
282
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
283
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
|
284
284
|
check_xpaths(
|
285
285
|
serialize(:attributes => :untyped),
|
286
286
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
287
|
-
"/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{
|
288
|
-
"/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{
|
287
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
|
288
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
|
289
289
|
)
|
290
290
|
end
|
291
291
|
end
|
292
|
-
|
292
|
+
|
293
|
+
# FIXME
|
293
294
|
describe "with default namespace" do
|
294
295
|
it "should serialize with default namespace" do
|
295
|
-
@graph.
|
296
|
-
@graph.
|
297
|
-
@graph.
|
298
|
-
@graph.bind(Namespace.new(FOO_NS.uri, ""))
|
296
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
297
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
298
|
+
@graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
|
299
299
|
|
300
|
-
|
301
|
-
xml = serialize(:max_depth => 1, :attributes => :untyped)
|
302
|
-
#puts xml
|
300
|
+
xml = serialize(:max_depth => 1, :attributes => :untyped, :default_namespace => FOO.to_s)
|
303
301
|
xml.should =~ /<Release/
|
304
302
|
xml.should =~ /<pred/
|
305
303
|
doc = Nokogiri::XML.parse(xml)
|
306
|
-
doc.at_xpath("/rdf:RDF
|
304
|
+
doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
|
307
305
|
end
|
308
306
|
end
|
309
307
|
|
310
308
|
describe "with base" do
|
311
309
|
it "should generate relative about URI" do
|
312
|
-
@graph.
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
310
|
+
@graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
|
311
|
+
check_xpaths(
|
312
|
+
serialize(:attributes => :untyped, :base_uri => "http://release/"),
|
313
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "a",
|
314
|
+
"/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
|
315
|
+
)
|
318
316
|
end
|
319
317
|
end
|
320
318
|
|
321
319
|
describe "with bnodes" do
|
322
320
|
it "should not generate nodeID attribute unless node is referenced as an object" do
|
323
|
-
@graph.
|
321
|
+
@graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
|
324
322
|
check_xpaths(
|
325
323
|
serialize(:attributes => :untyped, :base => "http://release/"),
|
326
324
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
@@ -329,34 +327,37 @@ describe "XML Serializer" do
|
|
329
327
|
end
|
330
328
|
|
331
329
|
it "should generate a nodeID attribute if node is referenced as an object" do
|
332
|
-
bn =
|
333
|
-
@graph
|
334
|
-
@graph
|
330
|
+
bn = RDF::Node.new("a")
|
331
|
+
@graph << [bn, RDF::DC.title, "foo"]
|
332
|
+
@graph << [bn, RDF::OWL.equals, bn]
|
335
333
|
check_xpaths(
|
336
334
|
serialize(:attributes => :untyped, :base => "http://release/"),
|
337
335
|
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
338
|
-
"/rdf:RDF/rdf:Description/@rdf:nodeID" => /
|
339
|
-
"/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /
|
336
|
+
"/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
|
337
|
+
"/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
|
340
338
|
)
|
341
339
|
end
|
342
340
|
|
343
341
|
it "should replicate rdfcore/rdfms-seq-representation" do
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
342
|
+
begin
|
343
|
+
@graph.parse(%(
|
344
|
+
<http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
|
345
|
+
))
|
346
|
+
graph2 = Graph.new
|
347
|
+
graph2.parse(serialize(:format => :xml)).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
|
348
|
+
rescue
|
349
|
+
pending("Requires Turtle reader")
|
350
|
+
end
|
349
351
|
end
|
350
352
|
end
|
351
353
|
|
352
354
|
def check_xpaths(doc, paths)
|
353
|
-
puts doc if $DEBUG || $verbose
|
355
|
+
puts doc.to_s if $DEBUG || $verbose
|
354
356
|
doc = Nokogiri::XML.parse(doc)
|
355
|
-
#puts "doc: #{doc.to_s}"
|
356
357
|
doc.should be_a(Nokogiri::XML::Document)
|
358
|
+
doc.root.should be_a(Nokogiri::XML::Element)
|
357
359
|
paths.each_pair do |path, value|
|
358
|
-
|
359
|
-
puts doc.root.at_xpath(path, @namespaces).inspect if $DEBUG
|
360
|
+
@debug << doc.root.at_xpath(path, @namespaces).to_s if $DEBUG
|
360
361
|
case value
|
361
362
|
when false
|
362
363
|
doc.root.at_xpath(path, doc.namespaces).should be_nil
|
@@ -372,15 +373,18 @@ describe "XML Serializer" do
|
|
372
373
|
end
|
373
374
|
|
374
375
|
# Parse generated graph and compare to source
|
375
|
-
Graph.new
|
376
|
-
|
376
|
+
#graph = RDF::Graph.new
|
377
|
+
#RDF::RDFXML::Reader.new(doc, :base_uri => "http://release/", :format => :rdf).each {|st| graph << st}
|
378
|
+
#graph.should be_equivalent_graph(@graph, :about => "http://release/", :trace => @debug.join("\n"))
|
377
379
|
end
|
378
380
|
|
379
381
|
# Serialize ntstr to a string and compare against regexps
|
380
|
-
def serialize(options)
|
381
|
-
|
382
|
-
result =
|
383
|
-
|
382
|
+
def serialize(options = {})
|
383
|
+
@debug = []
|
384
|
+
result = RDF::RDFXML::Writer.buffer(options.merge(:debug => @debug)) do |writer|
|
385
|
+
writer.write_graph(@graph)
|
386
|
+
end
|
387
|
+
puts @debug.join("\n") if $DEBUG
|
384
388
|
result
|
385
389
|
end
|
386
390
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-rdfxml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gregg Kellogg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-12 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -117,8 +117,13 @@ files:
|
|
117
117
|
- lib/rdf/rdfxml.rb
|
118
118
|
- lib/rdf/rdfxml/format.rb
|
119
119
|
- lib/rdf/rdfxml/patches/array_hacks.rb
|
120
|
+
- lib/rdf/rdfxml/patches/graph_properties.rb
|
121
|
+
- lib/rdf/rdfxml/patches/literal_hacks.rb
|
120
122
|
- lib/rdf/rdfxml/patches/nokogiri_hacks.rb
|
123
|
+
- lib/rdf/rdfxml/patches/qname_hacks.rb
|
121
124
|
- lib/rdf/rdfxml/patches/rdf_escape.rb
|
125
|
+
- lib/rdf/rdfxml/patches/seq.rb
|
126
|
+
- lib/rdf/rdfxml/patches/uri_hacks.rb
|
122
127
|
- lib/rdf/rdfxml/reader.rb
|
123
128
|
- lib/rdf/rdfxml/version.rb
|
124
129
|
- lib/rdf/rdfxml/vocab.rb
|
@@ -126,7 +131,10 @@ files:
|
|
126
131
|
- rdf-rdfxml.gemspec
|
127
132
|
- script/console
|
128
133
|
- spec/format_spec.rb
|
134
|
+
- spec/graph_spec.rb
|
135
|
+
- spec/literal_spec.rb
|
129
136
|
- spec/matchers.rb
|
137
|
+
- spec/rdf_escape_spec.rb
|
130
138
|
- spec/rdf_helper.rb
|
131
139
|
- spec/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.nt
|
132
140
|
- spec/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.rdf
|
@@ -490,7 +498,8 @@ files:
|
|
490
498
|
- spec/reader_spec.rb
|
491
499
|
- spec/spec.opts
|
492
500
|
- spec/spec_helper.rb
|
493
|
-
- spec/
|
501
|
+
- spec/uri_spec.rb
|
502
|
+
- spec/writer_spec.rb
|
494
503
|
has_rdoc: true
|
495
504
|
homepage: http://github.com/gkellogg/rdf-rdfxml
|
496
505
|
licenses: []
|
@@ -527,8 +536,12 @@ specification_version: 3
|
|
527
536
|
summary: RDF/XML reader/writer for RDF.rb.
|
528
537
|
test_files:
|
529
538
|
- spec/format_spec.rb
|
539
|
+
- spec/graph_spec.rb
|
540
|
+
- spec/literal_spec.rb
|
530
541
|
- spec/matchers.rb
|
542
|
+
- spec/rdf_escape_spec.rb
|
531
543
|
- spec/rdf_helper.rb
|
532
544
|
- spec/reader_spec.rb
|
533
545
|
- spec/spec_helper.rb
|
534
|
-
- spec/
|
546
|
+
- spec/uri_spec.rb
|
547
|
+
- spec/writer_spec.rb
|