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
data/spec/frame_spec.rb
ADDED
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require_relative 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe YAML_LD::API do
|
|
5
|
+
let(:logger) {RDF::Spec.logger}
|
|
6
|
+
|
|
7
|
+
describe ".frame" do
|
|
8
|
+
{
|
|
9
|
+
"exact @type match": {
|
|
10
|
+
frame: %(
|
|
11
|
+
"@context":
|
|
12
|
+
ex: http://example.org/
|
|
13
|
+
"@type": ex:Type1
|
|
14
|
+
),
|
|
15
|
+
input: %(
|
|
16
|
+
- "@context":
|
|
17
|
+
ex: http://example.org/
|
|
18
|
+
"@id": ex:Sub1
|
|
19
|
+
"@type": ex:Type1
|
|
20
|
+
- "@context":
|
|
21
|
+
ex: http://example.org/
|
|
22
|
+
"@id": ex:Sub2
|
|
23
|
+
"@type": ex:Type2
|
|
24
|
+
),
|
|
25
|
+
output: %(---
|
|
26
|
+
"@context":
|
|
27
|
+
ex: http://example.org/
|
|
28
|
+
"@graph":
|
|
29
|
+
- "@id": ex:Sub1
|
|
30
|
+
"@type": ex:Type1
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
"wildcard @type match": {
|
|
34
|
+
frame: %(
|
|
35
|
+
"@context":
|
|
36
|
+
ex: http://example.org/
|
|
37
|
+
"@type": {}
|
|
38
|
+
),
|
|
39
|
+
input: %(
|
|
40
|
+
- "@context":
|
|
41
|
+
ex: http://example.org/
|
|
42
|
+
"@id": ex:Sub1
|
|
43
|
+
"@type": ex:Type1
|
|
44
|
+
- "@context":
|
|
45
|
+
ex: http://example.org/
|
|
46
|
+
"@id": ex:Sub2
|
|
47
|
+
"@type": ex:Type2
|
|
48
|
+
),
|
|
49
|
+
output: %(
|
|
50
|
+
"@context":
|
|
51
|
+
ex: http://example.org/
|
|
52
|
+
"@graph":
|
|
53
|
+
- "@id": ex:Sub1
|
|
54
|
+
"@type": ex:Type1
|
|
55
|
+
- "@id": ex:Sub2
|
|
56
|
+
"@type": ex:Type2
|
|
57
|
+
)
|
|
58
|
+
},
|
|
59
|
+
"match none @type match": {
|
|
60
|
+
frame: %(
|
|
61
|
+
"@context":
|
|
62
|
+
ex: http://example.org/
|
|
63
|
+
"@type": []
|
|
64
|
+
),
|
|
65
|
+
input: %(
|
|
66
|
+
- "@context":
|
|
67
|
+
ex: http://example.org/
|
|
68
|
+
"@id": ex:Sub1
|
|
69
|
+
"@type": ex:Type1
|
|
70
|
+
ex:p: Foo
|
|
71
|
+
- "@context":
|
|
72
|
+
ex: http://example.org/
|
|
73
|
+
"@id": ex:Sub2
|
|
74
|
+
ex:p: Bar
|
|
75
|
+
),
|
|
76
|
+
output: %(
|
|
77
|
+
"@context":
|
|
78
|
+
ex: http://example.org/
|
|
79
|
+
"@graph":
|
|
80
|
+
- "@id": ex:Sub2
|
|
81
|
+
ex:p: Bar
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
"multiple matches on @type": {
|
|
85
|
+
frame: %(
|
|
86
|
+
"@context":
|
|
87
|
+
ex: http://example.org/
|
|
88
|
+
"@type": ex:Type1
|
|
89
|
+
),
|
|
90
|
+
input: %(
|
|
91
|
+
- "@context":
|
|
92
|
+
ex: http://example.org/
|
|
93
|
+
"@id": ex:Sub1
|
|
94
|
+
"@type": ex:Type1
|
|
95
|
+
- "@context":
|
|
96
|
+
ex: http://example.org/
|
|
97
|
+
"@id": ex:Sub2
|
|
98
|
+
"@type": ex:Type1
|
|
99
|
+
- "@context":
|
|
100
|
+
ex: http://example.org/
|
|
101
|
+
"@id": ex:Sub3
|
|
102
|
+
"@type":
|
|
103
|
+
- ex:Type1
|
|
104
|
+
- ex:Type2
|
|
105
|
+
),
|
|
106
|
+
output: %(
|
|
107
|
+
"@context":
|
|
108
|
+
ex: http://example.org/
|
|
109
|
+
"@graph":
|
|
110
|
+
- "@id": ex:Sub1
|
|
111
|
+
"@type": ex:Type1
|
|
112
|
+
- "@id": ex:Sub2
|
|
113
|
+
"@type": ex:Type1
|
|
114
|
+
- "@id": ex:Sub3
|
|
115
|
+
"@type":
|
|
116
|
+
- ex:Type1
|
|
117
|
+
- ex:Type2
|
|
118
|
+
)
|
|
119
|
+
},
|
|
120
|
+
"single @id match": {
|
|
121
|
+
frame: %(
|
|
122
|
+
"@context":
|
|
123
|
+
ex: http://example.org/
|
|
124
|
+
"@id": ex:Sub1
|
|
125
|
+
),
|
|
126
|
+
input: %(
|
|
127
|
+
- "@context":
|
|
128
|
+
ex: http://example.org/
|
|
129
|
+
"@id": ex:Sub1
|
|
130
|
+
"@type": ex:Type1
|
|
131
|
+
- "@context":
|
|
132
|
+
ex: http://example.org/
|
|
133
|
+
"@id": ex:Sub2
|
|
134
|
+
"@type": ex:Type2
|
|
135
|
+
),
|
|
136
|
+
output: %(
|
|
137
|
+
"@context":
|
|
138
|
+
ex: http://example.org/
|
|
139
|
+
"@graph":
|
|
140
|
+
- "@id": ex:Sub1
|
|
141
|
+
"@type": ex:Type1
|
|
142
|
+
)
|
|
143
|
+
},
|
|
144
|
+
"multiple @id match": {
|
|
145
|
+
frame: %(
|
|
146
|
+
"@context":
|
|
147
|
+
ex: http://example.org/
|
|
148
|
+
"@id":
|
|
149
|
+
- ex:Sub1
|
|
150
|
+
- ex:Sub2
|
|
151
|
+
),
|
|
152
|
+
input: %(
|
|
153
|
+
- "@context":
|
|
154
|
+
ex: http://example.org/
|
|
155
|
+
"@id": ex:Sub1
|
|
156
|
+
"@type": ex:Type1
|
|
157
|
+
- "@context":
|
|
158
|
+
ex: http://example.org/
|
|
159
|
+
"@id": ex:Sub2
|
|
160
|
+
"@type": ex:Type2
|
|
161
|
+
- "@context":
|
|
162
|
+
ex: http://example.org/
|
|
163
|
+
"@id": ex:Sub3
|
|
164
|
+
"@type": ex:Type3
|
|
165
|
+
),
|
|
166
|
+
output: %(
|
|
167
|
+
"@context":
|
|
168
|
+
ex: http://example.org/
|
|
169
|
+
"@graph":
|
|
170
|
+
- "@id": ex:Sub1
|
|
171
|
+
"@type": ex:Type1
|
|
172
|
+
- "@id": ex:Sub2
|
|
173
|
+
"@type": ex:Type2
|
|
174
|
+
)
|
|
175
|
+
},
|
|
176
|
+
"wildcard and match none": {
|
|
177
|
+
frame: %(
|
|
178
|
+
"@context":
|
|
179
|
+
ex: http://example.org/
|
|
180
|
+
ex:p: []
|
|
181
|
+
ex:q: {}
|
|
182
|
+
),
|
|
183
|
+
input: %(
|
|
184
|
+
- "@context":
|
|
185
|
+
ex: http://example.org/
|
|
186
|
+
"@id": ex:Sub1
|
|
187
|
+
ex:q: bar
|
|
188
|
+
- "@context":
|
|
189
|
+
ex: http://example.org/
|
|
190
|
+
"@id": ex:Sub2
|
|
191
|
+
ex:p: foo
|
|
192
|
+
ex:q: bar
|
|
193
|
+
),
|
|
194
|
+
output: %(
|
|
195
|
+
"@context":
|
|
196
|
+
ex: http://example.org/
|
|
197
|
+
"@graph":
|
|
198
|
+
- "@id": ex:Sub1
|
|
199
|
+
ex:p:
|
|
200
|
+
ex:q: bar
|
|
201
|
+
)
|
|
202
|
+
},
|
|
203
|
+
"match on any property if @requireAll is false": {
|
|
204
|
+
frame: %(
|
|
205
|
+
"@context":
|
|
206
|
+
ex: http://example.org/
|
|
207
|
+
"@requireAll": false
|
|
208
|
+
ex:p: {}
|
|
209
|
+
ex:q: {}
|
|
210
|
+
),
|
|
211
|
+
input: %(
|
|
212
|
+
- "@context":
|
|
213
|
+
ex: http://example.org/
|
|
214
|
+
"@id": ex:Sub1
|
|
215
|
+
ex:p: foo
|
|
216
|
+
- "@context":
|
|
217
|
+
ex: http://example.org/
|
|
218
|
+
"@id": ex:Sub2
|
|
219
|
+
ex:q: bar
|
|
220
|
+
),
|
|
221
|
+
output: %(
|
|
222
|
+
"@context":
|
|
223
|
+
ex: http://example.org/
|
|
224
|
+
"@graph":
|
|
225
|
+
- "@id": ex:Sub1
|
|
226
|
+
ex:p: foo
|
|
227
|
+
ex:q:
|
|
228
|
+
- "@id": ex:Sub2
|
|
229
|
+
ex:p:
|
|
230
|
+
ex:q: bar
|
|
231
|
+
)
|
|
232
|
+
},
|
|
233
|
+
"match on defeaults if @requireAll is true and at least one property matches": {
|
|
234
|
+
frame: %(
|
|
235
|
+
"@context":
|
|
236
|
+
ex: http://example.org/
|
|
237
|
+
"@requireAll": true
|
|
238
|
+
ex:p:
|
|
239
|
+
"@default": Foo
|
|
240
|
+
ex:q:
|
|
241
|
+
"@default": Bar
|
|
242
|
+
),
|
|
243
|
+
input: %(
|
|
244
|
+
- "@context":
|
|
245
|
+
ex: http://example.org/
|
|
246
|
+
"@id": ex:Sub1
|
|
247
|
+
ex:p: foo
|
|
248
|
+
- "@context":
|
|
249
|
+
ex: http://example.org/
|
|
250
|
+
"@id": ex:Sub2
|
|
251
|
+
ex:q: bar
|
|
252
|
+
- "@context":
|
|
253
|
+
ex: http://example.org/
|
|
254
|
+
"@id": ex:Sub3
|
|
255
|
+
ex:p: foo
|
|
256
|
+
ex:q: bar
|
|
257
|
+
- "@context":
|
|
258
|
+
ex: http://example.org/
|
|
259
|
+
"@id": ex:Sub4
|
|
260
|
+
ex:r: baz
|
|
261
|
+
),
|
|
262
|
+
output: %(
|
|
263
|
+
"@context":
|
|
264
|
+
ex: http://example.org/
|
|
265
|
+
"@graph":
|
|
266
|
+
- "@id": ex:Sub1
|
|
267
|
+
ex:p: foo
|
|
268
|
+
ex:q: Bar
|
|
269
|
+
- "@id": ex:Sub2
|
|
270
|
+
ex:p: Foo
|
|
271
|
+
ex:q: bar
|
|
272
|
+
- "@id": ex:Sub3
|
|
273
|
+
ex:p: foo
|
|
274
|
+
ex:q: bar
|
|
275
|
+
)
|
|
276
|
+
},
|
|
277
|
+
"issue #40 - example": {
|
|
278
|
+
frame: %(
|
|
279
|
+
"@context":
|
|
280
|
+
"@version": 1.1
|
|
281
|
+
"@vocab": https://schema.org/
|
|
282
|
+
"@type": Person
|
|
283
|
+
"@requireAll": true
|
|
284
|
+
givenName: John
|
|
285
|
+
familyName: Doe
|
|
286
|
+
),
|
|
287
|
+
input: %(
|
|
288
|
+
"@context":
|
|
289
|
+
"@version": 1.1
|
|
290
|
+
"@vocab": https://schema.org/
|
|
291
|
+
"@graph":
|
|
292
|
+
- "@id": '1'
|
|
293
|
+
"@type": Person
|
|
294
|
+
name: John Doe
|
|
295
|
+
givenName: John
|
|
296
|
+
familyName: Doe
|
|
297
|
+
- "@id": '2'
|
|
298
|
+
"@type": Person
|
|
299
|
+
name: Jane Doe
|
|
300
|
+
givenName: Jane
|
|
301
|
+
),
|
|
302
|
+
output: %(
|
|
303
|
+
"@context":
|
|
304
|
+
"@version": 1.1
|
|
305
|
+
"@vocab": https://schema.org/
|
|
306
|
+
"@id": '1'
|
|
307
|
+
"@type": Person
|
|
308
|
+
familyName: Doe
|
|
309
|
+
givenName: John
|
|
310
|
+
name: John Doe
|
|
311
|
+
),
|
|
312
|
+
processingMode: 'json-ld-1.1'
|
|
313
|
+
},
|
|
314
|
+
"mixed content": {
|
|
315
|
+
frame: %(
|
|
316
|
+
"@context":
|
|
317
|
+
ex: http://example.org/
|
|
318
|
+
ex:mixed:
|
|
319
|
+
"@embed": "@never"
|
|
320
|
+
),
|
|
321
|
+
input: %(
|
|
322
|
+
"@context":
|
|
323
|
+
ex: http://example.org/
|
|
324
|
+
"@id": ex:Sub1
|
|
325
|
+
ex:mixed:
|
|
326
|
+
- "@id": ex:Sub2
|
|
327
|
+
- literal1
|
|
328
|
+
),
|
|
329
|
+
output: %(
|
|
330
|
+
"@context":
|
|
331
|
+
ex: http://example.org/
|
|
332
|
+
"@graph":
|
|
333
|
+
- "@id": ex:Sub1
|
|
334
|
+
ex:mixed:
|
|
335
|
+
- "@id": ex:Sub2
|
|
336
|
+
- literal1
|
|
337
|
+
)
|
|
338
|
+
},
|
|
339
|
+
"framed list": {
|
|
340
|
+
frame: %(
|
|
341
|
+
"@context":
|
|
342
|
+
ex: http://example.org/
|
|
343
|
+
list:
|
|
344
|
+
"@id": ex:list
|
|
345
|
+
"@container": "@list"
|
|
346
|
+
list:
|
|
347
|
+
- "@type": ex:Element
|
|
348
|
+
),
|
|
349
|
+
input: %(
|
|
350
|
+
"@context":
|
|
351
|
+
ex: http://example.org/
|
|
352
|
+
list:
|
|
353
|
+
"@id": ex:list
|
|
354
|
+
"@container": "@list"
|
|
355
|
+
"@id": ex:Sub1
|
|
356
|
+
"@type": ex:Type1
|
|
357
|
+
list:
|
|
358
|
+
- "@id": ex:Sub2
|
|
359
|
+
"@type": ex:Element
|
|
360
|
+
- literal1
|
|
361
|
+
),
|
|
362
|
+
output: %(
|
|
363
|
+
"@context":
|
|
364
|
+
ex: http://example.org/
|
|
365
|
+
list:
|
|
366
|
+
"@id": ex:list
|
|
367
|
+
"@container": "@list"
|
|
368
|
+
"@graph":
|
|
369
|
+
- "@id": ex:Sub1
|
|
370
|
+
"@type": ex:Type1
|
|
371
|
+
list:
|
|
372
|
+
- "@id": ex:Sub2
|
|
373
|
+
"@type": ex:Element
|
|
374
|
+
- literal1
|
|
375
|
+
)
|
|
376
|
+
},
|
|
377
|
+
"presentation example": {
|
|
378
|
+
frame: %(
|
|
379
|
+
"@context":
|
|
380
|
+
primaryTopic:
|
|
381
|
+
"@id": http://xmlns.com/foaf/0.1/primaryTopic
|
|
382
|
+
"@type": "@id"
|
|
383
|
+
sameAs:
|
|
384
|
+
"@id": http://www.w3.org/2002/07/owl#sameAs
|
|
385
|
+
"@type": "@id"
|
|
386
|
+
primaryTopic:
|
|
387
|
+
"@type": http://dbpedia.org/class/yago/Buzzwords
|
|
388
|
+
sameAs: {}
|
|
389
|
+
),
|
|
390
|
+
input: %(
|
|
391
|
+
- "@id": http://en.wikipedia.org/wiki/Linked_Data
|
|
392
|
+
http://xmlns.com/foaf/0.1/primaryTopic:
|
|
393
|
+
"@id": http://dbpedia.org/resource/Linked_Data
|
|
394
|
+
- "@id": http://www4.wiwiss.fu-berlin.de/flickrwrappr/photos/Linked_Data
|
|
395
|
+
http://www.w3.org/2002/07/owl#sameAs:
|
|
396
|
+
"@id": http://dbpedia.org/resource/Linked_Data
|
|
397
|
+
- "@id": http://dbpedia.org/resource/Linked_Data
|
|
398
|
+
"@type": http://dbpedia.org/class/yago/Buzzwords
|
|
399
|
+
http://www.w3.org/2002/07/owl#sameAs:
|
|
400
|
+
"@id": http://rdf.freebase.com/ns/m/02r2kb1
|
|
401
|
+
- "@id": http://mpii.de/yago/resource/Linked_Data
|
|
402
|
+
http://www.w3.org/2002/07/owl#sameAs:
|
|
403
|
+
"@id": http://dbpedia.org/resource/Linked_Data
|
|
404
|
+
),
|
|
405
|
+
output: %(
|
|
406
|
+
"@context":
|
|
407
|
+
primaryTopic:
|
|
408
|
+
"@id": http://xmlns.com/foaf/0.1/primaryTopic
|
|
409
|
+
"@type": "@id"
|
|
410
|
+
sameAs:
|
|
411
|
+
"@id": http://www.w3.org/2002/07/owl#sameAs
|
|
412
|
+
"@type": "@id"
|
|
413
|
+
"@graph":
|
|
414
|
+
- "@id": http://en.wikipedia.org/wiki/Linked_Data
|
|
415
|
+
primaryTopic:
|
|
416
|
+
"@id": http://dbpedia.org/resource/Linked_Data
|
|
417
|
+
"@type": http://dbpedia.org/class/yago/Buzzwords
|
|
418
|
+
sameAs: http://rdf.freebase.com/ns/m/02r2kb1
|
|
419
|
+
)
|
|
420
|
+
},
|
|
421
|
+
"library": {
|
|
422
|
+
frame: %(
|
|
423
|
+
"@context":
|
|
424
|
+
dc: http://purl.org/dc/elements/1.1/
|
|
425
|
+
ex: http://example.org/vocab#
|
|
426
|
+
xsd: http://www.w3.org/2001/XMLSchema#
|
|
427
|
+
ex:contains:
|
|
428
|
+
"@type": "@id"
|
|
429
|
+
"@type": ex:Library
|
|
430
|
+
ex:contains: {}
|
|
431
|
+
),
|
|
432
|
+
input: %(
|
|
433
|
+
"@context":
|
|
434
|
+
dc: http://purl.org/dc/elements/1.1/
|
|
435
|
+
ex: http://example.org/vocab#
|
|
436
|
+
xsd: http://www.w3.org/2001/XMLSchema#
|
|
437
|
+
"@id": http://example.org/library
|
|
438
|
+
"@type": ex:Library
|
|
439
|
+
dc:name: Library
|
|
440
|
+
ex:contains:
|
|
441
|
+
"@id": http://example.org/library/the-republic
|
|
442
|
+
"@type": ex:Book
|
|
443
|
+
dc:creator: Plato
|
|
444
|
+
dc:title: The Republic
|
|
445
|
+
ex:contains:
|
|
446
|
+
"@id": http://example.org/library/the-republic#introduction
|
|
447
|
+
"@type": ex:Chapter
|
|
448
|
+
dc:description: An introductory chapter on The Republic.
|
|
449
|
+
dc:title: The Introduction
|
|
450
|
+
),
|
|
451
|
+
output: %(
|
|
452
|
+
"@context":
|
|
453
|
+
dc: http://purl.org/dc/elements/1.1/
|
|
454
|
+
ex: http://example.org/vocab#
|
|
455
|
+
xsd: http://www.w3.org/2001/XMLSchema#
|
|
456
|
+
ex:contains:
|
|
457
|
+
"@type": "@id"
|
|
458
|
+
"@graph":
|
|
459
|
+
- "@id": http://example.org/library
|
|
460
|
+
"@type": ex:Library
|
|
461
|
+
dc:name: Library
|
|
462
|
+
ex:contains:
|
|
463
|
+
"@id": http://example.org/library/the-republic
|
|
464
|
+
"@type": ex:Book
|
|
465
|
+
dc:creator: Plato
|
|
466
|
+
dc:title: The Republic
|
|
467
|
+
ex:contains:
|
|
468
|
+
"@id": http://example.org/library/the-republic#introduction
|
|
469
|
+
"@type": ex:Chapter
|
|
470
|
+
dc:description: An introductory chapter on The Republic.
|
|
471
|
+
dc:title: The Introduction
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
}.each do |title, params|
|
|
475
|
+
it title do
|
|
476
|
+
do_frame(params)
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
describe "@reverse" do
|
|
481
|
+
{
|
|
482
|
+
"embed matched frames with @reverse": {
|
|
483
|
+
frame: %(
|
|
484
|
+
"@context":
|
|
485
|
+
ex: http://example.org/
|
|
486
|
+
"@type": ex:Type1
|
|
487
|
+
"@reverse":
|
|
488
|
+
ex:includes: {}
|
|
489
|
+
),
|
|
490
|
+
input: %(
|
|
491
|
+
- "@context":
|
|
492
|
+
ex: http://example.org/
|
|
493
|
+
"@id": ex:Sub1
|
|
494
|
+
"@type": ex:Type1
|
|
495
|
+
- "@context":
|
|
496
|
+
ex: http://example.org/
|
|
497
|
+
"@id": ex:Sub2
|
|
498
|
+
"@type": ex:Type2
|
|
499
|
+
ex:includes:
|
|
500
|
+
"@id": ex:Sub1
|
|
501
|
+
),
|
|
502
|
+
output: %(
|
|
503
|
+
"@context":
|
|
504
|
+
ex: http://example.org/
|
|
505
|
+
"@graph":
|
|
506
|
+
- "@id": ex:Sub1
|
|
507
|
+
"@type": ex:Type1
|
|
508
|
+
"@reverse":
|
|
509
|
+
ex:includes:
|
|
510
|
+
"@id": ex:Sub2
|
|
511
|
+
"@type": ex:Type2
|
|
512
|
+
ex:includes:
|
|
513
|
+
"@id": ex:Sub1
|
|
514
|
+
)
|
|
515
|
+
},
|
|
516
|
+
"embed matched frames with reversed property": {
|
|
517
|
+
frame: %(
|
|
518
|
+
"@context":
|
|
519
|
+
ex: http://example.org/
|
|
520
|
+
excludes:
|
|
521
|
+
"@reverse": ex:includes
|
|
522
|
+
"@type": ex:Type1
|
|
523
|
+
excludes: {}
|
|
524
|
+
),
|
|
525
|
+
input: %(
|
|
526
|
+
- "@context":
|
|
527
|
+
ex: http://example.org/
|
|
528
|
+
"@id": ex:Sub1
|
|
529
|
+
"@type": ex:Type1
|
|
530
|
+
- "@context":
|
|
531
|
+
ex: http://example.org/
|
|
532
|
+
"@id": ex:Sub2
|
|
533
|
+
"@type": ex:Type2
|
|
534
|
+
ex:includes:
|
|
535
|
+
"@id": ex:Sub1
|
|
536
|
+
),
|
|
537
|
+
output: %(
|
|
538
|
+
"@context":
|
|
539
|
+
ex: http://example.org/
|
|
540
|
+
excludes:
|
|
541
|
+
"@reverse": ex:includes
|
|
542
|
+
"@graph":
|
|
543
|
+
- "@id": ex:Sub1
|
|
544
|
+
"@type": ex:Type1
|
|
545
|
+
excludes:
|
|
546
|
+
"@id": ex:Sub2
|
|
547
|
+
"@type": ex:Type2
|
|
548
|
+
ex:includes:
|
|
549
|
+
"@id": ex:Sub1
|
|
550
|
+
)
|
|
551
|
+
},
|
|
552
|
+
}.each do |title, params|
|
|
553
|
+
it title do
|
|
554
|
+
do_frame(params)
|
|
555
|
+
end
|
|
556
|
+
end
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
context "omitGraph option" do
|
|
560
|
+
{
|
|
561
|
+
"Defaults to false in 1.0": {
|
|
562
|
+
input: %(
|
|
563
|
+
- http://example.org/prop:
|
|
564
|
+
- "@value": value
|
|
565
|
+
http://example.org/foo:
|
|
566
|
+
- "@value": bar
|
|
567
|
+
),
|
|
568
|
+
frame: %(
|
|
569
|
+
"@context":
|
|
570
|
+
"@vocab": http://example.org/
|
|
571
|
+
),
|
|
572
|
+
output: %(
|
|
573
|
+
"@context":
|
|
574
|
+
"@vocab": http://example.org/
|
|
575
|
+
"@graph":
|
|
576
|
+
- foo: bar
|
|
577
|
+
prop: value
|
|
578
|
+
),
|
|
579
|
+
processingMode: "json-ld-1.0"
|
|
580
|
+
},
|
|
581
|
+
"Set with option in 1.0": {
|
|
582
|
+
input: %(
|
|
583
|
+
- http://example.org/prop:
|
|
584
|
+
- "@value": value
|
|
585
|
+
http://example.org/foo:
|
|
586
|
+
- "@value": bar
|
|
587
|
+
),
|
|
588
|
+
frame: %(
|
|
589
|
+
"@context":
|
|
590
|
+
"@vocab": http://example.org/
|
|
591
|
+
),
|
|
592
|
+
output: %(
|
|
593
|
+
"@context":
|
|
594
|
+
"@vocab": http://example.org/
|
|
595
|
+
foo: bar
|
|
596
|
+
prop: value
|
|
597
|
+
),
|
|
598
|
+
processingMode: "json-ld-1.0",
|
|
599
|
+
omitGraph: true
|
|
600
|
+
},
|
|
601
|
+
"Defaults to true in 1.1": {
|
|
602
|
+
input: %(
|
|
603
|
+
- http://example.org/prop:
|
|
604
|
+
- "@value": value
|
|
605
|
+
http://example.org/foo:
|
|
606
|
+
- "@value": bar
|
|
607
|
+
),
|
|
608
|
+
frame: %(
|
|
609
|
+
"@context":
|
|
610
|
+
"@vocab": http://example.org/
|
|
611
|
+
),
|
|
612
|
+
output: %(
|
|
613
|
+
"@context":
|
|
614
|
+
"@vocab": http://example.org/
|
|
615
|
+
foo: bar
|
|
616
|
+
prop: value
|
|
617
|
+
),
|
|
618
|
+
processingMode: "json-ld-1.1"
|
|
619
|
+
},
|
|
620
|
+
"Set with option in 1.1": {
|
|
621
|
+
input: %(
|
|
622
|
+
- http://example.org/prop:
|
|
623
|
+
- "@value": value
|
|
624
|
+
http://example.org/foo:
|
|
625
|
+
- "@value": bar
|
|
626
|
+
),
|
|
627
|
+
frame: %(
|
|
628
|
+
"@context":
|
|
629
|
+
"@vocab": http://example.org/
|
|
630
|
+
),
|
|
631
|
+
output: %(
|
|
632
|
+
"@context":
|
|
633
|
+
"@vocab": http://example.org/
|
|
634
|
+
"@graph":
|
|
635
|
+
- foo: bar
|
|
636
|
+
prop: value
|
|
637
|
+
),
|
|
638
|
+
processingMode: "json-ld-1.1",
|
|
639
|
+
omitGraph: false
|
|
640
|
+
},
|
|
641
|
+
}.each do |title, params|
|
|
642
|
+
it(title) {do_frame(params.merge(pruneBlankNodeIdentifiers: true))}
|
|
643
|
+
end
|
|
644
|
+
end
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
def do_frame(params)
|
|
648
|
+
begin
|
|
649
|
+
input, frame, output = params[:input], params[:frame], params[:output]
|
|
650
|
+
params = {processingMode: 'json-ld-1.0'}.merge(params)
|
|
651
|
+
input = StringIO.new(input) if input.is_a?(String)
|
|
652
|
+
frame = StringIO.new(frame) if frame.is_a?(String)
|
|
653
|
+
yld = nil
|
|
654
|
+
if params[:write]
|
|
655
|
+
expect{yld = YAML_LD::API.frame(input, frame, logger: logger, **params)}.to write(params[:write]).to(:error)
|
|
656
|
+
else
|
|
657
|
+
expect{yld = YAML_LD::API.frame(input, frame, logger: logger, **params)}.not_to write.to(:error)
|
|
658
|
+
end
|
|
659
|
+
expect(yld).to produce_yamlld(output, logger)
|
|
660
|
+
end
|
|
661
|
+
end
|
|
662
|
+
end
|