rdf-rdfxml 0.2.3 → 0.3.0
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 -0
- data/{History.txt → History.rdoc} +21 -0
- data/README.rdoc +11 -12
- data/Rakefile +11 -19
- data/VERSION +1 -1
- data/lib/rdf/rdfxml.rb +3 -2
- data/lib/rdf/rdfxml/patches/literal_hacks.rb +15 -17
- data/lib/rdf/rdfxml/reader.rb +115 -79
- data/lib/rdf/rdfxml/version.rb +4 -7
- data/lib/rdf/rdfxml/writer.rb +239 -190
- data/rdf-rdfxml.gemspec +14 -20
- data/script/parse +16 -10
- data/script/tc +10 -9
- data/spec/graph_spec.rb +0 -16
- data/spec/literal_spec.rb +2 -3
- data/spec/rdf_helper.rb +6 -6
- data/spec/reader_spec.rb +17 -17
- data/spec/spec_helper.rb +11 -4
- data/spec/writer_spec.rb +384 -331
- metadata +22 -18
- data/lib/rdf/rdfxml/patches/qname_hacks.rb +0 -57
- data/lib/rdf/rdfxml/patches/seq.rb +0 -34
- data/lib/rdf/rdfxml/patches/uri_hacks.rb +0 -24
- data/spec/uri_spec.rb +0 -115
data/spec/writer_spec.rb
CHANGED
@@ -13,389 +13,442 @@ describe "RDF::RDFXML::Writer" do
|
|
13
13
|
|
14
14
|
it_should_behave_like RDF_Writer
|
15
15
|
|
16
|
-
describe "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
describe "#buffer" do
|
17
|
+
describe "with types" do
|
18
|
+
it "should serialize resource without type" do
|
19
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
20
|
+
check_xpaths(
|
21
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
22
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
23
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
24
|
+
)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
it "should serialize resource with type" do
|
28
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
29
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
30
|
+
check_xpaths(
|
31
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
32
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
33
|
+
"/rdf:RDF/foo:Release/@dc:title" =>"foo",
|
34
|
+
"/rdf:RDF/foo:Release/rdf:type" => ""
|
35
|
+
)
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
it "should serialize resource with two types as attribute" do
|
39
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
40
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
41
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
42
|
+
check_xpaths(
|
43
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
44
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
45
|
+
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
46
|
+
"/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
|
47
|
+
)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
it "should serialize resource with two types as element" do
|
51
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
52
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
53
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
54
|
+
check_xpaths(
|
55
|
+
serialize(:max_depth => 1, :attributes => :none),
|
56
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
57
|
+
"/rdf:RDF/foo:Release/dc:title" => true,
|
58
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
|
59
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.Release}"]) => false
|
60
|
+
)
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
check_xpaths(
|
67
|
-
serialize(:max_depth => 1, :attributes => :typed),
|
68
|
-
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
69
|
-
"/rdf:RDF/foo:Release/@dc:title" => true,
|
70
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
|
71
|
-
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "with children" do
|
77
|
-
it "should serialize referenced resource by ref" do
|
78
|
-
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
79
|
-
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
80
|
-
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
81
|
-
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
82
|
-
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
63
|
+
it "should serialize resource with three types as element" do
|
64
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
65
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
|
66
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
|
67
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
83
68
|
check_xpaths(
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
69
|
+
serialize(:max_depth => 1, :attributes => :typed),
|
70
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
71
|
+
"/rdf:RDF/foo:Release/@dc:title" => true,
|
72
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
|
73
|
+
%(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
|
74
|
+
)
|
75
|
+
end
|
91
76
|
end
|
92
77
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
78
|
+
describe "with children" do
|
79
|
+
it "should serialize referenced resource by ref" do
|
80
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
81
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
82
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
83
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
84
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
85
|
+
check_xpaths(
|
86
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
87
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
88
|
+
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
89
|
+
"/rdf:RDF/foo:Release/foo:releaseContributor/@rdf:resource" => "http://release/contributor",
|
90
|
+
"/rdf:RDF/foo:Contributor/@rdf:about" => "http://release/contributor",
|
91
|
+
"/rdf:RDF/foo:Contributor/@dc:title" => "bar"
|
92
|
+
)
|
93
|
+
end
|
107
94
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
95
|
+
it "should serialize referenced resource by inclusion" do
|
96
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
97
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
98
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
|
99
|
+
@graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
|
100
|
+
@graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
|
101
|
+
check_xpaths(
|
102
|
+
serialize(:max_depth => 3, :attributes => :untyped),
|
103
|
+
"/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
|
104
|
+
"/rdf:RDF/foo:Release/@dc:title" => "foo",
|
105
|
+
"/rdf:RDF/foo:Release/foo:releaseContributor/foo:Contributor/@rdf:about" => "http://release/contributor"
|
106
|
+
)
|
107
|
+
end
|
119
108
|
end
|
120
109
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
110
|
+
describe "with sequences" do
|
111
|
+
it "should serialize rdf:Seq with rdf:_n" do
|
112
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
113
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
114
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
115
|
+
check_xpaths(
|
116
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
117
|
+
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
118
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
|
119
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should serialize rdf:Seq with rdf:_n in proper sequence" do
|
124
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
125
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
126
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
127
|
+
check_xpaths(
|
128
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
129
|
+
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
130
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
|
131
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
|
132
|
+
)
|
133
|
+
end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
it "should serialize rdf:Bag with rdf:_n" do
|
136
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
|
137
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
138
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
139
|
+
check_xpaths(
|
140
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
141
|
+
"/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
|
142
|
+
%(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) => true,
|
143
|
+
%(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) => true
|
144
|
+
)
|
145
|
+
end
|
144
146
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
147
|
+
it "should serialize rdf:Alt with multiple rdf:_2" do
|
148
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
|
149
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
150
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
151
|
+
check_xpaths(
|
152
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
153
|
+
"/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
|
154
|
+
%(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) => true,
|
155
|
+
%(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) => true
|
156
|
+
)
|
157
|
+
end
|
155
158
|
end
|
156
|
-
end
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
160
|
+
describe "with lists" do
|
161
|
+
it "should serialize List rdf:first/rdf:rest" do
|
162
|
+
@graph = parse(%(
|
163
|
+
@prefix foo: <http://foo/> . foo:author foo:is (:Gregg :Barnum :Kellogg) .
|
164
|
+
), :base_uri => "http://foo/", :reader => RDF::N3::Reader)
|
165
|
+
check_xpaths(
|
166
|
+
serialize({}),
|
167
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
|
168
|
+
"/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
|
169
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
|
170
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
|
171
|
+
%(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
|
172
|
+
%(//rdf:first) => false
|
173
|
+
)
|
174
|
+
end
|
171
175
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
it "should serialize resource with rdf:_n in proper sequence" do
|
177
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
|
178
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
|
179
|
+
@graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
|
180
|
+
check_xpaths(
|
181
|
+
serialize(:max_depth => 1, :attributes => :untyped),
|
182
|
+
"/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
|
183
|
+
%(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
|
184
|
+
%(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
|
185
|
+
)
|
186
|
+
end
|
182
187
|
end
|
183
|
-
end
|
184
188
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
189
|
+
describe "with untyped literals" do
|
190
|
+
it "should seralize as element if :attributes == :none" do
|
191
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
192
|
+
check_xpaths(
|
193
|
+
serialize(:attributes => :none),
|
194
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
195
|
+
"/rdf:RDF/rdf:Description/dc:title" => "<dc:title>foo</dc:title>"
|
196
|
+
)
|
197
|
+
end
|
194
198
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
199
|
+
it "should seralize as attribute if :attributes == :untyped or :typed" do
|
200
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
201
|
+
check_xpaths(
|
202
|
+
serialize(:attributes => :untyped),
|
203
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
204
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
205
|
+
)
|
206
|
+
check_xpaths(
|
207
|
+
serialize(:attributes => :typed),
|
208
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
209
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
210
|
+
)
|
211
|
+
end
|
208
212
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
it "should output untyped without lang if attribute lang set" do
|
214
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
215
|
+
check_xpaths(
|
216
|
+
serialize(:attributes => :untyped, :lang => "de"),
|
217
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
218
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
219
|
+
)
|
220
|
+
end
|
217
221
|
|
218
|
-
|
219
|
-
|
220
|
-
|
222
|
+
describe "with language" do
|
223
|
+
it "should output property for title with language" do
|
224
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
225
|
+
check_xpaths(
|
226
|
+
serialize(:attributes => :untyped, :lang => "de"),
|
227
|
+
"/rdf:RDF/@xml:lang" => "de",
|
228
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
229
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="en-us">foo</dc:title>)
|
230
|
+
)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should output untyped as attribute if lang is default" do
|
235
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
221
236
|
check_xpaths(
|
222
237
|
serialize(:attributes => :untyped, :lang => "de"),
|
223
238
|
"/rdf:RDF/@xml:lang" => "de",
|
224
239
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
225
|
-
"/rdf:RDF/rdf:Description
|
240
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
226
241
|
)
|
227
242
|
end
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should output untyped as attribute if lang is default" do
|
231
|
-
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
232
|
-
check_xpaths(
|
233
|
-
serialize(:attributes => :untyped, :lang => "de"),
|
234
|
-
"/rdf:RDF/@xml:lang" => "de",
|
235
|
-
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
236
|
-
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
237
|
-
)
|
238
|
-
end
|
239
243
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
it "should output untyped as property if lang set and not default" do
|
251
|
-
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
252
|
-
check_xpaths(
|
253
|
-
serialize(:attributes => :untyped, :lang => "en-us"),
|
254
|
-
"/rdf:RDF/@xml:lang" => "en-us",
|
255
|
-
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
256
|
-
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
257
|
-
)
|
258
|
-
end
|
244
|
+
it "should output untyped as property if lang set and no default" do
|
245
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
246
|
+
check_xpaths(
|
247
|
+
serialize(:attributes => :untyped),
|
248
|
+
"/rdf:RDF/@xml:lang" => false,
|
249
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
250
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
251
|
+
)
|
252
|
+
end
|
259
253
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
)
|
270
|
-
end
|
254
|
+
it "should output untyped as property if lang set and not default" do
|
255
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
256
|
+
check_xpaths(
|
257
|
+
serialize(:attributes => :untyped, :lang => "en-us"),
|
258
|
+
"/rdf:RDF/@xml:lang" => "en-us",
|
259
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
260
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
|
261
|
+
)
|
262
|
+
end
|
271
263
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
)
|
284
|
-
end
|
264
|
+
it "should output multiple untyped attributes values through properties" do
|
265
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
|
266
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
|
267
|
+
check_xpaths(
|
268
|
+
serialize(:attributes => :untyped, :lang => "en-us"),
|
269
|
+
"/rdf:RDF/@xml:lang" => "en-us",
|
270
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
271
|
+
"/rdf:RDF/rdf:Description/dc:title[lang('de')]" => %(<dc:title xml:lang="de">foo</dc:title>),
|
272
|
+
"/rdf:RDF/rdf:Description/dc:title[lang('en-us')]" => %(<dc:title>foo</dc:title>)
|
273
|
+
)
|
274
|
+
end
|
285
275
|
|
286
|
-
|
287
|
-
|
288
|
-
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
|
276
|
+
it "should output typed node as attribute" do
|
277
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
289
278
|
check_xpaths(
|
290
279
|
serialize(:attributes => :untyped),
|
291
280
|
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
292
|
-
"/rdf:RDF/rdf:Description/dc:title
|
293
|
-
|
281
|
+
"/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
|
282
|
+
)
|
283
|
+
check_xpaths(
|
284
|
+
serialize(:attributes => :typed),
|
285
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
286
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
|
294
287
|
)
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should output multiple typed values through properties" do
|
291
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
|
292
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
|
293
|
+
check_xpaths(
|
294
|
+
serialize(:attributes => :untyped),
|
295
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
|
296
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
|
297
|
+
"/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
|
298
|
+
)
|
299
|
+
end
|
295
300
|
end
|
296
|
-
end
|
297
301
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
302
|
+
describe "with default namespace" do
|
303
|
+
it "should serialize with default namespace" do
|
304
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
305
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
306
|
+
@graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
|
303
307
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
308
|
+
xml = serialize(:max_depth => 1, :attributes => :untyped,
|
309
|
+
:default_namespace => FOO.to_s,
|
310
|
+
:prefixes => {:foo => FOO.to_s})
|
311
|
+
xml.should =~ /<Release/
|
312
|
+
xml.should =~ /<pred/
|
313
|
+
doc = Nokogiri::XML.parse(xml)
|
314
|
+
doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should serialize with nil namespace" do
|
318
|
+
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
|
319
|
+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
|
320
|
+
@graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
|
321
|
+
|
322
|
+
xml = serialize(:max_depth => 1, :attributes => :untyped,
|
323
|
+
:prefixes => {nil => FOO.to_s, :foo => FOO.to_s})
|
324
|
+
xml.should =~ /<Release/
|
325
|
+
xml.should =~ /<pred/
|
326
|
+
doc = Nokogiri::XML.parse(xml)
|
327
|
+
doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
|
328
|
+
end
|
309
329
|
end
|
310
|
-
end
|
311
330
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
331
|
+
describe "with base" do
|
332
|
+
it "should generate relative about URI" do
|
333
|
+
@graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
|
334
|
+
check_xpaths(
|
335
|
+
serialize(:attributes => :untyped, :base_uri => "http://release/"),
|
336
|
+
"/rdf:RDF/rdf:Description/@rdf:about" => "a",
|
337
|
+
"/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
|
338
|
+
)
|
339
|
+
end
|
320
340
|
end
|
321
|
-
end
|
322
341
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
342
|
+
describe "with bnodes" do
|
343
|
+
it "should not generate nodeID attribute unless node is referenced as an object" do
|
344
|
+
@graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
|
345
|
+
check_xpaths(
|
346
|
+
serialize(:attributes => :untyped, :base => "http://release/"),
|
347
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
348
|
+
"/rdf:RDF/rdf:Description/@rdf:nodeID" => false
|
349
|
+
)
|
350
|
+
end
|
332
351
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
352
|
+
it "should generate a nodeID attribute if node is referenced as an object" do
|
353
|
+
bn = RDF::Node.new("a")
|
354
|
+
@graph << [bn, RDF::DC.title, "foo"]
|
355
|
+
@graph << [bn, RDF::OWL.equals, bn]
|
356
|
+
check_xpaths(
|
357
|
+
serialize(:attributes => :untyped, :base => "http://release/"),
|
358
|
+
"/rdf:RDF/rdf:Description/@dc:title" => "foo",
|
359
|
+
"/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
|
360
|
+
"/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
|
361
|
+
)
|
362
|
+
end
|
344
363
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
364
|
+
it "should replicate rdfcore/rdfms-seq-representation" do
|
365
|
+
graph_expect = parse(%(
|
366
|
+
<http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
|
367
|
+
), :reader => RDF::N3::Reader)
|
368
|
+
graph_check = parse(serialize(:format => :rdfxml)).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
|
369
|
+
end
|
350
370
|
end
|
351
|
-
end
|
352
371
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
else
|
370
|
-
doc.root.at_xpath(path, doc.namespaces).to_s.should == value
|
372
|
+
describe "w3c rdfcore tests" do
|
373
|
+
require 'rdf_helper'
|
374
|
+
|
375
|
+
def self.positive_tests
|
376
|
+
RdfHelper::TestCase.positive_parser_tests(RDFCORE_TEST, RDFCORE_DIR)
|
377
|
+
end
|
378
|
+
|
379
|
+
positive_tests.each do |t|
|
380
|
+
#next unless t.about =~ /rdfms-not-id-and-resource-attr\/test001/
|
381
|
+
next if t.about =~ /rdfms-xml-literal-namespaces|xml-canon/ # Literal serialization adds namespace definitions
|
382
|
+
#next unless t.name =~ /11/
|
383
|
+
#puts t.inspect
|
384
|
+
specify "#{t.name}: " + (t.description || "#{t.outputDocument}") do
|
385
|
+
@graph = parse(t.output, :base_uri => t.about, :format => :ntriples)
|
386
|
+
parse(serialize(:format => :rdfxml, :base_uri => t.about), :base_uri => t.about).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
|
387
|
+
end
|
371
388
|
end
|
372
389
|
end
|
390
|
+
|
391
|
+
def check_xpaths(doc, paths)
|
392
|
+
puts doc.to_s if ::RDF::RDFXML::debug? || $verbose
|
393
|
+
doc = Nokogiri::XML.parse(doc)
|
394
|
+
doc.should be_a(Nokogiri::XML::Document)
|
395
|
+
doc.root.should be_a(Nokogiri::XML::Element)
|
396
|
+
paths.each_pair do |path, value|
|
397
|
+
@debug << doc.root.at_xpath(path, doc.namespaces).to_s if ::RDF::RDFXML::debug?
|
398
|
+
case value
|
399
|
+
when false
|
400
|
+
doc.root.at_xpath(path, doc.namespaces).should be_nil
|
401
|
+
when true
|
402
|
+
doc.root.at_xpath(path, doc.namespaces).should_not be_nil
|
403
|
+
when Array
|
404
|
+
doc.root.at_xpath(path, doc.namespaces).to_s.split(" ").should include(*value)
|
405
|
+
when Regexp
|
406
|
+
doc.root.at_xpath(path, doc.namespaces).to_s.should =~ value
|
407
|
+
else
|
408
|
+
doc.root.at_xpath(path, doc.namespaces).to_s.should == value
|
409
|
+
end
|
410
|
+
end
|
373
411
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
412
|
+
# Parse generated graph and compare to source
|
413
|
+
#graph = RDF::Graph.new
|
414
|
+
#RDF::RDFXML::Reader.new(doc, :base_uri => "http://release/", :format => :rdfxml).each {|st| graph << st}
|
415
|
+
#graph.should be_equivalent_graph(@graph, :about => "http://release/", :trace => @debug.join("\n"))
|
416
|
+
end
|
379
417
|
|
380
|
-
|
381
|
-
|
382
|
-
|
418
|
+
require 'rdf/n3'
|
419
|
+
def parse(input, options = {})
|
420
|
+
reader_class = options.fetch(:reader, detect_format(input))
|
383
421
|
|
384
|
-
|
385
|
-
|
386
|
-
|
422
|
+
graph = RDF::Graph.new
|
423
|
+
reader_class.new(input, options).each do |statement|
|
424
|
+
graph << statement
|
425
|
+
end
|
426
|
+
graph
|
387
427
|
end
|
388
|
-
graph
|
389
|
-
end
|
390
428
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
429
|
+
# Serialize @graph to a string and compare against regexps
|
430
|
+
def serialize(options = {})
|
431
|
+
@debug = []
|
432
|
+
result = @writer.buffer({:debug => @debug, :standard_prefixes => true}.merge(options)) do |writer|
|
433
|
+
writer << @graph
|
434
|
+
end
|
435
|
+
require 'cgi'
|
436
|
+
puts CGI.escapeHTML(result) if $verbose
|
437
|
+
result
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
describe "#get_qname" do
|
442
|
+
subject { RDF::RDFXML::Writer.new }
|
443
|
+
describe "with undefined predicate URIs" do
|
444
|
+
{
|
445
|
+
"http://a/b" => [:ns0, :b],
|
446
|
+
"dc:title" => [:ns0, :title]
|
447
|
+
}.each_pair do |uri, qname|
|
448
|
+
it "returns #{qname.inspect} given #{uri}" do
|
449
|
+
subject.get_qname(uri).should == qname
|
450
|
+
end
|
451
|
+
end
|
396
452
|
end
|
397
|
-
require 'cgi'
|
398
|
-
puts CGI.escapeHTML(result) if $verbose
|
399
|
-
result
|
400
453
|
end
|
401
454
|
end
|