json-ld 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/VERSION +1 -1
  4. data/lib/json/ld/api.rb +807 -771
  5. data/lib/json/ld/compact.rb +304 -304
  6. data/lib/json/ld/conneg.rb +179 -161
  7. data/lib/json/ld/context.rb +2079 -1913
  8. data/lib/json/ld/expand.rb +745 -666
  9. data/lib/json/ld/extensions.rb +14 -13
  10. data/lib/json/ld/flatten.rb +257 -247
  11. data/lib/json/ld/format.rb +202 -194
  12. data/lib/json/ld/frame.rb +525 -502
  13. data/lib/json/ld/from_rdf.rb +223 -204
  14. data/lib/json/ld/html/nokogiri.rb +123 -121
  15. data/lib/json/ld/html/rexml.rb +151 -147
  16. data/lib/json/ld/reader.rb +107 -100
  17. data/lib/json/ld/resource.rb +224 -205
  18. data/lib/json/ld/streaming_reader.rb +574 -507
  19. data/lib/json/ld/streaming_writer.rb +93 -92
  20. data/lib/json/ld/to_rdf.rb +171 -169
  21. data/lib/json/ld/utils.rb +270 -264
  22. data/lib/json/ld/version.rb +24 -14
  23. data/lib/json/ld/writer.rb +334 -311
  24. data/lib/json/ld.rb +103 -96
  25. metadata +56 -225
  26. data/spec/api_spec.rb +0 -132
  27. data/spec/compact_spec.rb +0 -3482
  28. data/spec/conneg_spec.rb +0 -373
  29. data/spec/context_spec.rb +0 -2056
  30. data/spec/expand_spec.rb +0 -4496
  31. data/spec/flatten_spec.rb +0 -1203
  32. data/spec/format_spec.rb +0 -115
  33. data/spec/frame_spec.rb +0 -2541
  34. data/spec/from_rdf_spec.rb +0 -1072
  35. data/spec/matchers.rb +0 -20
  36. data/spec/rdfstar_spec.rb +0 -25
  37. data/spec/reader_spec.rb +0 -883
  38. data/spec/resource_spec.rb +0 -76
  39. data/spec/spec_helper.rb +0 -281
  40. data/spec/streaming_reader_spec.rb +0 -237
  41. data/spec/streaming_writer_spec.rb +0 -145
  42. data/spec/suite_compact_spec.rb +0 -22
  43. data/spec/suite_expand_spec.rb +0 -36
  44. data/spec/suite_flatten_spec.rb +0 -34
  45. data/spec/suite_frame_spec.rb +0 -29
  46. data/spec/suite_from_rdf_spec.rb +0 -22
  47. data/spec/suite_helper.rb +0 -411
  48. data/spec/suite_html_spec.rb +0 -22
  49. data/spec/suite_http_spec.rb +0 -35
  50. data/spec/suite_remote_doc_spec.rb +0 -22
  51. data/spec/suite_to_rdf_spec.rb +0 -30
  52. data/spec/support/extensions.rb +0 -44
  53. data/spec/test-files/test-1-compacted.jsonld +0 -10
  54. data/spec/test-files/test-1-context.jsonld +0 -7
  55. data/spec/test-files/test-1-expanded.jsonld +0 -5
  56. data/spec/test-files/test-1-input.jsonld +0 -10
  57. data/spec/test-files/test-1-rdf.ttl +0 -8
  58. data/spec/test-files/test-2-compacted.jsonld +0 -20
  59. data/spec/test-files/test-2-context.jsonld +0 -7
  60. data/spec/test-files/test-2-expanded.jsonld +0 -16
  61. data/spec/test-files/test-2-input.jsonld +0 -20
  62. data/spec/test-files/test-2-rdf.ttl +0 -14
  63. data/spec/test-files/test-3-compacted.jsonld +0 -11
  64. data/spec/test-files/test-3-context.jsonld +0 -8
  65. data/spec/test-files/test-3-expanded.jsonld +0 -10
  66. data/spec/test-files/test-3-input.jsonld +0 -11
  67. data/spec/test-files/test-3-rdf.ttl +0 -8
  68. data/spec/test-files/test-4-compacted.jsonld +0 -10
  69. data/spec/test-files/test-4-context.jsonld +0 -7
  70. data/spec/test-files/test-4-expanded.jsonld +0 -6
  71. data/spec/test-files/test-4-input.jsonld +0 -10
  72. data/spec/test-files/test-4-rdf.ttl +0 -5
  73. data/spec/test-files/test-5-compacted.jsonld +0 -13
  74. data/spec/test-files/test-5-context.jsonld +0 -7
  75. data/spec/test-files/test-5-expanded.jsonld +0 -9
  76. data/spec/test-files/test-5-input.jsonld +0 -13
  77. data/spec/test-files/test-5-rdf.ttl +0 -7
  78. data/spec/test-files/test-6-compacted.jsonld +0 -10
  79. data/spec/test-files/test-6-context.jsonld +0 -7
  80. data/spec/test-files/test-6-expanded.jsonld +0 -10
  81. data/spec/test-files/test-6-input.jsonld +0 -10
  82. data/spec/test-files/test-6-rdf.ttl +0 -6
  83. data/spec/test-files/test-7-compacted.jsonld +0 -23
  84. data/spec/test-files/test-7-context.jsonld +0 -4
  85. data/spec/test-files/test-7-expanded.jsonld +0 -20
  86. data/spec/test-files/test-7-input.jsonld +0 -23
  87. data/spec/test-files/test-7-rdf.ttl +0 -14
  88. data/spec/test-files/test-8-compacted.jsonld +0 -34
  89. data/spec/test-files/test-8-context.jsonld +0 -11
  90. data/spec/test-files/test-8-expanded.jsonld +0 -24
  91. data/spec/test-files/test-8-frame.jsonld +0 -18
  92. data/spec/test-files/test-8-framed.jsonld +0 -25
  93. data/spec/test-files/test-8-input.jsonld +0 -30
  94. data/spec/test-files/test-8-rdf.ttl +0 -15
  95. data/spec/test-files/test-9-compacted.jsonld +0 -20
  96. data/spec/test-files/test-9-context.jsonld +0 -13
  97. data/spec/test-files/test-9-expanded.jsonld +0 -14
  98. data/spec/test-files/test-9-input.jsonld +0 -12
  99. data/spec/to_rdf_spec.rb +0 -1684
  100. data/spec/writer_spec.rb +0 -427
data/spec/frame_spec.rb DELETED
@@ -1,2541 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD::API do
5
- let(:logger) {RDF::Spec.logger}
6
-
7
- describe ".frame" do
8
- {
9
- "exact @type match": {
10
- frame: %({
11
- "@context": {"ex": "http://example.org/"},
12
- "@type": "ex:Type1"
13
- }),
14
- input: %([
15
- {
16
- "@context": {"ex": "http://example.org/"},
17
- "@id": "ex:Sub1",
18
- "@type": "ex:Type1"
19
- }, {
20
- "@context": { "ex":"http://example.org/"},
21
- "@id": "ex:Sub2",
22
- "@type": "ex:Type2"
23
- }
24
- ]),
25
- output: %({
26
- "@context": {"ex": "http://example.org/"},
27
- "@graph": [{
28
- "@id": "ex:Sub1",
29
- "@type": "ex:Type1"
30
- }]
31
- })
32
- },
33
- "wildcard @type match": {
34
- frame: %({
35
- "@context": {"ex": "http://example.org/"},
36
- "@type": {}
37
- }),
38
- input: %([
39
- {
40
- "@context": {"ex": "http://example.org/"},
41
- "@id": "ex:Sub1",
42
- "@type": "ex:Type1"
43
- }, {
44
- "@context": { "ex":"http://example.org/"},
45
- "@id": "ex:Sub2",
46
- "@type": "ex:Type2"
47
- }
48
- ]),
49
- output: %({
50
- "@context": {"ex": "http://example.org/"},
51
- "@graph": [{
52
- "@id": "ex:Sub1",
53
- "@type": "ex:Type1"
54
- }, {
55
- "@id": "ex:Sub2",
56
- "@type": "ex:Type2"
57
- }]
58
- })
59
- },
60
- "match none @type match": {
61
- frame: %({
62
- "@context": {"ex": "http://example.org/"},
63
- "@type": []
64
- }),
65
- input: %([
66
- {
67
- "@context": {"ex": "http://example.org/"},
68
- "@id": "ex:Sub1",
69
- "@type": "ex:Type1",
70
- "ex:p": "Foo"
71
- }, {
72
- "@context": { "ex":"http://example.org/"},
73
- "@id": "ex:Sub2",
74
- "ex:p": "Bar"
75
- }
76
- ]),
77
- output: %({
78
- "@context": {"ex": "http://example.org/"},
79
- "@graph": [{
80
- "@id": "ex:Sub2",
81
- "ex:p": "Bar"
82
- }]
83
- })
84
- },
85
- "multiple matches on @type": {
86
- frame: %({
87
- "@context": {"ex": "http://example.org/"},
88
- "@type": "ex:Type1"
89
- }),
90
- input: %([{
91
- "@context": {"ex": "http://example.org/"},
92
- "@id": "ex:Sub1",
93
- "@type": "ex:Type1"
94
- }, {
95
- "@context": {"ex": "http://example.org/"},
96
- "@id": "ex:Sub2",
97
- "@type": "ex:Type1"
98
- }, {
99
- "@context": {"ex": "http://example.org/"},
100
- "@id": "ex:Sub3",
101
- "@type": ["ex:Type1", "ex:Type2"]
102
- }]),
103
- output: %({
104
- "@context": {"ex": "http://example.org/"},
105
- "@graph": [{
106
- "@id": "ex:Sub1",
107
- "@type": "ex:Type1"
108
- }, {
109
- "@id": "ex:Sub2",
110
- "@type": "ex:Type1"
111
- }, {
112
- "@id": "ex:Sub3",
113
- "@type": ["ex:Type1", "ex:Type2"]
114
- }]
115
- })
116
- },
117
- "single @id match": {
118
- frame: %({
119
- "@context": {"ex": "http://example.org/"},
120
- "@id": "ex:Sub1"
121
- }),
122
- input: %([
123
- {
124
- "@context": {"ex": "http://example.org/"},
125
- "@id": "ex:Sub1",
126
- "@type": "ex:Type1"
127
- }, {
128
- "@context": { "ex":"http://example.org/"},
129
- "@id": "ex:Sub2",
130
- "@type": "ex:Type2"
131
- }
132
- ]),
133
- output: %({
134
- "@context": {"ex": "http://example.org/"},
135
- "@graph": [{
136
- "@id": "ex:Sub1",
137
- "@type": "ex:Type1"
138
- }]
139
- })
140
- },
141
- "multiple @id match": {
142
- frame: %({
143
- "@context": {"ex": "http://example.org/"},
144
- "@id": ["ex:Sub1", "ex:Sub2"]
145
- }),
146
- input: %([
147
- {
148
- "@context": {"ex": "http://example.org/"},
149
- "@id": "ex:Sub1",
150
- "@type": "ex:Type1"
151
- }, {
152
- "@context": { "ex":"http://example.org/"},
153
- "@id": "ex:Sub2",
154
- "@type": "ex:Type2"
155
- }, {
156
- "@context": { "ex":"http://example.org/"},
157
- "@id": "ex:Sub3",
158
- "@type": "ex:Type3"
159
- }
160
- ]),
161
- output: %({
162
- "@context": {"ex": "http://example.org/"},
163
- "@graph": [{
164
- "@id": "ex:Sub1",
165
- "@type": "ex:Type1"
166
- }, {
167
- "@id": "ex:Sub2",
168
- "@type": "ex:Type2"
169
- }]
170
- })
171
- },
172
- "wildcard and match none": {
173
- frame: %({
174
- "@context": {"ex": "http://example.org/"},
175
- "ex:p": [],
176
- "ex:q": {}
177
- }),
178
- input: %([
179
- {
180
- "@context": {"ex": "http://example.org/"},
181
- "@id": "ex:Sub1",
182
- "ex:q": "bar"
183
- }, {
184
- "@context": { "ex":"http://example.org/"},
185
- "@id": "ex:Sub2",
186
- "ex:p": "foo",
187
- "ex:q": "bar"
188
- }
189
- ]),
190
- output: %({
191
- "@context": {"ex": "http://example.org/"},
192
- "@graph": [{
193
- "@id": "ex:Sub1",
194
- "ex:p": null,
195
- "ex:q": "bar"
196
- }]
197
- })
198
- },
199
- "match on any property if @requireAll is false": {
200
- frame: %({
201
- "@context": {"ex": "http://example.org/"},
202
- "@requireAll": false,
203
- "ex:p": {},
204
- "ex:q": {}
205
- }),
206
- input: %([
207
- {
208
- "@context": {"ex": "http://example.org/"},
209
- "@id": "ex:Sub1",
210
- "ex:p": "foo"
211
- }, {
212
- "@context": { "ex":"http://example.org/"},
213
- "@id": "ex:Sub2",
214
- "ex:q": "bar"
215
- }
216
- ]),
217
- output: %({
218
- "@context": {"ex": "http://example.org/"},
219
- "@graph": [{
220
- "@id": "ex:Sub1",
221
- "ex:p": "foo",
222
- "ex:q": null
223
- }, {
224
- "@id": "ex:Sub2",
225
- "ex:p": null,
226
- "ex:q": "bar"
227
- }]
228
- })
229
- },
230
- "match on defeaults if @requireAll is true and at least one property matches": {
231
- frame: %({
232
- "@context": {"ex": "http://example.org/"},
233
- "@requireAll": true,
234
- "ex:p": {"@default": "Foo"},
235
- "ex:q": {"@default": "Bar"}
236
- }),
237
- input: %([
238
- {
239
- "@context": {"ex": "http://example.org/"},
240
- "@id": "ex:Sub1",
241
- "ex:p": "foo"
242
- }, {
243
- "@context": { "ex":"http://example.org/"},
244
- "@id": "ex:Sub2",
245
- "ex:q": "bar"
246
- }, {
247
- "@context": { "ex":"http://example.org/"},
248
- "@id": "ex:Sub3",
249
- "ex:p": "foo",
250
- "ex:q": "bar"
251
- }, {
252
- "@context": { "ex":"http://example.org/"},
253
- "@id": "ex:Sub4",
254
- "ex:r": "baz"
255
- }
256
- ]),
257
- output: %({
258
- "@context": {"ex": "http://example.org/"},
259
- "@graph": [{
260
- "@id": "ex:Sub1",
261
- "ex:p": "foo",
262
- "ex:q": "Bar"
263
- }, {
264
- "@id": "ex:Sub2",
265
- "ex:p": "Foo",
266
- "ex:q": "bar"
267
- }, {
268
- "@id": "ex:Sub3",
269
- "ex:p": "foo",
270
- "ex:q": "bar"
271
- }]
272
- })
273
- },
274
- "match with @requireAll with one default": {
275
- frame: %({
276
- "@context": {"ex": "http://example.org/"},
277
- "@requireAll": true,
278
- "ex:p": {},
279
- "ex:q": {"@default": "Bar"}
280
- }),
281
- input: %([
282
- {
283
- "@context": {"ex": "http://example.org/"},
284
- "@id": "ex:Sub1",
285
- "ex:p": "foo"
286
- }, {
287
- "@context": { "ex":"http://example.org/"},
288
- "@id": "ex:Sub2",
289
- "ex:q": "bar"
290
- }, {
291
- "@context": { "ex":"http://example.org/"},
292
- "@id": "ex:Sub3",
293
- "ex:p": "foo",
294
- "ex:q": "bar"
295
- }
296
- ]),
297
- output: %({
298
- "@context": {"ex": "http://example.org/"},
299
- "@graph": [{
300
- "@id": "ex:Sub1",
301
- "ex:p": "foo",
302
- "ex:q": "Bar"
303
- }, {
304
- "@id": "ex:Sub3",
305
- "ex:p": "foo",
306
- "ex:q": "bar"
307
- }]
308
- })
309
- },
310
- "don't match with @requireAll, matching @type but no matching property": {
311
- frame: %({
312
- "@context": {"ex": "http://example.org/"},
313
- "@requireAll": true,
314
- "@type": "ex:Type",
315
- "ex:p": {}
316
- }),
317
- input: %([
318
- {
319
- "@context": {"ex": "http://example.org/"},
320
- "@id": "ex:Sub1",
321
- "@type": "ex:Type",
322
- "ex:p": "foo"
323
- }, {
324
- "@context": { "ex":"http://example.org/"},
325
- "@id": "ex:Sub2",
326
- "@type": "ex:Type"
327
- }, {
328
- "@context": { "ex":"http://example.org/"},
329
- "@id": "ex:Sub3",
330
- "ex:p": "foo"
331
- }
332
- ]),
333
- output: %({
334
- "@context": {"ex": "http://example.org/"},
335
- "@graph": [{
336
- "@id": "ex:Sub1",
337
- "@type": "ex:Type",
338
- "ex:p": "foo"
339
- }]
340
- })
341
- },
342
- "don't match with @requireAll, matching @id but no matching @type": {
343
- frame: %({
344
- "@context": {"ex": "http://example.org/"},
345
- "@requireAll": true,
346
- "@id": ["ex:Sub1", "ex:Sub2"],
347
- "@type": "ex:Type"
348
- }),
349
- input: %([
350
- {
351
- "@context": {"ex": "http://example.org/"},
352
- "@id": "ex:Sub1",
353
- "@type": "ex:Type",
354
- "ex:p": "foo"
355
- }, {
356
- "@context": { "ex":"http://example.org/"},
357
- "@id": "ex:Sub2",
358
- "@type": "ex:OtherType"
359
- }, {
360
- "@context": { "ex":"http://example.org/"},
361
- "@id": "ex:Sub3",
362
- "@type": "ex:Type",
363
- "ex:p": "foo"
364
- }
365
- ]),
366
- output: %({
367
- "@context": {"ex": "http://example.org/"},
368
- "@graph": [{
369
- "@id": "ex:Sub1",
370
- "@type": "ex:Type",
371
- "ex:p": "foo"
372
- }]
373
- })
374
- },
375
- "issue #40 - example": {
376
- frame: %({
377
- "@context": {
378
- "@version": 1.1,
379
- "@vocab": "https://schema.org/"
380
- },
381
- "@type": "Person",
382
- "@requireAll": true,
383
- "givenName": "John",
384
- "familyName": "Doe"
385
- }),
386
- input: %({
387
- "@context": {
388
- "@version": 1.1,
389
- "@vocab": "https://schema.org/"
390
- },
391
- "@graph": [
392
- {
393
- "@id": "1",
394
- "@type": "Person",
395
- "name": "John Doe",
396
- "givenName": "John",
397
- "familyName": "Doe"
398
- },
399
- {
400
- "@id": "2",
401
- "@type": "Person",
402
- "name": "Jane Doe",
403
- "givenName": "Jane"
404
- }
405
- ]
406
- }),
407
- output: %({
408
- "@context": {
409
- "@version": 1.1,
410
- "@vocab": "https://schema.org/"
411
- },
412
- "@id": "1",
413
- "@type": "Person",
414
- "familyName": "Doe",
415
- "givenName": "John",
416
- "name": "John Doe"
417
- }),
418
- processingMode: 'json-ld-1.1'
419
- },
420
- "implicitly includes unframed properties (default @explicit false)": {
421
- frame: %({
422
- "@context": {"ex": "http://example.org/"},
423
- "@type": "ex:Type1"
424
- }),
425
- input: %q({
426
- "@context": {"ex": "http://example.org/"},
427
- "@id": "ex:Sub1",
428
- "@type": "ex:Type1",
429
- "ex:prop1": "Property 1",
430
- "ex:prop2": {"@id": "ex:Obj1"}
431
- }),
432
- output: %({
433
- "@context": {"ex": "http://example.org/"},
434
- "@graph": [{
435
- "@id": "ex:Sub1",
436
- "@type": "ex:Type1",
437
- "ex:prop1": "Property 1",
438
- "ex:prop2": {"@id": "ex:Obj1"}
439
- }]
440
- })
441
- },
442
- "explicitly includes unframed properties @explicit false": {
443
- frame: %({
444
- "@context": {"ex": "http://example.org/"},
445
- "@explicit": false,
446
- "@type": "ex:Type1"
447
- }),
448
- input: %q({
449
- "@context": {"ex": "http://example.org/"},
450
- "@id": "ex:Sub1",
451
- "@type": "ex:Type1",
452
- "ex:prop1": "Property 1",
453
- "ex:prop2": {"@id": "ex:Obj1"}
454
- }),
455
- output: %({
456
- "@context": {"ex": "http://example.org/"},
457
- "@graph": [{
458
- "@id": "ex:Sub1",
459
- "@type": "ex:Type1",
460
- "ex:prop1": "Property 1",
461
- "ex:prop2": {"@id": "ex:Obj1"}
462
- }]
463
- })
464
- },
465
- "explicitly excludes unframed properties (@explicit: true)": {
466
- frame: %({
467
- "@context": {"ex": "http://example.org/"},
468
- "@explicit": true,
469
- "@type": "ex:Type1"
470
- }),
471
- input: %({
472
- "@context": {"ex": "http://example.org/"},
473
- "@id": "ex:Sub1",
474
- "@type": "ex:Type1",
475
- "ex:prop1": "Property 1",
476
- "ex:prop2": {"@id": "ex:Obj1"}
477
- }),
478
- output: %({
479
- "@context": {"ex": "http://example.org/"},
480
- "@graph": [{
481
- "@id": "ex:Sub1",
482
- "@type": "ex:Type1"
483
- }]
484
- })
485
- },
486
- "non-existent framed properties create null property": {
487
- frame: %({
488
- "@context": {"ex": "http://example.org/"},
489
- "@type": "ex:Type1",
490
- "ex:null": []
491
- }),
492
- input: %({
493
- "@context": {"ex": "http://example.org/"},
494
- "@id": "ex:Sub1",
495
- "@type": "ex:Type1",
496
- "ex:prop1": "Property 1",
497
- "ex:prop2": {"@id": "ex:Obj1"}
498
- }),
499
- output: %({
500
- "@context": {
501
- "ex": "http://example.org/"
502
- },
503
- "@graph": [{
504
- "@id": "ex:Sub1",
505
- "@type": "ex:Type1",
506
- "ex:prop1": "Property 1",
507
- "ex:prop2": {
508
- "@id": "ex:Obj1"
509
- },
510
- "ex:null": null
511
- }]
512
- })
513
- },
514
- "non-existent framed properties create default property": {
515
- frame: %({
516
- "@context": {
517
- "ex": "http://example.org/",
518
- "ex:null": {"@container": "@set"}
519
- },
520
- "@type": "ex:Type1",
521
- "ex:null": [{"@default": "foo"}]
522
- }),
523
- input: %({
524
- "@context": {"ex": "http://example.org/"},
525
- "@id": "ex:Sub1",
526
- "@type": "ex:Type1",
527
- "ex:prop1": "Property 1",
528
- "ex:prop2": {"@id": "ex:Obj1"}
529
- }),
530
- output: %({
531
- "@context": {
532
- "ex": "http://example.org/",
533
- "ex:null": {"@container": "@set"}
534
- },
535
- "@graph": [{
536
- "@id": "ex:Sub1",
537
- "@type": "ex:Type1",
538
- "ex:prop1": "Property 1",
539
- "ex:prop2": {"@id": "ex:Obj1"},
540
- "ex:null": ["foo"]
541
- }]
542
- })
543
- },
544
- "default value for @type": {
545
- frame: %({
546
- "@context": {"ex": "http://example.org/"},
547
- "@type": {"@default": "ex:Foo"},
548
- "ex:foo": "bar"
549
- }),
550
- input: %({
551
- "@context": {"ex": "http://example.org/"},
552
- "@id": "ex:Sub1",
553
- "ex:foo": "bar"
554
- }),
555
- output: %({
556
- "@context": {"ex": "http://example.org/"},
557
- "@graph": [{
558
- "@id": "ex:Sub1",
559
- "@type": "ex:Foo",
560
- "ex:foo": "bar"
561
- }]
562
- })
563
- },
564
- "mixed content": {
565
- frame: %({
566
- "@context": {"ex": "http://example.org/"},
567
- "ex:mixed": {"@embed": "@never"}
568
- }),
569
- input: %({
570
- "@context": {"ex": "http://example.org/"},
571
- "@id": "ex:Sub1",
572
- "ex:mixed": [
573
- {"@id": "ex:Sub2"},
574
- "literal1"
575
- ]
576
- }),
577
- output: %({
578
- "@context": {"ex": "http://example.org/"},
579
- "@graph": [{
580
- "@id": "ex:Sub1",
581
- "ex:mixed": [
582
- {"@id": "ex:Sub2"},
583
- "literal1"
584
- ]
585
- }]
586
- })
587
- },
588
- "no embedding (@embed: @never)": {
589
- frame: %({
590
- "@context": {"ex": "http://example.org/"},
591
- "ex:embed": {"@embed": "@never"}
592
- }),
593
- input: %({
594
- "@context": {"ex": "http://example.org/"},
595
- "@id": "ex:Sub1",
596
- "ex:embed": {
597
- "@id": "ex:Sub2",
598
- "ex:prop": "property"
599
- }
600
- }),
601
- output: %({
602
- "@context": {"ex": "http://example.org/"},
603
- "@graph": [{
604
- "@id": "ex:Sub1",
605
- "ex:embed": {"@id": "ex:Sub2"}
606
- }]
607
- })
608
- },
609
- "first embed (@embed: @once)": {
610
- frame: %({
611
- "@context": {"ex": "http://www.example.com/#"},
612
- "@type": "ex:Thing",
613
- "@embed": "@once"
614
- }),
615
- input: %({
616
- "@context": {"ex": "http://www.example.com/#"},
617
- "@id": "http://example/outer",
618
- "@type": "ex:Thing",
619
- "ex:embed1": {"@id": "http://example/embedded", "ex:name": "Embedded"},
620
- "ex:embed2": {"@id": "http://example/embedded", "ex:name": "Embedded"}
621
- }),
622
- output: %({
623
- "@context": {"ex": "http://www.example.com/#"},
624
- "@graph": [
625
- {
626
- "@id": "http://example/outer",
627
- "@type": "ex:Thing",
628
- "ex:embed1": {"@id": "http://example/embedded", "ex:name": "Embedded"},
629
- "ex:embed2": {"@id": "http://example/embedded"}
630
- }
631
- ]
632
- }),
633
- ordered: true
634
- },
635
- "always embed (@embed: @always)": {
636
- frame: %({
637
- "@context": {"ex": "http://www.example.com/#"},
638
- "@type": "ex:Thing",
639
- "@embed": "@always"
640
- }),
641
- input: %({
642
- "@context": {"ex": "http://www.example.com/#"},
643
- "@id": "http://example/outer",
644
- "@type": "ex:Thing",
645
- "ex:embed1": {"@id": "http://example/embedded", "ex:name": "Embedded"},
646
- "ex:embed2": {"@id": "http://example/embedded", "ex:name": "Embedded"}
647
- }),
648
- output: %({
649
- "@context": {"ex": "http://www.example.com/#"},
650
- "@graph": [
651
- {
652
- "@id": "http://example/outer",
653
- "@type": "ex:Thing",
654
- "ex:embed1": {"@id": "http://example/embedded", "ex:name": "Embedded"},
655
- "ex:embed2": {"@id": "http://example/embedded", "ex:name": "Embedded"}
656
- }
657
- ]
658
- })
659
- },
660
- "mixed list": {
661
- frame: %({
662
- "@context": {"ex": "http://example.org/"},
663
- "ex:mixedlist": {}
664
- }),
665
- input: %({
666
- "@context": {"ex": "http://example.org/"},
667
- "@id": "ex:Sub1",
668
- "@type": "ex:Type1",
669
- "ex:mixedlist": {
670
- "@list": [
671
- {"@id": "ex:Sub2", "@type": "ex:Type2"},
672
- "literal1"
673
- ]
674
- }
675
- }),
676
- output: %({
677
- "@context": {"ex": "http://example.org/"},
678
- "@graph": [{
679
- "@id": "ex:Sub1",
680
- "@type": "ex:Type1",
681
- "ex:mixedlist": {
682
- "@list": [
683
- {"@id": "ex:Sub2", "@type": "ex:Type2"},
684
- "literal1"
685
- ]
686
- }
687
- }]
688
- })
689
- },
690
- "framed list": {
691
- frame: %({
692
- "@context": {
693
- "ex": "http://example.org/",
694
- "list": {"@id": "ex:list", "@container": "@list"}
695
- },
696
- "list": [{"@type": "ex:Element"}]
697
- }),
698
- input: %({
699
- "@context": {
700
- "ex": "http://example.org/",
701
- "list": {"@id": "ex:list", "@container": "@list"}
702
- },
703
- "@id": "ex:Sub1",
704
- "@type": "ex:Type1",
705
- "list": [
706
- {"@id": "ex:Sub2", "@type": "ex:Element"},
707
- "literal1"
708
- ]
709
- }),
710
- output: %({
711
- "@context": {
712
- "ex": "http://example.org/",
713
- "list": {"@id": "ex:list", "@container": "@list"}
714
- },
715
- "@graph": [{
716
- "@id": "ex:Sub1",
717
- "@type": "ex:Type1",
718
- "list": [
719
- {"@id": "ex:Sub2", "@type": "ex:Element"},
720
- "literal1"
721
- ]
722
- }]
723
- })
724
- },
725
- "presentation example": {
726
- frame: %({
727
- "@context": {
728
- "primaryTopic": {
729
- "@id": "http://xmlns.com/foaf/0.1/primaryTopic",
730
- "@type": "@id"
731
- },
732
- "sameAs": {
733
- "@id": "http://www.w3.org/2002/07/owl#sameAs",
734
- "@type": "@id"
735
- }
736
- },
737
- "primaryTopic": {
738
- "@type": "http://dbpedia.org/class/yago/Buzzwords",
739
- "sameAs": {}
740
- }
741
- }),
742
- input: %([{
743
- "@id": "http://en.wikipedia.org/wiki/Linked_Data",
744
- "http://xmlns.com/foaf/0.1/primaryTopic": {"@id": "http://dbpedia.org/resource/Linked_Data"}
745
- }, {
746
- "@id": "http://www4.wiwiss.fu-berlin.de/flickrwrappr/photos/Linked_Data",
747
- "http://www.w3.org/2002/07/owl#sameAs": {"@id": "http://dbpedia.org/resource/Linked_Data"}
748
- }, {
749
- "@id": "http://dbpedia.org/resource/Linked_Data",
750
- "@type": "http://dbpedia.org/class/yago/Buzzwords",
751
- "http://www.w3.org/2002/07/owl#sameAs": {"@id": "http://rdf.freebase.com/ns/m/02r2kb1"}
752
- }, {
753
- "@id": "http://mpii.de/yago/resource/Linked_Data",
754
- "http://www.w3.org/2002/07/owl#sameAs": {"@id": "http://dbpedia.org/resource/Linked_Data"}
755
- }
756
- ]),
757
- output: %({
758
- "@context": {
759
- "primaryTopic": {"@id": "http://xmlns.com/foaf/0.1/primaryTopic", "@type": "@id"},
760
- "sameAs": {"@id": "http://www.w3.org/2002/07/owl#sameAs", "@type": "@id"}
761
- },
762
- "@graph": [{
763
- "@id": "http://en.wikipedia.org/wiki/Linked_Data",
764
- "primaryTopic": {
765
- "@id": "http://dbpedia.org/resource/Linked_Data",
766
- "@type": "http://dbpedia.org/class/yago/Buzzwords",
767
- "sameAs": "http://rdf.freebase.com/ns/m/02r2kb1"
768
- }
769
- }]
770
- })
771
- },
772
- "microdata manifest": {
773
- frame: %({
774
- "@context": {
775
- "xsd": "http://www.w3.org/2001/XMLSchema#",
776
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
777
- "mf": "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
778
- "mq": "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
779
- "comment": "rdfs:comment",
780
- "entries": {"@id": "mf:entries", "@container": "@list"},
781
- "name": "mf:name",
782
- "action": "mf:action",
783
- "data": {"@id": "mq:data", "@type": "@id"},
784
- "query": {"@id": "mq:query", "@type": "@id"},
785
- "result": {"@id": "mf:result", "@type": "xsd:boolean"}
786
- },
787
- "@type": "mf:Manifest",
788
- "entries": [{
789
- "@type": "mf:ManifestEntry",
790
- "action": {
791
- "@type": "mq:QueryTest"
792
- }
793
- }]
794
- }),
795
- input: %q({
796
- "@context": {
797
- "md": "http://www.w3.org/ns/md#",
798
- "mf": "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
799
- "mq": "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
800
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
801
- },
802
- "@graph": [{
803
- "@id": "_:manifest",
804
- "@type": "mf:Manifest",
805
- "mf:entries": {"@list": [{"@id": "_:entry"}]},
806
- "rdfs:comment": "Positive processor tests"
807
- }, {
808
- "@id": "_:entry",
809
- "@type": "mf:ManifestEntry",
810
- "mf:action": {"@id": "_:query"},
811
- "mf:name": "Test 0001",
812
- "mf:result": "true",
813
- "rdfs:comment": "Item with no itemtype and literal itemprop"
814
- }, {
815
- "@id": "_:query",
816
- "@type": "mq:QueryTest",
817
- "mq:data": {"@id": "http://www.w3.org/TR/microdata-rdf/tests/0001.html"},
818
- "mq:query": {"@id": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"}
819
- }]
820
- }),
821
- output: %({
822
- "@context": {
823
- "xsd": "http://www.w3.org/2001/XMLSchema#",
824
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
825
- "mf": "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
826
- "mq": "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
827
- "comment": "rdfs:comment",
828
- "entries": {"@id": "mf:entries","@container": "@list"},
829
- "name": "mf:name",
830
- "action": "mf:action",
831
- "data": {"@id": "mq:data", "@type": "@id"},
832
- "query": {"@id": "mq:query", "@type": "@id"},
833
- "result": {"@id": "mf:result", "@type": "xsd:boolean"}
834
- },
835
- "@type": "mf:Manifest",
836
- "comment": "Positive processor tests",
837
- "entries": [{
838
- "@type": "mf:ManifestEntry",
839
- "action": {
840
- "@type": "mq:QueryTest",
841
- "data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
842
- "query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
843
- },
844
- "comment": "Item with no itemtype and literal itemprop",
845
- "mf:result": "true",
846
- "name": "Test 0001"
847
- }]
848
- }),
849
- processingMode: 'json-ld-1.1'
850
- },
851
- "library": {
852
- frame: %({
853
- "@context": {
854
- "dc": "http://purl.org/dc/elements/1.1/",
855
- "ex": "http://example.org/vocab#",
856
- "xsd": "http://www.w3.org/2001/XMLSchema#",
857
- "ex:contains": { "@type": "@id" }
858
- },
859
- "@type": "ex:Library",
860
- "ex:contains": {}
861
- }),
862
- input: %({
863
- "@context": {
864
- "dc": "http://purl.org/dc/elements/1.1/",
865
- "ex": "http://example.org/vocab#",
866
- "xsd": "http://www.w3.org/2001/XMLSchema#"
867
- },
868
- "@id": "http://example.org/library",
869
- "@type": "ex:Library",
870
- "dc:name": "Library",
871
- "ex:contains": {
872
- "@id": "http://example.org/library/the-republic",
873
- "@type": "ex:Book",
874
- "dc:creator": "Plato",
875
- "dc:title": "The Republic",
876
- "ex:contains": {
877
- "@id": "http://example.org/library/the-republic#introduction",
878
- "@type": "ex:Chapter",
879
- "dc:description": "An introductory chapter on The Republic.",
880
- "dc:title": "The Introduction"
881
- }
882
- }
883
- }),
884
- output: %({
885
- "@context": {
886
- "dc": "http://purl.org/dc/elements/1.1/",
887
- "ex": "http://example.org/vocab#",
888
- "xsd": "http://www.w3.org/2001/XMLSchema#",
889
- "ex:contains": { "@type": "@id" }
890
- },
891
- "@graph": [
892
- {
893
- "@id": "http://example.org/library",
894
- "@type": "ex:Library",
895
- "dc:name": "Library",
896
- "ex:contains": {
897
- "@id": "http://example.org/library/the-republic",
898
- "@type": "ex:Book",
899
- "dc:creator": "Plato",
900
- "dc:title": "The Republic",
901
- "ex:contains": {
902
- "@id": "http://example.org/library/the-republic#introduction",
903
- "@type": "ex:Chapter",
904
- "dc:description": "An introductory chapter on The Republic.",
905
- "dc:title": "The Introduction"
906
- }
907
- }
908
- }
909
- ]
910
- })
911
- }
912
- }.each do |title, params|
913
- it title do
914
- do_frame(params)
915
- end
916
- end
917
-
918
- describe "@reverse" do
919
- {
920
- "embed matched frames with @reverse": {
921
- frame: %({
922
- "@context": {"ex": "http://example.org/"},
923
- "@type": "ex:Type1",
924
- "@reverse": {"ex:includes": {}}
925
- }),
926
- input: %([{
927
- "@context": {"ex": "http://example.org/"},
928
- "@id": "ex:Sub1",
929
- "@type": "ex:Type1"
930
- }, {
931
- "@context": {"ex": "http://example.org/"},
932
- "@id": "ex:Sub2",
933
- "@type": "ex:Type2",
934
- "ex:includes": {"@id": "ex:Sub1"}
935
- }]),
936
- output: %({
937
- "@context": {"ex": "http://example.org/"},
938
- "@graph": [{
939
- "@id": "ex:Sub1",
940
- "@type": "ex:Type1",
941
- "@reverse": {
942
- "ex:includes": {
943
- "@id": "ex:Sub2",
944
- "@type": "ex:Type2",
945
- "ex:includes": {
946
- "@id": "ex:Sub1"
947
- }
948
- }
949
- }
950
- }]
951
- })
952
- },
953
- "embed matched frames with reversed property": {
954
- frame: %({
955
- "@context": {
956
- "ex": "http://example.org/",
957
- "excludes": {"@reverse": "ex:includes"}
958
- },
959
- "@type": "ex:Type1",
960
- "excludes": {}
961
- }),
962
- input: %([{
963
- "@context": {"ex": "http://example.org/"},
964
- "@id": "ex:Sub1",
965
- "@type": "ex:Type1"
966
- }, {
967
- "@context": {"ex": "http://example.org/"},
968
- "@id": "ex:Sub2",
969
- "@type": "ex:Type2",
970
- "ex:includes": {"@id": "ex:Sub1"}
971
- }]),
972
- output: %({
973
- "@context": {
974
- "ex": "http://example.org/",
975
- "excludes": {"@reverse": "ex:includes"}
976
- },
977
- "@graph": [{
978
- "@id": "ex:Sub1",
979
- "@type": "ex:Type1",
980
- "excludes": {
981
- "@id": "ex:Sub2",
982
- "@type": "ex:Type2",
983
- "ex:includes": {"@id": "ex:Sub1"}
984
- }
985
- }]
986
- })
987
- },
988
- }.each do |title, params|
989
- it title do
990
- do_frame(params)
991
- end
992
- end
993
- end
994
-
995
- context "omitGraph option" do
996
- {
997
- "Defaults to false in 1.0": {
998
- input: %([{
999
- "http://example.org/prop": [{"@value": "value"}],
1000
- "http://example.org/foo": [{"@value": "bar"}]
1001
- }]),
1002
- frame: %({
1003
- "@context": {
1004
- "@vocab": "http://example.org/"
1005
- }
1006
- }),
1007
- output: %({
1008
- "@context": {
1009
- "@vocab": "http://example.org/"
1010
- },
1011
- "@graph": [{
1012
- "foo": "bar",
1013
- "prop": "value"
1014
- }]
1015
- }),
1016
- processingMode: "json-ld-1.0"
1017
- },
1018
- "Set with option in 1.0": {
1019
- input: %([{
1020
- "http://example.org/prop": [{"@value": "value"}],
1021
- "http://example.org/foo": [{"@value": "bar"}]
1022
- }]),
1023
- frame: %({
1024
- "@context": {
1025
- "@vocab": "http://example.org/"
1026
- }
1027
- }),
1028
- output: %({
1029
- "@context": {
1030
- "@vocab": "http://example.org/"
1031
- },
1032
- "foo": "bar",
1033
- "prop": "value"
1034
- }),
1035
- processingMode: "json-ld-1.0",
1036
- omitGraph: true
1037
- },
1038
- "Defaults to true in 1.1": {
1039
- input: %([{
1040
- "http://example.org/prop": [{"@value": "value"}],
1041
- "http://example.org/foo": [{"@value": "bar"}]
1042
- }]),
1043
- frame: %({
1044
- "@context": {
1045
- "@vocab": "http://example.org/"
1046
- }
1047
- }),
1048
- output: %({
1049
- "@context": {
1050
- "@vocab": "http://example.org/"
1051
- },
1052
- "foo": "bar",
1053
- "prop": "value"
1054
- }),
1055
- processingMode: "json-ld-1.1"
1056
- },
1057
- "Set with option in 1.1": {
1058
- input: %([{
1059
- "http://example.org/prop": [{"@value": "value"}],
1060
- "http://example.org/foo": [{"@value": "bar"}]
1061
- }]),
1062
- frame: %({
1063
- "@context": {
1064
- "@vocab": "http://example.org/"
1065
- }
1066
- }),
1067
- output: %({
1068
- "@context": {
1069
- "@vocab": "http://example.org/"
1070
- },
1071
- "@graph": [{
1072
- "foo": "bar",
1073
- "prop": "value"
1074
- }]
1075
- }),
1076
- processingMode: "json-ld-1.1",
1077
- omitGraph: false
1078
- },
1079
- }.each do |title, params|
1080
- it(title) {do_frame(params.merge(pruneBlankNodeIdentifiers: true))}
1081
- end
1082
- end
1083
-
1084
- context "@included" do
1085
- {
1086
- "Basic Included array": {
1087
- input: %([{
1088
- "http://example.org/prop": [{"@value": "value"}],
1089
- "http://example.org/foo": [{"@value": "bar"}]
1090
- }, {
1091
- "http://example.org/prop": [{"@value": "value2"}],
1092
- "http://example.org/foo": [{"@value": "bar"}]
1093
- }]),
1094
- frame: %({
1095
- "@context": {
1096
- "@version": 1.1,
1097
- "@vocab": "http://example.org/",
1098
- "included": {"@id": "@included", "@container": "@set"}
1099
- },
1100
- "@requireAll": true,
1101
- "foo": "bar",
1102
- "prop": "value",
1103
- "@included": [{
1104
- "@requireAll": true,
1105
- "foo": "bar",
1106
- "prop": "value2"
1107
- }]
1108
- }),
1109
- output: %({
1110
- "@context": {
1111
- "@version": 1.1,
1112
- "@vocab": "http://example.org/",
1113
- "included": {"@id": "@included", "@container": "@set"}
1114
- },
1115
- "foo": "bar",
1116
- "included": [{
1117
- "foo": "bar",
1118
- "prop": "value2"
1119
- }],
1120
- "prop": "value"
1121
- })
1122
- },
1123
- "Basic Included object": {
1124
- input: %([{
1125
- "http://example.org/prop": [{"@value": "value"}],
1126
- "http://example.org/foo": [{"@value": "bar"}]
1127
- }, {
1128
- "http://example.org/prop": [{"@value": "value2"}],
1129
- "http://example.org/foo": [{"@value": "bar"}]
1130
- }]),
1131
- frame: %({
1132
- "@context": {
1133
- "@version": 1.1,
1134
- "@vocab": "http://example.org/"
1135
- },
1136
- "@requireAll": true,
1137
- "foo": "bar",
1138
- "prop": "value",
1139
- "@included": [{
1140
- "@requireAll": true,
1141
- "foo": "bar",
1142
- "prop": "value2"
1143
- }]
1144
- }),
1145
- output: %({
1146
- "@context": {
1147
- "@version": 1.1,
1148
- "@vocab": "http://example.org/"
1149
- },
1150
- "foo": "bar",
1151
- "prop": "value",
1152
- "@included": {
1153
- "prop": "value2",
1154
- "foo": "bar"
1155
- }
1156
- })
1157
- },
1158
- "json.api example": {
1159
- input: %([{
1160
- "@id": "http://example.org/base/1",
1161
- "@type": ["http://example.org/vocab#articles"],
1162
- "http://example.org/vocab#title": [{"@value": "JSON:API paints my bikeshed!"}],
1163
- "http://example.org/vocab#self": [{"@id": "http://example.com/articles/1"}],
1164
- "http://example.org/vocab#author": [{
1165
- "@id": "http://example.org/base/9",
1166
- "@type": ["http://example.org/vocab#people"],
1167
- "http://example.org/vocab#self": [{"@id": "http://example.com/articles/1/relationships/author"}],
1168
- "http://example.org/vocab#related": [{"@id": "http://example.com/articles/1/author"}]
1169
- }],
1170
- "http://example.org/vocab#comments": [{
1171
- "http://example.org/vocab#self": [{"@id": "http://example.com/articles/1/relationships/comments"}],
1172
- "http://example.org/vocab#related": [{"@id": "http://example.com/articles/1/comments"}]
1173
- }],
1174
- "@included": [{
1175
- "@id": "http://example.org/base/9",
1176
- "@type": ["http://example.org/vocab#people"],
1177
- "http://example.org/vocab#first-name": [{"@value": "Dan"}],
1178
- "http://example.org/vocab#last-name": [{"@value": "Gebhardt"}],
1179
- "http://example.org/vocab#twitter": [{"@value": "dgeb"}],
1180
- "http://example.org/vocab#self": [{"@id": "http://example.com/people/9"}]
1181
- }, {
1182
- "@id": "http://example.org/base/5",
1183
- "@type": ["http://example.org/vocab#comments"],
1184
- "http://example.org/vocab#body": [{"@value": "First!"}],
1185
- "http://example.org/vocab#author": [{
1186
- "@id": "http://example.org/base/2",
1187
- "@type": ["http://example.org/vocab#people"]
1188
- }],
1189
- "http://example.org/vocab#self": [{"@id": "http://example.com/comments/5"}]
1190
- }, {
1191
- "@id": "http://example.org/base/12",
1192
- "@type": ["http://example.org/vocab#comments"],
1193
- "http://example.org/vocab#body": [{"@value": "I like XML better"}],
1194
- "http://example.org/vocab#author": [{
1195
- "@id": "http://example.org/base/9",
1196
- "@type": ["http://example.org/vocab#people"]
1197
- }],
1198
- "http://example.org/vocab#self": [{"@id": "http://example.com/comments/12"}]
1199
- }]
1200
- }]),
1201
- frame: %({
1202
- "@context": {
1203
- "@version": 1.1,
1204
- "@vocab": "http://example.org/vocab#",
1205
- "@base": "http://example.org/base/",
1206
- "id": "@id",
1207
- "type": "@type",
1208
- "data": "@nest",
1209
- "attributes": "@nest",
1210
- "links": "@nest",
1211
- "relationships": "@nest",
1212
- "included": "@included",
1213
- "author": {"@type": "@id"},
1214
- "self": {"@type": "@id"},
1215
- "related": {"@type": "@id"},
1216
- "comments": {"@context": {"data": null}}
1217
- },
1218
- "data": {"type": "articles"},
1219
- "included": {
1220
- "@requireAll": true,
1221
- "type": ["comments", "people"],
1222
- "self": {}
1223
- }
1224
- }),
1225
- output: %({
1226
- "@context": {
1227
- "@version": 1.1,
1228
- "@vocab": "http://example.org/vocab#",
1229
- "@base": "http://example.org/base/",
1230
- "id": "@id",
1231
- "type": "@type",
1232
- "data": "@nest",
1233
- "attributes": "@nest",
1234
- "links": "@nest",
1235
- "relationships": "@nest",
1236
- "included": "@included",
1237
- "author": {"@type": "@id"},
1238
- "self": {"@type": "@id"},
1239
- "related": {"@type": "@id"},
1240
- "comments": {"@context": {"data": null}}
1241
- },
1242
- "id": "1",
1243
- "type": "articles",
1244
- "title": "JSON:API paints my bikeshed!",
1245
- "self": "http://example.com/articles/1",
1246
- "author": "9",
1247
- "comments": {
1248
- "self": "http://example.com/articles/1/relationships/comments",
1249
- "related": "http://example.com/articles/1/comments"
1250
- },
1251
- "included": [{
1252
- "id": "5",
1253
- "type": "comments",
1254
- "body": "First!",
1255
- "author": {"id": "2", "type": "people"},
1256
- "self": "http://example.com/comments/5"
1257
- }, {
1258
- "id": "9",
1259
- "type": "people",
1260
- "first-name": "Dan",
1261
- "last-name": "Gebhardt",
1262
- "twitter": "dgeb",
1263
- "self": [
1264
- "http://example.com/people/9",
1265
- "http://example.com/articles/1/relationships/author"
1266
- ],
1267
- "related": "http://example.com/articles/1/author"
1268
- }, {
1269
- "id": "12",
1270
- "type": "comments",
1271
- "body": "I like XML better",
1272
- "author": "9",
1273
- "self": "http://example.com/comments/12"
1274
- }]
1275
- }),
1276
- },
1277
- }.each do |title, params|
1278
- it(title) {do_frame(params.merge(processingMode: 'json-ld-1.1'))}
1279
- end
1280
- end
1281
-
1282
- describe "node pattern" do
1283
- {
1284
- "matches a deep node pattern": {
1285
- frame: %({
1286
- "@context": {"ex": "http://example.org/"},
1287
- "ex:p": {
1288
- "ex:q": {}
1289
- }
1290
- }),
1291
- input: %({
1292
- "@context": {"ex": "http://example.org/"},
1293
- "@graph": [{
1294
- "@id": "ex:Sub1",
1295
- "@type": "ex:Type1",
1296
- "ex:p": {
1297
- "@id": "ex:Sub2",
1298
- "@type": "ex:Type2",
1299
- "ex:q": "foo"
1300
- }
1301
- }, {
1302
- "@id": "ex:Sub3",
1303
- "@type": "ex:Type1",
1304
- "ex:q": {
1305
- "@id": "ex:Sub4",
1306
- "@type": "ex:Type2",
1307
- "ex:r": "bar"
1308
- }
1309
- }]
1310
- }),
1311
- output: %({
1312
- "@context": {"ex": "http://example.org/"},
1313
- "@graph": [{
1314
- "@id": "ex:Sub1",
1315
- "@type": "ex:Type1",
1316
- "ex:p": {
1317
- "@id": "ex:Sub2",
1318
- "@type": "ex:Type2",
1319
- "ex:q": "foo"
1320
- }
1321
- }]
1322
- })
1323
- },
1324
- }.each do |title, params|
1325
- it title do
1326
- do_frame(params)
1327
- end
1328
- end
1329
- end
1330
-
1331
- describe "value pattern" do
1332
- {
1333
- "matches exact values": {
1334
- frame: %({
1335
- "@context": {"ex": "http://example.org/"},
1336
- "ex:p": "P",
1337
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1338
- "ex:r": {"@value": "R", "@language": "r"}
1339
- }),
1340
- input: %({
1341
- "@context": {"ex": "http://example.org/"},
1342
- "@id": "ex:Sub1",
1343
- "ex:p": "P",
1344
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1345
- "ex:r": {"@value": "R", "@language": "r"}
1346
- }),
1347
- output: %({
1348
- "@context": {"ex": "http://example.org/"},
1349
- "@graph": [{
1350
- "@id": "ex:Sub1",
1351
- "ex:p": "P",
1352
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1353
- "ex:r": {"@value": "R", "@language": "r"}
1354
- }]
1355
- })
1356
- },
1357
- "matches wildcard @value": {
1358
- frame: %({
1359
- "@context": {"ex": "http://example.org/"},
1360
- "ex:p": {"@value": {}},
1361
- "ex:q": {"@value": {}, "@type": "ex:q"},
1362
- "ex:r": {"@value": {}, "@language": "r"}
1363
- }),
1364
- input: %({
1365
- "@context": {"ex": "http://example.org/"},
1366
- "@id": "ex:Sub1",
1367
- "ex:p": "P",
1368
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1369
- "ex:r": {"@value": "R", "@language": "r"}
1370
- }),
1371
- output: %({
1372
- "@context": {"ex": "http://example.org/"},
1373
- "@graph": [{
1374
- "@id": "ex:Sub1",
1375
- "ex:p": "P",
1376
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1377
- "ex:r": {"@value": "R", "@language": "r"}
1378
- }]
1379
- })
1380
- },
1381
- "matches wildcard @type": {
1382
- frame: %({
1383
- "@context": {"ex": "http://example.org/"},
1384
- "ex:q": {"@value": "Q", "@type": {}}
1385
- }),
1386
- input: %({
1387
- "@context": {"ex": "http://example.org/"},
1388
- "@id": "ex:Sub1",
1389
- "ex:q": {"@value": "Q", "@type": "ex:q"}
1390
- }),
1391
- output: %({
1392
- "@context": {"ex": "http://example.org/"},
1393
- "@graph": [{
1394
- "@id": "ex:Sub1",
1395
- "ex:q": {"@value": "Q", "@type": "ex:q"}
1396
- }]
1397
- })
1398
- },
1399
- "matches wildcard @language": {
1400
- frame: %({
1401
- "@context": {"ex": "http://example.org/"},
1402
- "ex:r": {"@value": "R", "@language": {}}
1403
- }),
1404
- input: %({
1405
- "@context": {"ex": "http://example.org/"},
1406
- "@id": "ex:Sub1",
1407
- "ex:r": {"@value": "R", "@language": "r"}
1408
- }),
1409
- output: %({
1410
- "@context": {"ex": "http://example.org/"},
1411
- "@graph": [{
1412
- "@id": "ex:Sub1",
1413
- "ex:r": {"@value": "R", "@language": "r"}
1414
- }]
1415
- })
1416
- },
1417
- "match none @type": {
1418
- frame: %({
1419
- "@context": {"ex": "http://example.org/"},
1420
- "ex:p": {"@value": {}, "@type": []},
1421
- "ex:q": {"@value": {}, "@type": "ex:q"},
1422
- "ex:r": {"@value": {}, "@language": "r"}
1423
- }),
1424
- input: %({
1425
- "@context": {"ex": "http://example.org/"},
1426
- "@id": "ex:Sub1",
1427
- "ex:p": "P",
1428
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1429
- "ex:r": {"@value": "R", "@language": "r"}
1430
- }),
1431
- output: %({
1432
- "@context": {"ex": "http://example.org/"},
1433
- "@graph": [{
1434
- "@id": "ex:Sub1",
1435
- "ex:p": "P",
1436
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1437
- "ex:r": {"@value": "R", "@language": "r"}
1438
- }]
1439
- })
1440
- },
1441
- "match none @language": {
1442
- frame: %({
1443
- "@context": {"ex": "http://example.org/"},
1444
- "ex:p": {"@value": {}, "@language": []},
1445
- "ex:q": {"@value": {}, "@type": "ex:q"},
1446
- "ex:r": {"@value": {}, "@language": "r"}
1447
- }),
1448
- input: %({
1449
- "@context": {"ex": "http://example.org/"},
1450
- "@id": "ex:Sub1",
1451
- "ex:p": "P",
1452
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1453
- "ex:r": {"@value": "R", "@language": "r"}
1454
- }),
1455
- output: %({
1456
- "@context": {"ex": "http://example.org/"},
1457
- "@graph": [{
1458
- "@id": "ex:Sub1",
1459
- "ex:p": "P",
1460
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1461
- "ex:r": {"@value": "R", "@language": "r"}
1462
- }]
1463
- })
1464
- },
1465
- "matches some @value": {
1466
- frame: %({
1467
- "@context": {"ex": "http://example.org/"},
1468
- "ex:p": {"@value": ["P", "Q", "R"]},
1469
- "ex:q": {"@value": ["P", "Q", "R"], "@type": "ex:q"},
1470
- "ex:r": {"@value": ["P", "Q", "R"], "@language": "r"}
1471
- }),
1472
- input: %({
1473
- "@context": {"ex": "http://example.org/"},
1474
- "@id": "ex:Sub1",
1475
- "ex:p": "P",
1476
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1477
- "ex:r": {"@value": "R", "@language": "r"}
1478
- }),
1479
- output: %({
1480
- "@context": {"ex": "http://example.org/"},
1481
- "@graph": [{
1482
- "@id": "ex:Sub1",
1483
- "ex:p": "P",
1484
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1485
- "ex:r": {"@value": "R", "@language": "r"}
1486
- }]
1487
- })
1488
- },
1489
- "matches some @type": {
1490
- frame: %({
1491
- "@context": {"ex": "http://example.org/"},
1492
- "ex:q": {"@value": "Q", "@type": ["ex:q", "ex:Q"]}
1493
- }),
1494
- input: %({
1495
- "@context": {"ex": "http://example.org/"},
1496
- "@id": "ex:Sub1",
1497
- "ex:q": {"@value": "Q", "@type": "ex:q"}
1498
- }),
1499
- output: %({
1500
- "@context": {"ex": "http://example.org/"},
1501
- "@graph": [{
1502
- "@id": "ex:Sub1",
1503
- "ex:q": {"@value": "Q", "@type": "ex:q"}
1504
- }]
1505
- })
1506
- },
1507
- "matches some @language": {
1508
- frame: %({
1509
- "@context": {"ex": "http://example.org/"},
1510
- "ex:r": {"@value": "R", "@language": ["p", "q", "r"]}
1511
- }),
1512
- input: %({
1513
- "@context": {"ex": "http://example.org/"},
1514
- "@id": "ex:Sub1",
1515
- "ex:r": {"@value": "R", "@language": "R"}
1516
- }),
1517
- output: %({
1518
- "@context": {"ex": "http://example.org/"},
1519
- "@graph": [{
1520
- "@id": "ex:Sub1",
1521
- "ex:r": {"@value": "R", "@language": "R"}
1522
- }]
1523
- })
1524
- },
1525
- "excludes non-matched values": {
1526
- frame: %({
1527
- "@context": {"ex": "http://example.org/"},
1528
- "ex:p": {"@value": {}},
1529
- "ex:q": {"@value": {}, "@type": "ex:q"},
1530
- "ex:r": {"@value": {}, "@language": "R"}
1531
- }),
1532
- input: %({
1533
- "@context": {"ex": "http://example.org/"},
1534
- "@id": "ex:Sub1",
1535
- "ex:p": ["P", {"@value": "P", "@type": "ex:p"}, {"@value": "P", "@language": "P"}],
1536
- "ex:q": ["Q", {"@value": "Q", "@type": "ex:q"}, {"@value": "Q", "@language": "Q"}],
1537
- "ex:r": ["R", {"@value": "R", "@type": "ex:r"}, {"@value": "R", "@language": "R"}]
1538
- }),
1539
- output: %({
1540
- "@context": {"ex": "http://example.org/"},
1541
- "@graph": [{
1542
- "@id": "ex:Sub1",
1543
- "ex:p": "P",
1544
- "ex:q": {"@value": "Q", "@type": "ex:q"},
1545
- "ex:r": {"@value": "R", "@language": "R"}
1546
- }]
1547
- })
1548
- },
1549
- }.each do |title, params|
1550
- it title do
1551
- do_frame(params)
1552
- end
1553
- end
1554
- end
1555
-
1556
- describe "named graphs" do
1557
- {
1558
- "Merge graphs if no outer @graph is used": {
1559
- frame: %({
1560
- "@context": {"@vocab": "urn:"},
1561
- "@type": "Class"
1562
- }),
1563
- input: %({
1564
- "@context": {"@vocab": "urn:"},
1565
- "@id": "urn:id-1",
1566
- "@type": "Class",
1567
- "preserve": {
1568
- "@graph": {
1569
- "@id": "urn:id-2",
1570
- "term": "data"
1571
- }
1572
- }
1573
- }),
1574
- output: %({
1575
- "@context": {"@vocab": "urn:"},
1576
- "@id": "urn:id-1",
1577
- "@type": "Class",
1578
- "preserve": {}
1579
- }),
1580
- processingMode: 'json-ld-1.1'
1581
- },
1582
- "Frame default graph if outer @graph is used": {
1583
- frame: %({
1584
- "@context": {"@vocab": "urn:"},
1585
- "@type": "Class",
1586
- "@graph": {}
1587
- }),
1588
- input: %({
1589
- "@context": {"@vocab": "urn:"},
1590
- "@id": "urn:id-1",
1591
- "@type": "Class",
1592
- "preserve": {
1593
- "@id": "urn:gr-1",
1594
- "@graph": {
1595
- "@id": "urn:id-2",
1596
- "term": "data"
1597
- }
1598
- }
1599
- }),
1600
- output: %({
1601
- "@context": {"@vocab": "urn:"},
1602
- "@id": "urn:id-1",
1603
- "@type": "Class",
1604
- "preserve": {
1605
- "@id": "urn:gr-1",
1606
- "@graph": {
1607
- "@id": "urn:id-2",
1608
- "term": "data"
1609
- }
1610
- }
1611
- }),
1612
- processingMode: 'json-ld-1.1'
1613
- },
1614
- "Merge one graph and preserve another": {
1615
- frame: %({
1616
- "@context": {"@vocab": "urn:"},
1617
- "@type": "Class",
1618
- "preserve": {
1619
- "@graph": {}
1620
- }
1621
- }),
1622
- input: %({
1623
- "@context": {"@vocab": "urn:"},
1624
- "@id": "urn:id-1",
1625
- "@type": "Class",
1626
- "merge": {
1627
- "@id": "urn:id-2",
1628
- "@graph": {
1629
- "@id": "urn:id-2",
1630
- "term": "foo"
1631
- }
1632
- },
1633
- "preserve": {
1634
- "@id": "urn:graph-1",
1635
- "@graph": {
1636
- "@id": "urn:id-3",
1637
- "term": "bar"
1638
- }
1639
- }
1640
- }),
1641
- output: %({
1642
- "@context": {"@vocab": "urn:"},
1643
- "@id": "urn:id-1",
1644
- "@type": "Class",
1645
- "merge": {
1646
- "@id": "urn:id-2",
1647
- "term": "foo"
1648
- },
1649
- "preserve": {
1650
- "@id": "urn:graph-1",
1651
- "@graph": {
1652
- "@id": "urn:id-3",
1653
- "term": "bar"
1654
- }
1655
- }
1656
- }),
1657
- processingMode: 'json-ld-1.1'
1658
- },
1659
- "Merge one graph and deep preserve another": {
1660
- frame: %({
1661
- "@context": {"@vocab": "urn:"},
1662
- "@type": "Class",
1663
- "preserve": {
1664
- "deep": {
1665
- "@graph": {}
1666
- }
1667
- }
1668
- }),
1669
- input: %({
1670
- "@context": {"@vocab": "urn:"},
1671
- "@id": "urn:id-1",
1672
- "@type": "Class",
1673
- "merge": {
1674
- "@id": "urn:id-2",
1675
- "@graph": {
1676
- "@id": "urn:id-2",
1677
- "term": "foo"
1678
- }
1679
- },
1680
- "preserve": {
1681
- "deep": {
1682
- "@graph": {
1683
- "@id": "urn:id-3",
1684
- "term": "bar"
1685
- }
1686
- }
1687
- }
1688
- }),
1689
- output: %({
1690
- "@context": {"@vocab": "urn:"},
1691
- "@id": "urn:id-1",
1692
- "@type": "Class",
1693
- "merge": {
1694
- "@id": "urn:id-2",
1695
- "term": "foo"
1696
- },
1697
- "preserve": {
1698
- "deep": {
1699
- "@graph": {
1700
- "@id": "urn:id-3",
1701
- "term": "bar"
1702
- }
1703
- }
1704
- }
1705
- }),
1706
- processingMode: 'json-ld-1.1'
1707
- },
1708
- "library": {
1709
- frame: %({
1710
- "@context": {"@vocab": "http://example.org/"},
1711
- "@type": "Library",
1712
- "contains": {
1713
- "@id": "http://example.org/graphs/books",
1714
- "@graph": {"@type": "Book"}
1715
- }
1716
- }),
1717
- input: %({
1718
- "@context": {"@vocab": "http://example.org/"},
1719
- "@id": "http://example.org/library",
1720
- "@type": "Library",
1721
- "name": "Library",
1722
- "contains": {
1723
- "@id": "http://example.org/graphs/books",
1724
- "@graph": {
1725
- "@id": "http://example.org/library/the-republic",
1726
- "@type": "Book",
1727
- "creator": "Plato",
1728
- "title": "The Republic",
1729
- "contains": {
1730
- "@id": "http://example.org/library/the-republic#introduction",
1731
- "@type": "Chapter",
1732
- "description": "An introductory chapter on The Republic.",
1733
- "title": "The Introduction"
1734
- }
1735
- }
1736
- }
1737
- }),
1738
- output: %({
1739
- "@context": {"@vocab": "http://example.org/"},
1740
- "@id": "http://example.org/library",
1741
- "@type": "Library",
1742
- "name": "Library",
1743
- "contains": {
1744
- "@id": "http://example.org/graphs/books",
1745
- "@graph": {
1746
- "@id": "http://example.org/library/the-republic",
1747
- "@type": "Book",
1748
- "creator": "Plato",
1749
- "title": "The Republic",
1750
- "contains": {
1751
- "@id": "http://example.org/library/the-republic#introduction",
1752
- "@type": "Chapter",
1753
- "description": "An introductory chapter on The Republic.",
1754
- "title": "The Introduction"
1755
- }
1756
- }
1757
- }
1758
- }),
1759
- processingMode: 'json-ld-1.1'
1760
- },
1761
- "named graph with @embed: @never": {
1762
- input: %({
1763
- "@id": "ex:cred",
1764
- "ex:subject": {
1765
- "@id": "ex:Subject",
1766
- "ex:name": "the subject"
1767
- },
1768
- "ex:proof": {
1769
- "@graph": {
1770
- "@type": "ex:Proof",
1771
- "ex:name": "the proof",
1772
- "ex:signer": [{
1773
- "@id": "ex:Subject",
1774
- "ex:name": "something different"
1775
- }]
1776
- }
1777
- }
1778
- }),
1779
- frame: %({
1780
- "@context": {
1781
- "@version": 1.1,
1782
- "proof": {"@id": "ex:proof", "@container": "@graph"}
1783
- },
1784
- "@graph": {
1785
- "proof": {"@embed": "@never"}
1786
- }
1787
- }),
1788
- output: %({
1789
- "@context": {
1790
- "@version": 1.1,
1791
- "proof": {
1792
- "@id": "ex:proof",
1793
- "@container": "@graph"
1794
- }
1795
- },
1796
- "@id": "ex:cred",
1797
- "ex:subject": {
1798
- "@id": "ex:Subject",
1799
- "ex:name": "the subject"
1800
- },
1801
- "proof": {
1802
- "@included": [
1803
- {
1804
- "@type": "ex:Proof",
1805
- "ex:name": "the proof",
1806
- "ex:signer": {
1807
- "@id": "ex:Subject"
1808
- }
1809
- },
1810
- {
1811
- "@id": "ex:Subject",
1812
- "ex:name": "something different"
1813
- }
1814
- ]
1815
- }
1816
- }),
1817
- processingMode: 'json-ld-1.1'
1818
- },
1819
- }.each do |title, params|
1820
- it title do
1821
- do_frame(params)
1822
- end
1823
- end
1824
- end
1825
- end
1826
-
1827
- describe "prune blank nodes" do
1828
- {
1829
- "preserves single-use bnode identifiers if @version 1.0": {
1830
- frame: %({
1831
- "@context": {
1832
- "dc": "http://purl.org/dc/terms/",
1833
- "dc:creator": {
1834
- "@type": "@id"
1835
- },
1836
- "foaf": "http://xmlns.com/foaf/0.1/",
1837
- "ps": "http://purl.org/payswarm#"
1838
- },
1839
- "@id": "http://example.com/asset",
1840
- "@type": "ps:Asset",
1841
- "dc:creator": {}
1842
- }),
1843
- input: %({
1844
- "@context": {
1845
- "dc": "http://purl.org/dc/terms/",
1846
- "dc:creator": {
1847
- "@type": "@id"
1848
- },
1849
- "foaf": "http://xmlns.com/foaf/0.1/",
1850
- "ps": "http://purl.org/payswarm#"
1851
- },
1852
- "@id": "http://example.com/asset",
1853
- "@type": "ps:Asset",
1854
- "dc:creator": {
1855
- "foaf:name": "John Doe"
1856
- }
1857
- }),
1858
- output: %({
1859
- "@context": {
1860
- "dc": "http://purl.org/dc/terms/",
1861
- "dc:creator": {
1862
- "@type": "@id"
1863
- },
1864
- "foaf": "http://xmlns.com/foaf/0.1/",
1865
- "ps": "http://purl.org/payswarm#"
1866
- },
1867
- "@graph": [
1868
- {
1869
- "@id": "http://example.com/asset",
1870
- "@type": "ps:Asset",
1871
- "dc:creator": {
1872
- "@id": "_:b0",
1873
- "foaf:name": "John Doe"
1874
- }
1875
- }
1876
- ]
1877
- }),
1878
- processingMode: 'json-ld-1.0'
1879
- },
1880
- "preserves single-use bnode identifiers if pruneBlankNodeIdentifiers=false": {
1881
- frame: %({
1882
- "@context": {
1883
- "dc": "http://purl.org/dc/terms/",
1884
- "dc:creator": {
1885
- "@type": "@id"
1886
- },
1887
- "foaf": "http://xmlns.com/foaf/0.1/",
1888
- "ps": "http://purl.org/payswarm#"
1889
- },
1890
- "@id": "http://example.com/asset",
1891
- "@type": "ps:Asset",
1892
- "dc:creator": {}
1893
- }),
1894
- input: %({
1895
- "@context": {
1896
- "dc": "http://purl.org/dc/terms/",
1897
- "dc:creator": {
1898
- "@type": "@id"
1899
- },
1900
- "foaf": "http://xmlns.com/foaf/0.1/",
1901
- "ps": "http://purl.org/payswarm#"
1902
- },
1903
- "@id": "http://example.com/asset",
1904
- "@type": "ps:Asset",
1905
- "dc:creator": {
1906
- "foaf:name": "John Doe"
1907
- }
1908
- }),
1909
- output: %({
1910
- "@context": {
1911
- "dc": "http://purl.org/dc/terms/",
1912
- "dc:creator": {
1913
- "@type": "@id"
1914
- },
1915
- "foaf": "http://xmlns.com/foaf/0.1/",
1916
- "ps": "http://purl.org/payswarm#"
1917
- },
1918
- "@graph": [
1919
- {
1920
- "@id": "http://example.com/asset",
1921
- "@type": "ps:Asset",
1922
- "dc:creator": {
1923
- "@id": "_:b0",
1924
- "foaf:name": "John Doe"
1925
- }
1926
- }
1927
- ]
1928
- }),
1929
- pruneBlankNodeIdentiers: false
1930
- },
1931
- "framing with @version: 1.1 prunes identifiers": {
1932
- frame: %({
1933
- "@context": {
1934
- "@version": 1.1,
1935
- "@vocab": "https://example.com#",
1936
- "ex": "http://example.org/",
1937
- "claim": {
1938
- "@id": "ex:claim",
1939
- "@container": "@graph"
1940
- },
1941
- "id": "@id"
1942
- },
1943
- "claim": {}
1944
- }),
1945
- input: %({
1946
- "@context": {
1947
- "@version": 1.1,
1948
- "@vocab": "https://example.com#",
1949
- "ex": "http://example.org/",
1950
- "claim": {
1951
- "@id": "ex:claim",
1952
- "@container": "@graph"
1953
- },
1954
- "id": "@id"
1955
- },
1956
- "claim": {
1957
- "id": "ex:1",
1958
- "test": "foo"
1959
- }
1960
- }),
1961
- output: %({
1962
- "@context": {
1963
- "@version": 1.1,
1964
- "@vocab": "https://example.com#",
1965
- "ex": "http://example.org/",
1966
- "claim": {
1967
- "@id": "ex:claim",
1968
- "@container": "@graph"
1969
- },
1970
- "id": "@id"
1971
- },
1972
- "claim": {
1973
- "id": "ex:1",
1974
- "test": "foo"
1975
- }
1976
- }),
1977
- processingMode: 'json-ld-1.1'
1978
- }
1979
- }.each do |title, params|
1980
- it title do
1981
- do_frame(params)
1982
- end
1983
- end
1984
- end
1985
-
1986
- context "problem cases" do
1987
- {
1988
- "pr #20": {
1989
- frame: %({}),
1990
- input: %([
1991
- {
1992
- "@id": "_:gregg",
1993
- "@type": "http://xmlns.com/foaf/0.1/Person",
1994
- "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
1995
- }, {
1996
- "@id": "http://manu.sporny.org/#me",
1997
- "@type": "http://xmlns.com/foaf/0.1/Person",
1998
- "http://xmlns.com/foaf/0.1/knows": {"@id": "_:gregg"},
1999
- "http://xmlns.com/foaf/0.1/name": "Manu Sporny"
2000
- }
2001
- ]),
2002
- output: %({
2003
- "@graph": [
2004
- {
2005
- "@id": "_:b0",
2006
- "@type": "http://xmlns.com/foaf/0.1/Person",
2007
- "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
2008
- },
2009
- {
2010
- "@id": "http://manu.sporny.org/#me",
2011
- "@type": "http://xmlns.com/foaf/0.1/Person",
2012
- "http://xmlns.com/foaf/0.1/knows": {
2013
- "@id": "_:b0",
2014
- "@type": "http://xmlns.com/foaf/0.1/Person",
2015
- "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
2016
- },
2017
- "http://xmlns.com/foaf/0.1/name": "Manu Sporny"
2018
- }
2019
- ]
2020
- })
2021
- },
2022
- "issue #28": {
2023
- frame: %({
2024
- "@context": {
2025
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
2026
- "talksAbout": {
2027
- "@id": "http://www.myresource.com/ontology/1.0#talksAbout",
2028
- "@type": "@id"
2029
- },
2030
- "label": {
2031
- "@id": "rdfs:label",
2032
- "@language": "en"
2033
- }
2034
- },
2035
- "@id": "http://www.myresource/uuid"
2036
- }),
2037
- input: %({
2038
- "@context": {
2039
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
2040
- },
2041
- "@id": "http://www.myresource/uuid",
2042
- "http://www.myresource.com/ontology/1.0#talksAbout": [
2043
- {
2044
- "@id": "http://rdf.freebase.com/ns/m.018w8",
2045
- "rdfs:label": [
2046
- {
2047
- "@value": "Basketball",
2048
- "@language": "en"
2049
- }
2050
- ]
2051
- }
2052
- ]
2053
- }),
2054
- output: %({
2055
- "@context": {
2056
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
2057
- "talksAbout": {
2058
- "@id": "http://www.myresource.com/ontology/1.0#talksAbout",
2059
- "@type": "@id"
2060
- },
2061
- "label": {
2062
- "@id": "rdfs:label",
2063
- "@language": "en"
2064
- }
2065
- },
2066
- "@graph": [
2067
- {
2068
- "@id": "http://www.myresource/uuid",
2069
- "talksAbout": {
2070
- "@id": "http://rdf.freebase.com/ns/m.018w8",
2071
- "label": "Basketball"
2072
- }
2073
- }
2074
- ]
2075
- })
2076
- },
2077
- "PR #663 - Multiple named graphs": {
2078
- frame: %({
2079
- "@context": {
2080
- "@vocab": "http://example.com/",
2081
- "loves": {"@type": "@id"},
2082
- "unionOf": {
2083
- "@type": "@id",
2084
- "@id": "owl:unionOf",
2085
- "@container": "@list"
2086
- },
2087
- "Class": "owl:Class"
2088
- },
2089
- "@graph": [
2090
- {
2091
- "@explicit": false,
2092
- "@embed": "@once",
2093
- "@type": ["Act", "Class"],
2094
- "@graph": [{
2095
- "@explicit": true,
2096
- "@embed": "@always",
2097
- "@type": "Person",
2098
- "@id": {},
2099
- "loves": {"@embed": "@never"}
2100
- }]
2101
- }
2102
- ]
2103
- }),
2104
- input: %({
2105
- "@context": {
2106
- "@vocab": "http://example.com/",
2107
- "loves": {"@type": "@id"},
2108
- "unionOf": {
2109
- "@type": "@id",
2110
- "@id": "owl:unionOf",
2111
- "@container": "@list"
2112
- },
2113
- "Class": "owl:Class"
2114
- },
2115
- "@graph": [{
2116
- "@type": "Act",
2117
- "@graph": [
2118
- {"@id": "Romeo", "@type": "Person"},
2119
- {"@id": "Juliet", "@type": "Person"}
2120
- ]
2121
- }, {
2122
- "@id": "ActTwo",
2123
- "@type": "Act",
2124
- "@graph": [
2125
- {"@id": "Romeo", "@type": "Person", "loves": "Juliet"},
2126
- {"@id": "Juliet", "@type": "Person", "loves": "Romeo"}
2127
- ]
2128
- }, {
2129
- "@id": "Person",
2130
- "@type": "Class",
2131
- "unionOf": {
2132
- "@list": [
2133
- {"@id": "Montague", "@type": "Class"},
2134
- {"@id": "Capulet", "@type": "Class"}
2135
- ]
2136
- }
2137
- }]
2138
- }),
2139
- output: %({
2140
- "@context": {
2141
- "@vocab": "http://example.com/",
2142
- "loves": {"@type": "@id"},
2143
- "unionOf": {
2144
- "@type": "@id",
2145
- "@id": "owl:unionOf",
2146
- "@container": "@list"
2147
- },
2148
- "Class": "owl:Class"
2149
- },
2150
- "@graph": [{
2151
- "@id": "ActTwo",
2152
- "@type": "Act",
2153
- "@graph": [
2154
- {"@id": "Juliet", "@type": "Person", "loves": "Romeo"},
2155
- {"@id": "Romeo", "@type": "Person", "loves": "Juliet"}
2156
- ]
2157
- }, {
2158
- "@id": "Capulet",
2159
- "@type": "Class"
2160
- }, {
2161
- "@id": "Montague",
2162
- "@type": "Class"
2163
- }, {
2164
- "@id": "Person",
2165
- "@type": "Class",
2166
- "unionOf": [
2167
- {"@id": "Montague", "@type": "Class"},
2168
- {"@id": "Capulet", "@type": "Class"}
2169
- ]
2170
- }, {
2171
- "@type": "Act",
2172
- "@graph": [
2173
- {
2174
- "@id": "Juliet",
2175
- "@type": "Person",
2176
- "loves": null
2177
- }, {
2178
- "@id": "Romeo",
2179
- "@type": "Person",
2180
- "loves": null
2181
- }
2182
- ]
2183
- }]
2184
- }),
2185
- processingMode: 'json-ld-1.1'
2186
- },
2187
- "w3c/json-ld-framing#5": {
2188
- frame: %({
2189
- "@context" : {
2190
- "@vocab" : "http://purl.bdrc.io/ontology/core/",
2191
- "taxSubclassOf" : {
2192
- "@id" : "http://purl.bdrc.io/ontology/core/taxSubclassOf",
2193
- "@type" : "@id"
2194
- },
2195
- "bdr" : "http://purl.bdrc.io/resource/",
2196
- "children": { "@reverse": "http://purl.bdrc.io/ontology/core/taxSubclassOf" }
2197
- },
2198
- "@id" : "bdr:O9TAXTBRC201605",
2199
- "children": {
2200
- "children": {
2201
- "children": {}
2202
- }
2203
- }
2204
- }),
2205
- input: %({
2206
- "@context": {
2207
- "@vocab": "http://purl.bdrc.io/ontology/core/",
2208
- "taxSubclassOf": {
2209
- "@id": "http://purl.bdrc.io/ontology/core/taxSubclassOf",
2210
- "@type": "@id"
2211
- },
2212
- "bdr": "http://purl.bdrc.io/resource/"
2213
- },
2214
- "@graph": [{
2215
- "@id": "bdr:O9TAXTBRC201605",
2216
- "@type": "Taxonomy"
2217
- }, {
2218
- "@id": "bdr:O9TAXTBRC201605_0001",
2219
- "@type": "Taxonomy",
2220
- "taxSubclassOf": "bdr:O9TAXTBRC201605"
2221
- }, {
2222
- "@id": "bdr:O9TAXTBRC201605_0002",
2223
- "@type": "Taxonomy",
2224
- "taxSubclassOf": "bdr:O9TAXTBRC201605_0001"
2225
- }, {
2226
- "@id": "bdr:O9TAXTBRC201605_0010",
2227
- "@type": "Taxonomy",
2228
- "taxSubclassOf": "bdr:O9TAXTBRC201605"
2229
- }]
2230
- }),
2231
- output: %({
2232
- "@context" : {
2233
- "@vocab" : "http://purl.bdrc.io/ontology/core/",
2234
- "taxSubclassOf" : {
2235
- "@id" : "http://purl.bdrc.io/ontology/core/taxSubclassOf",
2236
- "@type" : "@id"
2237
- },
2238
- "bdr" : "http://purl.bdrc.io/resource/",
2239
- "children": { "@reverse": "http://purl.bdrc.io/ontology/core/taxSubclassOf" }
2240
- },
2241
- "@id" : "bdr:O9TAXTBRC201605",
2242
- "@type": "Taxonomy",
2243
- "children": [{
2244
- "@id": "bdr:O9TAXTBRC201605_0001",
2245
- "@type": "Taxonomy",
2246
- "taxSubclassOf": "bdr:O9TAXTBRC201605",
2247
- "children": {
2248
- "@id": "bdr:O9TAXTBRC201605_0002",
2249
- "@type": "Taxonomy",
2250
- "taxSubclassOf": "bdr:O9TAXTBRC201605_0001"
2251
- }
2252
- }, {
2253
- "@id": "bdr:O9TAXTBRC201605_0010",
2254
- "@type": "Taxonomy",
2255
- "taxSubclassOf": "bdr:O9TAXTBRC201605"
2256
- }]
2257
- }),
2258
- processingMode: 'json-ld-1.1'
2259
- },
2260
- "issue json-ld-framing#30": {
2261
- input: %({
2262
- "@context": {"eg": "https://example.org/ns/"},
2263
- "@id": "https://example.org/what",
2264
- "eg:sameAs": "https://example.org/what",
2265
- "eg:age": 42
2266
- }),
2267
- frame: %({
2268
- "@context": {"eg": "https://example.org/ns/"},
2269
- "@id": "https://example.org/what"
2270
- }),
2271
- output: %({
2272
- "@context": {"eg": "https://example.org/ns/"},
2273
- "@graph": [{
2274
- "@id": "https://example.org/what",
2275
- "eg:age": 42,
2276
- "eg:sameAs": "https://example.org/what"
2277
- }]
2278
- })
2279
- },
2280
- "issue json-ld-framing#64": {
2281
- input: %({
2282
- "@context": {
2283
- "@version": 1.1,
2284
- "@vocab": "http://example.org/vocab#"
2285
- },
2286
- "@id": "http://example.org/1",
2287
- "@type": "HumanMadeObject",
2288
- "produced_by": {
2289
- "@type": "Production",
2290
- "_label": "Top Production",
2291
- "part": {
2292
- "@type": "Production",
2293
- "_label": "Test Part"
2294
- }
2295
- }
2296
- }),
2297
- frame: %({
2298
- "@context": {
2299
- "@version": 1.1,
2300
- "@vocab": "http://example.org/vocab#",
2301
- "Production": {
2302
- "@context": {
2303
- "part": {
2304
- "@type": "@id",
2305
- "@container": "@set"
2306
- }
2307
- }
2308
- }
2309
- },
2310
- "@id": "http://example.org/1"
2311
- }),
2312
- output: %({
2313
- "@context": {
2314
- "@version": 1.1,
2315
- "@vocab": "http://example.org/vocab#",
2316
- "Production": {
2317
- "@context": {
2318
- "part": {
2319
- "@type": "@id",
2320
- "@container": "@set"
2321
- }
2322
- }
2323
- }
2324
- },
2325
- "@id": "http://example.org/1",
2326
- "@type": "HumanMadeObject",
2327
- "produced_by": {
2328
- "@type": "Production",
2329
- "part": [{
2330
- "@type": "Production",
2331
- "_label": "Test Part"
2332
- }],
2333
- "_label": "Top Production"
2334
- }
2335
- }),
2336
- processingMode: "json-ld-1.1"
2337
- },
2338
- "issue json-ld-framing#27": {
2339
- input: %({
2340
- "@id": "ex:cred",
2341
- "ex:subject": {
2342
- "@id": "ex:Subject",
2343
- "ex:name": "the subject",
2344
- "ex:knows": {
2345
- "@id": "ex:issuer",
2346
- "ex:name": "Someone else"
2347
- }
2348
- },
2349
- "ex:proof": {
2350
- "@graph": {
2351
- "@type": "ex:Proof",
2352
- "ex:name": "the proof",
2353
- "ex:signer": [{
2354
- "@id": "ex:Subject",
2355
- "ex:name": "something different"
2356
- }]
2357
- }
2358
- }
2359
- }),
2360
- frame: %({
2361
- "@context": {
2362
- "@version": 1.1,
2363
- "proof": {"@id": "ex:proof", "@container": "@graph"}
2364
- },
2365
- "@graph": {
2366
- "subject": {},
2367
- "proof": {}
2368
- }
2369
- }),
2370
- output: %({
2371
- "@context": {
2372
- "@version": 1.1,
2373
- "proof": {
2374
- "@id": "ex:proof",
2375
- "@container": "@graph"
2376
- }
2377
- },
2378
- "@id": "ex:cred",
2379
- "ex:subject": {
2380
- "@id": "ex:Subject",
2381
- "ex:name": "the subject",
2382
- "ex:knows": {
2383
- "@id": "ex:issuer",
2384
- "ex:name": "Someone else"
2385
- }
2386
- },
2387
- "proof": {
2388
- "@type": "ex:Proof",
2389
- "ex:name": "the proof",
2390
- "ex:signer": {
2391
- "@id": "ex:Subject",
2392
- "ex:name": "something different"
2393
- }
2394
- }
2395
- }),
2396
- processingMode: "json-ld-1.1"
2397
- },
2398
- "missing types": {
2399
- input: %({
2400
- "@context": {
2401
- "ex": "http://example.com#",
2402
- "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
2403
- },
2404
- "@graph": [{
2405
- "@id": "ex:graph1",
2406
- "@graph": [{
2407
- "@id": "ex:entity1",
2408
- "@type": ["ex:Type1","ex:Type2"],
2409
- "ex:title": "some title",
2410
- "ex:multipleValues": "ex:One"
2411
- }]
2412
- }, {
2413
- "@id": "ex:graph2",
2414
- "@graph": [{
2415
- "@id": "ex:entity1",
2416
- "@type": "ex:Type3",
2417
- "ex:tags": "tag1 tag2",
2418
- "ex:multipleValues": ["ex:Two","ex:Three"]
2419
- }]
2420
- }]
2421
- }),
2422
- output: %({
2423
- "@context": {
2424
- "ex": "http://example.com#",
2425
- "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
2426
- },
2427
- "@id": "ex:entity1",
2428
- "@type": ["ex:Type1", "ex:Type2", "ex:Type3"],
2429
- "ex:multipleValues": ["ex:One", "ex:Two","ex:Three"],
2430
- "ex:tags": "tag1 tag2",
2431
- "ex:title": "some title"
2432
- }),
2433
- frame: %({
2434
- "@context": {
2435
- "ex": "http://example.com#",
2436
- "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
2437
- },
2438
- "@id": "ex:entity1"
2439
- }),
2440
- processingMode: "json-ld-1.1"
2441
- },
2442
- "don't embed list elements": {
2443
- frame: %({
2444
- "@context": {"ex": "http://example.org/"},
2445
- "ex:embed": {
2446
- "@list": [{"@embed": "@never"}]
2447
- }
2448
- }),
2449
- input: %({
2450
- "@context": {"ex": "http://example.org/"},
2451
- "@id": "ex:Sub1",
2452
- "ex:embed": {
2453
- "@list": [{
2454
- "@id": "ex:Sub2",
2455
- "ex:prop": "property"
2456
- }]
2457
- }
2458
- }),
2459
- output: %({
2460
- "@context": {"ex": "http://example.org/"},
2461
- "@id": "ex:Sub1",
2462
- "ex:embed": {"@list": [{"@id": "ex:Sub2"}]}
2463
- }),
2464
- processingMode: "json-ld-1.1"
2465
- },
2466
- "issue #142": {
2467
- input: %({
2468
- "@context":{
2469
- "ex":"http://example.org/vocab#",
2470
- "ex:info":{"@type":"@json"},
2471
- "ex:other":{"@type":"@json"}
2472
- },
2473
- "@id":"http://example.org/test/#library",
2474
- "@type":"ex:Library",
2475
- "ex:info":{
2476
- "author":"JOHN",
2477
- "pages":200
2478
- },
2479
- "ex:other":{
2480
- "publisher":"JANE"
2481
- }
2482
- }),
2483
- frame: %({
2484
- "@context":{
2485
- "ex":"http://example.org/vocab#",
2486
- "ex:info":{"@type":"@json"},
2487
- "ex:other":{"@type":"@json"}
2488
- },
2489
- "http://example.org/vocab#info":{}
2490
- }),
2491
- output: %({
2492
- "@context": {
2493
- "ex": "http://example.org/vocab#",
2494
- "ex:info": {"@type": "@json"},
2495
- "ex:other": {"@type": "@json"}
2496
- },
2497
- "@id": "http://example.org/test/#library",
2498
- "@type": "ex:Library",
2499
- "ex:info": {
2500
- "author": "JOHN",
2501
- "pages": 200
2502
- },
2503
- "ex:other": {
2504
- "publisher": "JANE"
2505
- }
2506
- }),
2507
- processingMode: "json-ld-1.1"
2508
- }
2509
- }.each do |title, params|
2510
- it title do
2511
- do_frame(params)
2512
- end
2513
- end
2514
- end
2515
-
2516
- def do_frame(params)
2517
- begin
2518
- input, frame, output = params[:input], params[:frame], params[:output]
2519
- params = {processingMode: 'json-ld-1.0'}.merge(params)
2520
- input = ::JSON.parse(input) if input.is_a?(String)
2521
- frame = ::JSON.parse(frame) if frame.is_a?(String)
2522
- output = ::JSON.parse(output) if output.is_a?(String)
2523
- jld = nil
2524
- if params[:write]
2525
- expect{jld = JSON::LD::API.frame(input, frame, logger: logger, **params)}.to write(params[:write]).to(:error)
2526
- else
2527
- expect{jld = JSON::LD::API.frame(input, frame, logger: logger, **params)}.not_to write.to(:error)
2528
- end
2529
- expect(jld).to produce_jsonld(output, logger)
2530
-
2531
- # Compare expanded jld/output too to make sure list values remain ordered
2532
- exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
2533
- exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
2534
- expect(exp_jld).to produce_jsonld(exp_output, logger)
2535
- rescue JSON::LD::JsonLdError => e
2536
- fail("#{e.class}: #{e.message}\n" +
2537
- "#{logger}\n" +
2538
- "Backtrace:\n#{e.backtrace.join("\n")}")
2539
- end
2540
- end
2541
- end