yaml-ld 0.0.1
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.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/README.md +150 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/lib/yaml_ld/api.rb +295 -0
- data/lib/yaml_ld/format.rb +56 -0
- data/lib/yaml_ld/reader.rb +40 -0
- data/lib/yaml_ld/version.rb +20 -0
- data/lib/yaml_ld/writer.rb +42 -0
- data/lib/yaml_ld.rb +37 -0
- data/spec/api_spec.rb +92 -0
- data/spec/compact_spec.rb +358 -0
- data/spec/expand_spec.rb +565 -0
- data/spec/flatten_spec.rb +225 -0
- data/spec/format_spec.rb +54 -0
- data/spec/frame_spec.rb +662 -0
- data/spec/from_rdf_spec.rb +730 -0
- data/spec/matchers.rb +22 -0
- data/spec/reader_spec.rb +138 -0
- data/spec/spec_helper.rb +265 -0
- data/spec/support/extensions.rb +44 -0
- data/spec/test-files/test-1-compacted.jsonld +10 -0
- data/spec/test-files/test-1-context.jsonld +7 -0
- data/spec/test-files/test-1-expanded.jsonld +5 -0
- data/spec/test-files/test-1-input.yamlld +8 -0
- data/spec/test-files/test-1-rdf.ttl +8 -0
- data/spec/test-files/test-2-compacted.jsonld +20 -0
- data/spec/test-files/test-2-context.jsonld +7 -0
- data/spec/test-files/test-2-expanded.jsonld +16 -0
- data/spec/test-files/test-2-input.yamlld +16 -0
- data/spec/test-files/test-2-rdf.ttl +14 -0
- data/spec/test-files/test-3-compacted.jsonld +11 -0
- data/spec/test-files/test-3-context.jsonld +8 -0
- data/spec/test-files/test-3-expanded.jsonld +10 -0
- data/spec/test-files/test-3-input.yamlld +13 -0
- data/spec/test-files/test-3-rdf.ttl +8 -0
- data/spec/test-files/test-4-compacted.jsonld +10 -0
- data/spec/test-files/test-4-context.jsonld +7 -0
- data/spec/test-files/test-4-expanded.jsonld +6 -0
- data/spec/test-files/test-4-input.yamlld +9 -0
- data/spec/test-files/test-4-rdf.ttl +5 -0
- data/spec/test-files/test-5-compacted.jsonld +13 -0
- data/spec/test-files/test-5-context.jsonld +7 -0
- data/spec/test-files/test-5-expanded.jsonld +9 -0
- data/spec/test-files/test-5-input.yamlld +10 -0
- data/spec/test-files/test-5-rdf.ttl +7 -0
- data/spec/test-files/test-6-compacted.jsonld +10 -0
- data/spec/test-files/test-6-context.jsonld +7 -0
- data/spec/test-files/test-6-expanded.jsonld +10 -0
- data/spec/test-files/test-6-input.yamlld +12 -0
- data/spec/test-files/test-6-rdf.ttl +6 -0
- data/spec/test-files/test-7-compacted.jsonld +23 -0
- data/spec/test-files/test-7-context.jsonld +4 -0
- data/spec/test-files/test-7-expanded.jsonld +20 -0
- data/spec/test-files/test-7-input.yamlld +16 -0
- data/spec/test-files/test-7-rdf.ttl +14 -0
- data/spec/test-files/test-8-compacted.jsonld +34 -0
- data/spec/test-files/test-8-context.jsonld +11 -0
- data/spec/test-files/test-8-expanded.jsonld +24 -0
- data/spec/test-files/test-8-frame.jsonld +18 -0
- data/spec/test-files/test-8-framed.jsonld +25 -0
- data/spec/test-files/test-8-input.yamlld +24 -0
- data/spec/test-files/test-8-rdf.ttl +15 -0
- data/spec/test-files/test-9-compacted.jsonld +20 -0
- data/spec/test-files/test-9-context.jsonld +13 -0
- data/spec/test-files/test-9-expanded.jsonld +14 -0
- data/spec/test-files/test-9-input.yamlld +16 -0
- data/spec/to_rdf_spec.rb +556 -0
- data/spec/writer_spec.rb +441 -0
- metadata +350 -0
@@ -0,0 +1,730 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'rdf/spec/writer'
|
4
|
+
|
5
|
+
describe YAML_LD::API do
|
6
|
+
let(:logger) {RDF::Spec.logger}
|
7
|
+
|
8
|
+
describe ".fromRdf" do
|
9
|
+
context "simple tests" do
|
10
|
+
it "One subject IRI object" do
|
11
|
+
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
12
|
+
expect(serialize(input)).to produce_yamlld(%(
|
13
|
+
- "@id": http://a/b
|
14
|
+
http://a/c:
|
15
|
+
- "@id": http://a/d
|
16
|
+
), logger)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should generate object list" do
|
20
|
+
input = %(@prefix : <http://example.com/> . :b :c :d, :e .)
|
21
|
+
expect(serialize(input)).
|
22
|
+
to produce_yamlld(%(
|
23
|
+
- "@id": http://example.com/b
|
24
|
+
http://example.com/c:
|
25
|
+
- "@id": http://example.com/d
|
26
|
+
- "@id": http://example.com/e
|
27
|
+
), logger)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should generate property list" do
|
31
|
+
input = %(@prefix : <http://example.com/> . :b :c :d; :e :f .)
|
32
|
+
expect(serialize(input)).
|
33
|
+
to produce_yamlld(%(
|
34
|
+
- "@id": http://example.com/b
|
35
|
+
http://example.com/c:
|
36
|
+
- "@id": http://example.com/d
|
37
|
+
http://example.com/e:
|
38
|
+
- "@id": http://example.com/f
|
39
|
+
), logger)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "serializes multiple subjects" do
|
43
|
+
input = %q(
|
44
|
+
@prefix : <http://www.w3.org/2006/03/test-description#> .
|
45
|
+
@prefix dc: <http://purl.org/dc/elements/1.1/> .
|
46
|
+
<test-cases/0001> a :TestCase .
|
47
|
+
<test-cases/0002> a :TestCase .
|
48
|
+
)
|
49
|
+
expect(serialize(input)).
|
50
|
+
to produce_yamlld(%(
|
51
|
+
- "@id": test-cases/0001
|
52
|
+
"@type":
|
53
|
+
- http://www.w3.org/2006/03/test-description#TestCase
|
54
|
+
- "@id": test-cases/0002
|
55
|
+
"@type":
|
56
|
+
- http://www.w3.org/2006/03/test-description#TestCase
|
57
|
+
), logger)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "literals" do
|
62
|
+
context "coercion" do
|
63
|
+
it "typed literal" do
|
64
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"^^ex:d .)
|
65
|
+
expect(serialize(input)).to produce_yamlld(%(
|
66
|
+
- "@id": http://example.com/a
|
67
|
+
http://example.com/b:
|
68
|
+
- "@value": foo
|
69
|
+
"@type": http://example.com/d
|
70
|
+
), logger)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "integer" do
|
74
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
|
75
|
+
expect(serialize(input, useNativeTypes: true)).to produce_yamlld(%(
|
76
|
+
- "@id": http://example.com/a
|
77
|
+
http://example.com/b:
|
78
|
+
- "@value": 1
|
79
|
+
), logger)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "integer (non-native)" do
|
83
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
|
84
|
+
expect(serialize(input, useNativeTypes: false)).to produce_yamlld(%(
|
85
|
+
- "@id": http://example.com/a
|
86
|
+
http://example.com/b:
|
87
|
+
- "@value": '1'
|
88
|
+
"@type": http://www.w3.org/2001/XMLSchema#integer
|
89
|
+
), logger)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "boolean" do
|
93
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
|
94
|
+
expect(serialize(input, useNativeTypes: true)).to produce_yamlld(%(
|
95
|
+
- "@id": http://example.com/a
|
96
|
+
http://example.com/b:
|
97
|
+
- "@value": true
|
98
|
+
), logger)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "boolean (non-native)" do
|
102
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
|
103
|
+
expect(serialize(input, useNativeTypes: false)).to produce_yamlld(%(
|
104
|
+
- "@id": http://example.com/a
|
105
|
+
http://example.com/b:
|
106
|
+
- "@value": 'true'
|
107
|
+
"@type": http://www.w3.org/2001/XMLSchema#boolean
|
108
|
+
), logger)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "decmal" do
|
112
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0 .)
|
113
|
+
expect(serialize(input, useNativeTypes: true)).to produce_yamlld(%(
|
114
|
+
- "@id": http://example.com/a
|
115
|
+
http://example.com/b:
|
116
|
+
- "@value": '1.0'
|
117
|
+
"@type": http://www.w3.org/2001/XMLSchema#decimal
|
118
|
+
), logger)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "double" do
|
122
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
|
123
|
+
expect(serialize(input, useNativeTypes: true)).to produce_yamlld(%(
|
124
|
+
- "@id": http://example.com/a
|
125
|
+
http://example.com/b:
|
126
|
+
- "@value": 1.0
|
127
|
+
), logger)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "double (non-native)" do
|
131
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
|
132
|
+
expect(serialize(input, useNativeTypes: false)).to produce_yamlld(%(
|
133
|
+
- "@id": http://example.com/a
|
134
|
+
http://example.com/b:
|
135
|
+
- "@value": 1.0E0
|
136
|
+
"@type": http://www.w3.org/2001/XMLSchema#double
|
137
|
+
), logger)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "datatyped (non-native)" do
|
142
|
+
{
|
143
|
+
integer: 1,
|
144
|
+
unsignedInteger: 1,
|
145
|
+
nonNegativeInteger: 1,
|
146
|
+
float: 1,
|
147
|
+
nonPositiveInteger: -1,
|
148
|
+
negativeInteger: -1,
|
149
|
+
}.each do |t, v|
|
150
|
+
it "#{t}" do
|
151
|
+
input = %(
|
152
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
153
|
+
@prefix ex: <http://example.com/> .
|
154
|
+
ex:a ex:b "#{v}"^^xsd:#{t} .
|
155
|
+
)
|
156
|
+
expect(serialize(input, useNativeTypes: false)).to produce_yamlld(%(
|
157
|
+
- "@id": http://example.com/a
|
158
|
+
http://example.com/b:
|
159
|
+
- "@value": "#{v}"
|
160
|
+
"@type": http://www.w3.org/2001/XMLSchema##{t}
|
161
|
+
), logger)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "encodes language literal" do
|
167
|
+
input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"@en-us .)
|
168
|
+
expect(serialize(input)).to produce_yamlld(%(
|
169
|
+
- "@id": http://example.com/a
|
170
|
+
http://example.com/b:
|
171
|
+
- "@value": foo
|
172
|
+
"@language": en-us
|
173
|
+
), logger)
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with @type: @json" do
|
177
|
+
{
|
178
|
+
"true": {
|
179
|
+
output: %(
|
180
|
+
- "@id": http://example.org/vocab#id
|
181
|
+
http://example.org/vocab#bool:
|
182
|
+
- "@value": true
|
183
|
+
"@type": "@json"
|
184
|
+
),
|
185
|
+
input:%(
|
186
|
+
@prefix ex: <http://example.org/vocab#> .
|
187
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
188
|
+
ex:id ex:bool "true"^^rdf:JSON .
|
189
|
+
)
|
190
|
+
},
|
191
|
+
"false": {
|
192
|
+
output: %(
|
193
|
+
- "@id": http://example.org/vocab#id
|
194
|
+
http://example.org/vocab#bool:
|
195
|
+
- "@value": false
|
196
|
+
"@type": "@json"
|
197
|
+
),
|
198
|
+
input: %(
|
199
|
+
@prefix ex: <http://example.org/vocab#> .
|
200
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
201
|
+
ex:id ex:bool "false"^^rdf:JSON .
|
202
|
+
)
|
203
|
+
},
|
204
|
+
"double": {
|
205
|
+
output: %(
|
206
|
+
- "@id": http://example.org/vocab#id
|
207
|
+
http://example.org/vocab#double:
|
208
|
+
- "@value": 1.23
|
209
|
+
"@type": "@json"
|
210
|
+
),
|
211
|
+
input: %(
|
212
|
+
@prefix ex: <http://example.org/vocab#> .
|
213
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
214
|
+
ex:id ex:double "1.23E0"^^rdf:JSON .
|
215
|
+
)
|
216
|
+
},
|
217
|
+
"double-zero": {
|
218
|
+
output: %(
|
219
|
+
- "@id": http://example.org/vocab#id
|
220
|
+
http://example.org/vocab#double:
|
221
|
+
- "@value": 0
|
222
|
+
"@type": "@json"
|
223
|
+
),
|
224
|
+
input: %(
|
225
|
+
@prefix ex: <http://example.org/vocab#> .
|
226
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
227
|
+
ex:id ex:double "0.0E0"^^rdf:JSON .
|
228
|
+
)
|
229
|
+
},
|
230
|
+
"integer": {
|
231
|
+
output: %(
|
232
|
+
- "@id": http://example.org/vocab#id
|
233
|
+
http://example.org/vocab#integer:
|
234
|
+
- "@value": 123
|
235
|
+
"@type": "@json"
|
236
|
+
),
|
237
|
+
input: %(
|
238
|
+
@prefix ex: <http://example.org/vocab#> .
|
239
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
240
|
+
ex:id ex:integer "123"^^rdf:JSON .
|
241
|
+
)
|
242
|
+
},
|
243
|
+
"string": {
|
244
|
+
output: %(
|
245
|
+
- "@id": http://example.org/vocab#id
|
246
|
+
http://example.org/vocab#string:
|
247
|
+
- "@value": string
|
248
|
+
"@type": "@json"
|
249
|
+
),
|
250
|
+
input: %(
|
251
|
+
@prefix ex: <http://example.org/vocab#> .
|
252
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
253
|
+
ex:id ex:string "\\"string\\""^^rdf:JSON .
|
254
|
+
)
|
255
|
+
},
|
256
|
+
"null": {
|
257
|
+
output: %(
|
258
|
+
- "@id": http://example.org/vocab#id
|
259
|
+
http://example.org/vocab#null:
|
260
|
+
- "@value":
|
261
|
+
"@type": "@json"
|
262
|
+
),
|
263
|
+
input: %(
|
264
|
+
@prefix ex: <http://example.org/vocab#> .
|
265
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
266
|
+
ex:id ex:null "null"^^rdf:JSON .
|
267
|
+
)
|
268
|
+
},
|
269
|
+
"object": {
|
270
|
+
output: %(
|
271
|
+
- "@id": http://example.org/vocab#id
|
272
|
+
http://example.org/vocab#object:
|
273
|
+
- "@value":
|
274
|
+
foo: bar
|
275
|
+
"@type": "@json"
|
276
|
+
),
|
277
|
+
input: %(
|
278
|
+
@prefix ex: <http://example.org/vocab#> .
|
279
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
280
|
+
ex:id ex:object """{"foo":"bar"}"""^^rdf:JSON .
|
281
|
+
)
|
282
|
+
},
|
283
|
+
"array": {
|
284
|
+
output: %(
|
285
|
+
- "@id": http://example.org/vocab#id
|
286
|
+
http://example.org/vocab#array:
|
287
|
+
- "@value":
|
288
|
+
- foo: bar
|
289
|
+
"@type": "@json"
|
290
|
+
),
|
291
|
+
input: %(
|
292
|
+
@prefix ex: <http://example.org/vocab#> .
|
293
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
294
|
+
ex:id ex:array """[{"foo":"bar"}]"""^^rdf:JSON .
|
295
|
+
)
|
296
|
+
},
|
297
|
+
}.each do |title, params|
|
298
|
+
params[:input] = RDF::Graph.new << RDF::Turtle::Reader.new(params[:input])
|
299
|
+
it(title) {do_fromRdf(processingMode: "json-ld-1.1", **params)}
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "@direction" do
|
305
|
+
context "rdfDirection: null" do
|
306
|
+
{
|
307
|
+
"no language rtl datatype": {
|
308
|
+
input: %q(
|
309
|
+
<http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
|
310
|
+
),
|
311
|
+
output: %q(
|
312
|
+
- "@id": http://example.com/a
|
313
|
+
http://example.org/label:
|
314
|
+
- "@value": no language
|
315
|
+
"@type": https://www.w3.org/ns/i18n#_rtl
|
316
|
+
),
|
317
|
+
},
|
318
|
+
"no language rtl compound-literal": {
|
319
|
+
input: %q(
|
320
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
321
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
322
|
+
|
323
|
+
_:cl1 rdf:value "no language";
|
324
|
+
rdf:direction "rtl" .
|
325
|
+
),
|
326
|
+
output: %q(
|
327
|
+
- "@id": http://example.com/a
|
328
|
+
http://example.org/label:
|
329
|
+
- "@id": _:cl1
|
330
|
+
- "@id": _:cl1
|
331
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#value:
|
332
|
+
- "@value": no language
|
333
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#direction:
|
334
|
+
- "@value": rtl
|
335
|
+
),
|
336
|
+
},
|
337
|
+
"en-US rtl datatype": {
|
338
|
+
input: %q(
|
339
|
+
<http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-us_rtl> .
|
340
|
+
),
|
341
|
+
output: %q(
|
342
|
+
- "@id": http://example.com/a
|
343
|
+
http://example.org/label:
|
344
|
+
- "@value": en-US
|
345
|
+
"@type": https://www.w3.org/ns/i18n#en-us_rtl
|
346
|
+
),
|
347
|
+
},
|
348
|
+
"en-US rtl compound-literal": {
|
349
|
+
input: %q(
|
350
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
351
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
352
|
+
|
353
|
+
_:cl1 rdf:value "en-US";
|
354
|
+
rdf:language "en-us";
|
355
|
+
rdf:direction "rtl" .
|
356
|
+
),
|
357
|
+
output: %q(
|
358
|
+
- "@id": http://example.com/a
|
359
|
+
http://example.org/label:
|
360
|
+
- "@id": _:cl1
|
361
|
+
- "@id": _:cl1
|
362
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#value:
|
363
|
+
- "@value": en-US
|
364
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#language:
|
365
|
+
- "@value": en-us
|
366
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#direction:
|
367
|
+
- "@value": rtl
|
368
|
+
),
|
369
|
+
}
|
370
|
+
}.each_pair do |name, params|
|
371
|
+
it name do
|
372
|
+
do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: nil))
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
context "rdfDirection: i18n-datatype" do
|
378
|
+
{
|
379
|
+
"no language rtl datatype": {
|
380
|
+
input: %q(
|
381
|
+
<http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
|
382
|
+
),
|
383
|
+
output: %q(
|
384
|
+
- "@id": http://example.com/a
|
385
|
+
http://example.org/label:
|
386
|
+
- "@value": no language
|
387
|
+
"@direction": rtl
|
388
|
+
),
|
389
|
+
},
|
390
|
+
"no language rtl compound-literal": {
|
391
|
+
input: %q(
|
392
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
393
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
394
|
+
|
395
|
+
_:cl1 rdf:value "no language";
|
396
|
+
rdf:direction "rtl" .
|
397
|
+
),
|
398
|
+
output: %q(
|
399
|
+
- "@id": http://example.com/a
|
400
|
+
http://example.org/label:
|
401
|
+
- "@id": _:cl1
|
402
|
+
- "@id": _:cl1
|
403
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#value:
|
404
|
+
- "@value": no language
|
405
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#direction:
|
406
|
+
- "@value": rtl
|
407
|
+
),
|
408
|
+
},
|
409
|
+
"en-US rtl datatype": {
|
410
|
+
input: %q(
|
411
|
+
<http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-US_rtl> .
|
412
|
+
),
|
413
|
+
output: %q(
|
414
|
+
- "@id": http://example.com/a
|
415
|
+
http://example.org/label:
|
416
|
+
- "@value": en-US
|
417
|
+
"@language": en-US
|
418
|
+
"@direction": rtl
|
419
|
+
),
|
420
|
+
},
|
421
|
+
"en-US rtl compound-literal": {
|
422
|
+
input: %q(
|
423
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
424
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
425
|
+
|
426
|
+
_:cl1 rdf:value "en-US";
|
427
|
+
rdf:language "en-US";
|
428
|
+
rdf:direction "rtl" .
|
429
|
+
),
|
430
|
+
output: %q(
|
431
|
+
- "@id": http://example.com/a
|
432
|
+
http://example.org/label:
|
433
|
+
- "@id": _:cl1
|
434
|
+
- "@id": _:cl1
|
435
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#value:
|
436
|
+
- "@value": en-US
|
437
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#language:
|
438
|
+
- "@value": en-US
|
439
|
+
http://www.w3.org/1999/02/22-rdf-syntax-ns#direction:
|
440
|
+
- "@value": rtl
|
441
|
+
),
|
442
|
+
}
|
443
|
+
}.each_pair do |name, params|
|
444
|
+
it name do
|
445
|
+
do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: 'i18n-datatype', processingMode: 'json-ld-1.1'))
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
context "rdfDirection: compound-literal" do
|
451
|
+
{
|
452
|
+
"no language rtl datatype": {
|
453
|
+
input: %q(
|
454
|
+
<http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
|
455
|
+
),
|
456
|
+
output: %q(
|
457
|
+
- "@id": http://example.com/a
|
458
|
+
http://example.org/label:
|
459
|
+
- "@value": no language
|
460
|
+
"@type": https://www.w3.org/ns/i18n#_rtl
|
461
|
+
),
|
462
|
+
},
|
463
|
+
"no language rtl compound-literal": {
|
464
|
+
input: %q(
|
465
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
466
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
467
|
+
|
468
|
+
_:cl1 rdf:value "no language";
|
469
|
+
rdf:direction "rtl" .
|
470
|
+
),
|
471
|
+
output: %q(
|
472
|
+
- "@id": http://example.com/a
|
473
|
+
http://example.org/label:
|
474
|
+
- "@value": no language
|
475
|
+
"@direction": rtl
|
476
|
+
),
|
477
|
+
},
|
478
|
+
"en-US rtl datatype": {
|
479
|
+
input: %q(
|
480
|
+
<http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-us_rtl> .
|
481
|
+
),
|
482
|
+
output: %q(
|
483
|
+
- "@id": http://example.com/a
|
484
|
+
http://example.org/label:
|
485
|
+
- "@value": en-US
|
486
|
+
"@type": https://www.w3.org/ns/i18n#en-us_rtl
|
487
|
+
),
|
488
|
+
},
|
489
|
+
"en-US rtl compound-literal": {
|
490
|
+
input: %q(
|
491
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
492
|
+
<http://example.com/a> <http://example.org/label> _:cl1 .
|
493
|
+
|
494
|
+
_:cl1 rdf:value "en-US";
|
495
|
+
rdf:language "en-us";
|
496
|
+
rdf:direction "rtl" .
|
497
|
+
),
|
498
|
+
output: %q(
|
499
|
+
- "@id": http://example.com/a
|
500
|
+
http://example.org/label:
|
501
|
+
- "@value": en-US
|
502
|
+
"@language": en-us
|
503
|
+
"@direction": rtl
|
504
|
+
),
|
505
|
+
}
|
506
|
+
}.each_pair do |name, params|
|
507
|
+
it name do
|
508
|
+
do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: 'compound-literal', processingMode: 'json-ld-1.1'))
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
context "RDF-star" do
|
515
|
+
{
|
516
|
+
"subject-iii": {
|
517
|
+
input: RDF::Statement(
|
518
|
+
RDF::Statement(
|
519
|
+
RDF::URI('http://example/s1'),
|
520
|
+
RDF::URI('http://example/p1'),
|
521
|
+
RDF::URI('http://example/o1')),
|
522
|
+
RDF::URI('http://example/p'),
|
523
|
+
RDF::URI('http://example/o')),
|
524
|
+
output: %(
|
525
|
+
- "@id":
|
526
|
+
"@id": http://example/s1
|
527
|
+
http://example/p1:
|
528
|
+
- "@id": http://example/o1
|
529
|
+
http://example/p:
|
530
|
+
- "@id": http://example/o
|
531
|
+
)
|
532
|
+
},
|
533
|
+
"subject-iib": {
|
534
|
+
input: RDF::Statement(
|
535
|
+
RDF::Statement(
|
536
|
+
RDF::URI('http://example/s1'),
|
537
|
+
RDF::URI('http://example/p1'),
|
538
|
+
RDF::Node.new('o1')),
|
539
|
+
RDF::URI('http://example/p'),
|
540
|
+
RDF::URI('http://example/o')),
|
541
|
+
output: %(
|
542
|
+
- "@id":
|
543
|
+
"@id": http://example/s1
|
544
|
+
http://example/p1:
|
545
|
+
- "@id": _:o1
|
546
|
+
http://example/p:
|
547
|
+
- "@id": http://example/o
|
548
|
+
)
|
549
|
+
},
|
550
|
+
"subject-iil": {
|
551
|
+
input: RDF::Statement(
|
552
|
+
RDF::Statement(
|
553
|
+
RDF::URI('http://example/s1'),
|
554
|
+
RDF::URI('http://example/p1'),
|
555
|
+
RDF::Literal('o1')),
|
556
|
+
RDF::URI('http://example/p'),
|
557
|
+
RDF::URI('http://example/o')),
|
558
|
+
output: %(
|
559
|
+
- "@id":
|
560
|
+
"@id": http://example/s1
|
561
|
+
http://example/p1:
|
562
|
+
- "@value": o1
|
563
|
+
http://example/p:
|
564
|
+
- "@id": http://example/o
|
565
|
+
)
|
566
|
+
},
|
567
|
+
"subject-bii": {
|
568
|
+
input: RDF::Statement(
|
569
|
+
RDF::Statement(
|
570
|
+
RDF::Node('s1'),
|
571
|
+
RDF::URI('http://example/p1'),
|
572
|
+
RDF::URI('http://example/o1')),
|
573
|
+
RDF::URI('http://example/p'),
|
574
|
+
RDF::URI('http://example/o')),
|
575
|
+
output: %(
|
576
|
+
- "@id":
|
577
|
+
"@id": _:s1
|
578
|
+
http://example/p1:
|
579
|
+
- "@id": http://example/o1
|
580
|
+
http://example/p:
|
581
|
+
- "@id": http://example/o
|
582
|
+
)
|
583
|
+
},
|
584
|
+
"subject-bib": {
|
585
|
+
input: RDF::Statement(
|
586
|
+
RDF::Statement(
|
587
|
+
RDF::Node('s1'),
|
588
|
+
RDF::URI('http://example/p1'),
|
589
|
+
RDF::Node.new('o1')),
|
590
|
+
RDF::URI('http://example/p'), RDF::URI('http://example/o')),
|
591
|
+
output: %(
|
592
|
+
- "@id":
|
593
|
+
"@id": _:s1
|
594
|
+
http://example/p1:
|
595
|
+
- "@id": _:o1
|
596
|
+
http://example/p:
|
597
|
+
- "@id": http://example/o
|
598
|
+
)
|
599
|
+
},
|
600
|
+
"subject-bil": {
|
601
|
+
input: RDF::Statement(
|
602
|
+
RDF::Statement(
|
603
|
+
RDF::Node('s1'),
|
604
|
+
RDF::URI('http://example/p1'),
|
605
|
+
RDF::Literal('o1')),
|
606
|
+
RDF::URI('http://example/p'),
|
607
|
+
RDF::URI('http://example/o')),
|
608
|
+
output: %(
|
609
|
+
- "@id":
|
610
|
+
"@id": _:s1
|
611
|
+
http://example/p1:
|
612
|
+
- "@value": o1
|
613
|
+
http://example/p:
|
614
|
+
- "@id": http://example/o
|
615
|
+
)
|
616
|
+
},
|
617
|
+
"object-iii": {
|
618
|
+
input: RDF::Statement(
|
619
|
+
RDF::URI('http://example/s'),
|
620
|
+
RDF::URI('http://example/p'),
|
621
|
+
RDF::Statement(
|
622
|
+
RDF::URI('http://example/s1'),
|
623
|
+
RDF::URI('http://example/p1'),
|
624
|
+
RDF::URI('http://example/o1'))),
|
625
|
+
output: %(
|
626
|
+
- "@id": http://example/s
|
627
|
+
http://example/p:
|
628
|
+
- "@id":
|
629
|
+
"@id": http://example/s1
|
630
|
+
http://example/p1:
|
631
|
+
- "@id": http://example/o1
|
632
|
+
)
|
633
|
+
},
|
634
|
+
"object-iib": {
|
635
|
+
input: RDF::Statement(
|
636
|
+
RDF::URI('http://example/s'),
|
637
|
+
RDF::URI('http://example/p'),
|
638
|
+
RDF::Statement(
|
639
|
+
RDF::URI('http://example/s1'),
|
640
|
+
RDF::URI('http://example/p1'),
|
641
|
+
RDF::Node.new('o1'))),
|
642
|
+
output: %(
|
643
|
+
- "@id": http://example/s
|
644
|
+
http://example/p:
|
645
|
+
- "@id":
|
646
|
+
"@id": http://example/s1
|
647
|
+
http://example/p1:
|
648
|
+
- "@id": _:o1
|
649
|
+
)
|
650
|
+
},
|
651
|
+
"object-iil": {
|
652
|
+
input: RDF::Statement(
|
653
|
+
RDF::URI('http://example/s'),
|
654
|
+
RDF::URI('http://example/p'),
|
655
|
+
RDF::Statement(
|
656
|
+
RDF::URI('http://example/s1'),
|
657
|
+
RDF::URI('http://example/p1'),
|
658
|
+
RDF::Literal('o1'))),
|
659
|
+
output: %(
|
660
|
+
- "@id": http://example/s
|
661
|
+
http://example/p:
|
662
|
+
- "@id":
|
663
|
+
"@id": http://example/s1
|
664
|
+
http://example/p1:
|
665
|
+
- "@value": o1
|
666
|
+
)
|
667
|
+
},
|
668
|
+
"recursive-subject": {
|
669
|
+
input: RDF::Statement(
|
670
|
+
RDF::Statement(
|
671
|
+
RDF::Statement(
|
672
|
+
RDF::URI('http://example/s2'),
|
673
|
+
RDF::URI('http://example/p2'),
|
674
|
+
RDF::URI('http://example/o2')),
|
675
|
+
RDF::URI('http://example/p1'),
|
676
|
+
RDF::URI('http://example/o1')),
|
677
|
+
RDF::URI('http://example/p'),
|
678
|
+
RDF::URI('http://example/o')),
|
679
|
+
output: %(
|
680
|
+
- "@id":
|
681
|
+
"@id":
|
682
|
+
"@id": http://example/s2
|
683
|
+
http://example/p2:
|
684
|
+
- "@id": http://example/o2
|
685
|
+
http://example/p1:
|
686
|
+
- "@id": http://example/o1
|
687
|
+
http://example/p:
|
688
|
+
- "@id": http://example/o
|
689
|
+
)
|
690
|
+
},
|
691
|
+
}.each do |name, params|
|
692
|
+
it name do
|
693
|
+
graph = RDF::Graph.new {|g| g << params[:input]}
|
694
|
+
do_fromRdf(params.merge(input: graph, prefixes: {ex: 'http://example/'}))
|
695
|
+
end
|
696
|
+
end
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
def parse(input, **options)
|
701
|
+
reader = options[:reader] || RDF::TriG::Reader
|
702
|
+
reader.new(input, **options, &:each_statement).to_a.extend(RDF::Enumerable)
|
703
|
+
end
|
704
|
+
|
705
|
+
# Serialize ntstr to a string and compare against regexps
|
706
|
+
def serialize(ntstr, **options)
|
707
|
+
logger.info ntstr if ntstr.is_a?(String)
|
708
|
+
g = ntstr.is_a?(String) ? parse(ntstr, **options) : ntstr
|
709
|
+
logger.info g.dump(:trig)
|
710
|
+
statements = g.each_statement.to_a
|
711
|
+
YAML_LD::API.fromRdf(statements, logger: logger, **options)
|
712
|
+
end
|
713
|
+
|
714
|
+
def do_fromRdf(params)
|
715
|
+
begin
|
716
|
+
input, output = params[:input], params[:output]
|
717
|
+
jld = nil
|
718
|
+
if params[:write]
|
719
|
+
expect{jld = serialize(input, **params)}.to write(params[:write]).to(:error)
|
720
|
+
else
|
721
|
+
expect{jld = serialize(input, **params)}.not_to write.to(:error)
|
722
|
+
end
|
723
|
+
expect(jld).to produce_yamlld(output, logger)
|
724
|
+
rescue JSON::LD::JsonLdError => e
|
725
|
+
fail("#{e.class}: #{e.message}\n" +
|
726
|
+
"#{logger}\n" +
|
727
|
+
"Backtrace:\n#{e.backtrace.join("\n")}")
|
728
|
+
end
|
729
|
+
end
|
730
|
+
end
|