json-ld 3.2.3 → 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -764
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1945
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +224 -166
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -167
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +78 -209
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2036
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2498
- data/spec/from_rdf_spec.rb +0 -1005
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1551
- data/spec/writer_spec.rb +0 -427
data/spec/compact_spec.rb
DELETED
@@ -1,3482 +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 ".compact" do
|
8
|
-
{
|
9
|
-
"prefix" => {
|
10
|
-
input: %({
|
11
|
-
"@id": "http://example.com/a",
|
12
|
-
"http://example.com/b": {"@id": "http://example.com/c"}
|
13
|
-
}),
|
14
|
-
context: %({"ex": "http://example.com/"}),
|
15
|
-
output: %({
|
16
|
-
"@context": {"ex": "http://example.com/"},
|
17
|
-
"@id": "ex:a",
|
18
|
-
"ex:b": {"@id": "ex:c"}
|
19
|
-
})
|
20
|
-
},
|
21
|
-
"term" => {
|
22
|
-
input: %({
|
23
|
-
"@id": "http://example.com/a",
|
24
|
-
"http://example.com/b": {"@id": "http://example.com/c"}
|
25
|
-
}),
|
26
|
-
context: %({"b": "http://example.com/b"}),
|
27
|
-
output: %({
|
28
|
-
"@context": {"b": "http://example.com/b"},
|
29
|
-
"@id": "http://example.com/a",
|
30
|
-
"b": {"@id": "http://example.com/c"}
|
31
|
-
})
|
32
|
-
},
|
33
|
-
"integer value" => {
|
34
|
-
input: %({
|
35
|
-
"@id": "http://example.com/a",
|
36
|
-
"http://example.com/b": {"@value": 1}
|
37
|
-
}),
|
38
|
-
context: %({"b": "http://example.com/b"}),
|
39
|
-
output: %({
|
40
|
-
"@context": {"b": "http://example.com/b"},
|
41
|
-
"@id": "http://example.com/a",
|
42
|
-
"b": 1
|
43
|
-
})
|
44
|
-
},
|
45
|
-
"boolean value" => {
|
46
|
-
input: %({
|
47
|
-
"@id": "http://example.com/a",
|
48
|
-
"http://example.com/b": {"@value": true}
|
49
|
-
}),
|
50
|
-
context: %({"b": "http://example.com/b"}),
|
51
|
-
output: %({
|
52
|
-
"@context": {"b": "http://example.com/b"},
|
53
|
-
"@id": "http://example.com/a",
|
54
|
-
"b": true
|
55
|
-
})
|
56
|
-
},
|
57
|
-
"@id" => {
|
58
|
-
input: %({"@id": "http://example.org/test#example"}),
|
59
|
-
context: {},
|
60
|
-
output: {}
|
61
|
-
},
|
62
|
-
"@id coercion" => {
|
63
|
-
input: %({
|
64
|
-
"@id": "http://example.com/a",
|
65
|
-
"http://example.com/b": {"@id": "http://example.com/c"}
|
66
|
-
}),
|
67
|
-
context: %({"b": {"@id": "http://example.com/b", "@type": "@id"}}),
|
68
|
-
output: %({
|
69
|
-
"@context": {"b": {"@id": "http://example.com/b", "@type": "@id"}},
|
70
|
-
"@id": "http://example.com/a",
|
71
|
-
"b": "http://example.com/c"
|
72
|
-
})
|
73
|
-
},
|
74
|
-
"xsd:date coercion" => {
|
75
|
-
input: %({
|
76
|
-
"http://example.com/b": {"@value": "2012-01-04", "@type": "http://www.w3.org/2001/XMLSchema#date"}
|
77
|
-
}),
|
78
|
-
context: %({
|
79
|
-
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
80
|
-
"b": {"@id": "http://example.com/b", "@type": "xsd:date"}
|
81
|
-
}),
|
82
|
-
output: %({
|
83
|
-
"@context": {
|
84
|
-
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
85
|
-
"b": {"@id": "http://example.com/b", "@type": "xsd:date"}
|
86
|
-
},
|
87
|
-
"b": "2012-01-04"
|
88
|
-
})
|
89
|
-
},
|
90
|
-
"@list coercion": {
|
91
|
-
input: %({
|
92
|
-
"http://example.com/b": {"@list": ["c", "d"]}
|
93
|
-
}),
|
94
|
-
context: %({"b": {"@id": "http://example.com/b", "@container": "@list"}}),
|
95
|
-
output: %({
|
96
|
-
"@context": {"b": {"@id": "http://example.com/b", "@container": "@list"}},
|
97
|
-
"b": ["c", "d"]
|
98
|
-
})
|
99
|
-
},
|
100
|
-
"@list coercion (integer)" => {
|
101
|
-
input: %({
|
102
|
-
"http://example.com/term": [
|
103
|
-
{"@list": [1]}
|
104
|
-
]
|
105
|
-
}),
|
106
|
-
context: %({
|
107
|
-
"term4": {"@id": "http://example.com/term", "@container": "@list"},
|
108
|
-
"@language": "de"
|
109
|
-
}),
|
110
|
-
output: %({
|
111
|
-
"@context": {
|
112
|
-
"term4": {"@id": "http://example.com/term", "@container": "@list"},
|
113
|
-
"@language": "de"
|
114
|
-
},
|
115
|
-
"term4": [1]
|
116
|
-
})
|
117
|
-
},
|
118
|
-
"@set coercion" => {
|
119
|
-
input: %({
|
120
|
-
"http://example.com/b": {"@set": ["c"]}
|
121
|
-
}),
|
122
|
-
context: %({"b": {"@id": "http://example.com/b", "@container": "@set"}}),
|
123
|
-
output: %({
|
124
|
-
"@context": {"b": {"@id": "http://example.com/b", "@container": "@set"}},
|
125
|
-
"b": ["c"]
|
126
|
-
})
|
127
|
-
},
|
128
|
-
"@set coercion on @type" => {
|
129
|
-
input: %({
|
130
|
-
"@type": "http://www.w3.org/2000/01/rdf-schema#Resource",
|
131
|
-
"http://example.org/foo": {"@value": "bar", "@type": "http://example.com/type"}
|
132
|
-
}),
|
133
|
-
context: %({"@version": 1.1, "@type": {"@container": "@set"}}),
|
134
|
-
output: %({
|
135
|
-
"@context": {"@version": 1.1, "@type": {"@container": "@set"}},
|
136
|
-
"@type": ["http://www.w3.org/2000/01/rdf-schema#Resource"],
|
137
|
-
"http://example.org/foo": {"@value": "bar", "@type": "http://example.com/type"}
|
138
|
-
})
|
139
|
-
},
|
140
|
-
"empty @set coercion" => {
|
141
|
-
input: %({
|
142
|
-
"http://example.com/b": []
|
143
|
-
}),
|
144
|
-
context: %({"b": {"@id": "http://example.com/b", "@container": "@set"}}),
|
145
|
-
output: %({
|
146
|
-
"@context": {"b": {"@id": "http://example.com/b", "@container": "@set"}},
|
147
|
-
"b": []
|
148
|
-
})
|
149
|
-
},
|
150
|
-
"@type with string @id" => {
|
151
|
-
input: %({
|
152
|
-
"@id": "http://example.com/",
|
153
|
-
"@type": "#{RDF::RDFS.Resource}"
|
154
|
-
}),
|
155
|
-
context: {},
|
156
|
-
output: %({
|
157
|
-
"@id": "http://example.com/",
|
158
|
-
"@type": "#{RDF::RDFS.Resource}"
|
159
|
-
}),
|
160
|
-
},
|
161
|
-
"@type with array @id" => {
|
162
|
-
input: %({
|
163
|
-
"@id": "http://example.com/",
|
164
|
-
"@type": ["#{RDF::RDFS.Resource}"]
|
165
|
-
}),
|
166
|
-
context: {},
|
167
|
-
output: %({
|
168
|
-
"@id": "http://example.com/",
|
169
|
-
"@type": "#{RDF::RDFS.Resource}"
|
170
|
-
}),
|
171
|
-
},
|
172
|
-
"default language" => {
|
173
|
-
input: %({
|
174
|
-
"http://example.com/term": [
|
175
|
-
"v5",
|
176
|
-
{"@value": "plain literal"}
|
177
|
-
]
|
178
|
-
}),
|
179
|
-
context: %({
|
180
|
-
"term5": {"@id": "http://example.com/term", "@language": null},
|
181
|
-
"@language": "de"
|
182
|
-
}),
|
183
|
-
output: %({
|
184
|
-
"@context": {
|
185
|
-
"term5": {"@id": "http://example.com/term", "@language": null},
|
186
|
-
"@language": "de"
|
187
|
-
},
|
188
|
-
"term5": [ "v5", "plain literal" ]
|
189
|
-
})
|
190
|
-
},
|
191
|
-
"default direction" => {
|
192
|
-
input: %({
|
193
|
-
"http://example.com/term": [
|
194
|
-
"v5",
|
195
|
-
{"@value": "plain literal"}
|
196
|
-
]
|
197
|
-
}),
|
198
|
-
context: %({
|
199
|
-
"term5": {"@id": "http://example.com/term", "@direction": null},
|
200
|
-
"@direction": "ltr"
|
201
|
-
}),
|
202
|
-
output: %({
|
203
|
-
"@context": {
|
204
|
-
"term5": {"@id": "http://example.com/term", "@direction": null},
|
205
|
-
"@direction": "ltr"
|
206
|
-
},
|
207
|
-
"term5": [ "v5", "plain literal" ]
|
208
|
-
})
|
209
|
-
},
|
210
|
-
}.each_pair do |title, params|
|
211
|
-
it(title) {run_compact(params)}
|
212
|
-
end
|
213
|
-
|
214
|
-
context "keyword aliasing" do
|
215
|
-
{
|
216
|
-
"@id" => {
|
217
|
-
input: %({
|
218
|
-
"@id": "",
|
219
|
-
"@type": "#{RDF::RDFS.Resource}"
|
220
|
-
}),
|
221
|
-
context: %({"id": "@id"}),
|
222
|
-
output: %({
|
223
|
-
"@context": {"id": "@id"},
|
224
|
-
"id": "",
|
225
|
-
"@type": "#{RDF::RDFS.Resource}"
|
226
|
-
})
|
227
|
-
},
|
228
|
-
"@type": {
|
229
|
-
input: %({
|
230
|
-
"@type": "http://www.w3.org/2000/01/rdf-schema#Resource",
|
231
|
-
"http://example.org/foo": {"@value": "bar", "@type": "http://example.com/type"}
|
232
|
-
}),
|
233
|
-
context: %({"type": "@type"}),
|
234
|
-
output: %({
|
235
|
-
"@context": {"type": "@type"},
|
236
|
-
"type": "http://www.w3.org/2000/01/rdf-schema#Resource",
|
237
|
-
"http://example.org/foo": {"@value": "bar", "type": "http://example.com/type"}
|
238
|
-
})
|
239
|
-
},
|
240
|
-
"@type with @container: @set": {
|
241
|
-
input: %({
|
242
|
-
"@type": "http://www.w3.org/2000/01/rdf-schema#Resource",
|
243
|
-
"http://example.org/foo": {"@value": "bar", "@type": "http://example.com/type"}
|
244
|
-
}),
|
245
|
-
context: %({"type": {"@id": "@type", "@container": "@set"}}),
|
246
|
-
output: %({
|
247
|
-
"@context": {"type": {"@id": "@type", "@container": "@set"}},
|
248
|
-
"type": ["http://www.w3.org/2000/01/rdf-schema#Resource"],
|
249
|
-
"http://example.org/foo": {"@value": "bar", "type": "http://example.com/type"}
|
250
|
-
}),
|
251
|
-
processingMode: 'json-ld-1.1'
|
252
|
-
},
|
253
|
-
"@language" => {
|
254
|
-
input: %({
|
255
|
-
"http://example.org/foo": {"@value": "bar", "@language": "baz"}
|
256
|
-
}),
|
257
|
-
context: %({"language": "@language"}),
|
258
|
-
output: %({
|
259
|
-
"@context": {"language": "@language"},
|
260
|
-
"http://example.org/foo": {"@value": "bar", "language": "baz"}
|
261
|
-
})
|
262
|
-
},
|
263
|
-
"@direction" => {
|
264
|
-
input: %({
|
265
|
-
"http://example.org/foo": {"@value": "bar", "@direction": "ltr"}
|
266
|
-
}),
|
267
|
-
context: %({"direction": "@direction"}),
|
268
|
-
output: %({
|
269
|
-
"@context": {"direction": "@direction"},
|
270
|
-
"http://example.org/foo": {"@value": "bar", "direction": "ltr"}
|
271
|
-
})
|
272
|
-
},
|
273
|
-
"@value" => {
|
274
|
-
input: %({
|
275
|
-
"http://example.org/foo": {"@value": "bar", "@language": "baz"}
|
276
|
-
}),
|
277
|
-
context: %({"literal": "@value"}),
|
278
|
-
output: %({
|
279
|
-
"@context": {"literal": "@value"},
|
280
|
-
"http://example.org/foo": {"literal": "bar", "@language": "baz"}
|
281
|
-
})
|
282
|
-
},
|
283
|
-
"@list" => {
|
284
|
-
input: %({
|
285
|
-
"http://example.org/foo": {"@list": ["bar"]}
|
286
|
-
}),
|
287
|
-
context: %({"list": "@list"}),
|
288
|
-
output: %({
|
289
|
-
"@context": {"list": "@list"},
|
290
|
-
"http://example.org/foo": {"list": ["bar"]}
|
291
|
-
})
|
292
|
-
},
|
293
|
-
}.each do |title, params|
|
294
|
-
it(title) {run_compact(params)}
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context "term selection" do
|
299
|
-
{
|
300
|
-
"Uses term with null language when two terms conflict on language" => {
|
301
|
-
input: %([{
|
302
|
-
"http://example.com/term": {"@value": "v1"}
|
303
|
-
}]),
|
304
|
-
context: %({
|
305
|
-
"term5": {"@id": "http://example.com/term","@language": null},
|
306
|
-
"@language": "de"
|
307
|
-
}),
|
308
|
-
output: %({
|
309
|
-
"@context": {
|
310
|
-
"term5": {"@id": "http://example.com/term","@language": null},
|
311
|
-
"@language": "de"
|
312
|
-
},
|
313
|
-
"term5": "v1"
|
314
|
-
})
|
315
|
-
},
|
316
|
-
"Uses term with null direction when two terms conflict on direction" => {
|
317
|
-
input: %([{
|
318
|
-
"http://example.com/term": {"@value": "v1"}
|
319
|
-
}]),
|
320
|
-
context: %({
|
321
|
-
"term5": {"@id": "http://example.com/term","@direction": null},
|
322
|
-
"@direction": "ltr"
|
323
|
-
}),
|
324
|
-
output: %({
|
325
|
-
"@context": {
|
326
|
-
"term5": {"@id": "http://example.com/term","@direction": null},
|
327
|
-
"@direction": "ltr"
|
328
|
-
},
|
329
|
-
"term5": "v1"
|
330
|
-
})
|
331
|
-
},
|
332
|
-
"Uses subject alias" => {
|
333
|
-
input: %([{
|
334
|
-
"@id": "http://example.com/id1",
|
335
|
-
"http://example.com/id1": {"@value": "foo", "@language": "de"}
|
336
|
-
}]),
|
337
|
-
context: %({
|
338
|
-
"id1": "http://example.com/id1",
|
339
|
-
"@language": "de"
|
340
|
-
}),
|
341
|
-
output: %({
|
342
|
-
"@context": {
|
343
|
-
"id1": "http://example.com/id1",
|
344
|
-
"@language": "de"
|
345
|
-
},
|
346
|
-
"@id": "http://example.com/id1",
|
347
|
-
"id1": "foo"
|
348
|
-
})
|
349
|
-
},
|
350
|
-
"compact-0007" => {
|
351
|
-
input: %(
|
352
|
-
{"http://example.org/vocab#contains": "this-is-not-an-IRI"}
|
353
|
-
),
|
354
|
-
context: %({
|
355
|
-
"ex": "http://example.org/vocab#",
|
356
|
-
"ex:contains": {"@type": "@id"}
|
357
|
-
}),
|
358
|
-
output: %({
|
359
|
-
"@context": {
|
360
|
-
"ex": "http://example.org/vocab#",
|
361
|
-
"ex:contains": {"@type": "@id"}
|
362
|
-
},
|
363
|
-
"http://example.org/vocab#contains": "this-is-not-an-IRI"
|
364
|
-
})
|
365
|
-
},
|
366
|
-
"Language map term with language value" => {
|
367
|
-
input: %([{"http://example/t": {"@value": "foo", "@language": "en"}}]),
|
368
|
-
context: %({"t": {"@id": "http://example/t", "@container": "@language"}}),
|
369
|
-
output: %({
|
370
|
-
"@context": {
|
371
|
-
"t": {"@id": "http://example/t", "@container": "@language"}
|
372
|
-
},
|
373
|
-
"t": {"en": "foo"}
|
374
|
-
})
|
375
|
-
},
|
376
|
-
"Datatyped term with datatyped value" => {
|
377
|
-
input: %([{"http://example/t": {"@value": "foo", "@type": "http:/example/type"}}]),
|
378
|
-
context: %({"t": {"@id": "http://example/t", "@type": "http:/example/type"}}),
|
379
|
-
output: %({
|
380
|
-
"@context": {
|
381
|
-
"t": {"@id": "http://example/t", "@type": "http:/example/type"}
|
382
|
-
},
|
383
|
-
"t": "foo"
|
384
|
-
})
|
385
|
-
},
|
386
|
-
"Datatyped term with simple value" => {
|
387
|
-
input: %([{"http://example/t": {"@value": "foo"}}]),
|
388
|
-
context: %({"t": {"@id": "http://example/t", "@type": "http:/example/type"}}),
|
389
|
-
output: %({
|
390
|
-
"@context": {
|
391
|
-
"t": {"@id": "http://example/t", "@type": "http:/example/type"}
|
392
|
-
},
|
393
|
-
"http://example/t": "foo"
|
394
|
-
})
|
395
|
-
},
|
396
|
-
"Datatyped term with object value" => {
|
397
|
-
input: %([{"http://example/t": {"@id": "http://example/id"}}]),
|
398
|
-
context: %({"t": {"@id": "http://example/t", "@type": "http:/example/type"}}),
|
399
|
-
output: %({
|
400
|
-
"@context": {
|
401
|
-
"t": {"@id": "http://example/t", "@type": "http:/example/type"}
|
402
|
-
},
|
403
|
-
"http://example/t": {"@id": "http://example/id"}
|
404
|
-
})
|
405
|
-
},
|
406
|
-
}.each_pair do |title, params|
|
407
|
-
it(title) {run_compact(params)}
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
context "IRI Compaction" do
|
412
|
-
{
|
413
|
-
"Expands and compacts to document base in 1.0" => {
|
414
|
-
input: %({
|
415
|
-
"@id": "a",
|
416
|
-
"http://example.com/b": {"@id": "c"}
|
417
|
-
}),
|
418
|
-
context: %({"b": "http://example.com/b"}),
|
419
|
-
output: %({
|
420
|
-
"@context": {"b": "http://example.com/b"},
|
421
|
-
"@id": "a",
|
422
|
-
"b": {"@id": "c"}
|
423
|
-
}),
|
424
|
-
base: "http://example.org/"
|
425
|
-
},
|
426
|
-
"Expands and compacts to document base in 1.1 with compactToRelative true" => {
|
427
|
-
input: %({
|
428
|
-
"@id": "a",
|
429
|
-
"http://example.com/b": {"@id": "c"}
|
430
|
-
}),
|
431
|
-
context: %({"b": "http://example.com/b"}),
|
432
|
-
output: %({
|
433
|
-
"@context": {"b": "http://example.com/b"},
|
434
|
-
"@id": "a",
|
435
|
-
"b": {"@id": "c"}
|
436
|
-
}),
|
437
|
-
base: "http://example.org/",
|
438
|
-
compactToRelative: true,
|
439
|
-
processingMode: 'json-ld-1.1'
|
440
|
-
},
|
441
|
-
"Expands but does not compact to document base in 1.1 with compactToRelative false" => {
|
442
|
-
input: %({
|
443
|
-
"@id": "http://example.org/a",
|
444
|
-
"http://example.com/b": {"@id": "http://example.org/c"}
|
445
|
-
}),
|
446
|
-
context: %({"b": "http://example.com/b"}),
|
447
|
-
output: %({
|
448
|
-
"@context": {"b": "http://example.com/b"},
|
449
|
-
"@id": "http://example.org/a",
|
450
|
-
"b": {"@id": "http://example.org/c"}
|
451
|
-
}),
|
452
|
-
compactToRelative: false,
|
453
|
-
processingMode: 'json-ld-1.1'
|
454
|
-
},
|
455
|
-
"Expands and compacts to document base in 1.1 by default" => {
|
456
|
-
input: %({
|
457
|
-
"@id": "a",
|
458
|
-
"http://example.com/b": {"@id": "c"}
|
459
|
-
}),
|
460
|
-
context: %({"b": "http://example.com/b"}),
|
461
|
-
output: %({
|
462
|
-
"@context": {"b": "http://example.com/b"},
|
463
|
-
"@id": "a",
|
464
|
-
"b": {"@id": "c"}
|
465
|
-
}),
|
466
|
-
base: "http://example.org/",
|
467
|
-
processingMode: 'json-ld-1.1'
|
468
|
-
},
|
469
|
-
}.each_pair do |title, params|
|
470
|
-
it(title) {run_compact(params)}
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
context "@container: @reverse" do
|
475
|
-
{
|
476
|
-
"@container: @reverse" => {
|
477
|
-
input: %([{
|
478
|
-
"@id": "http://example/one",
|
479
|
-
"@reverse": {
|
480
|
-
"http://example/forward": [
|
481
|
-
{
|
482
|
-
"@id": "http://example/two"
|
483
|
-
}
|
484
|
-
]
|
485
|
-
}
|
486
|
-
}]),
|
487
|
-
context: %({
|
488
|
-
"@vocab": "http://example/",
|
489
|
-
"rev": { "@reverse": "forward", "@type": "@id"}
|
490
|
-
}),
|
491
|
-
output: %({
|
492
|
-
"@context": {
|
493
|
-
"@vocab": "http://example/",
|
494
|
-
"rev": { "@reverse": "forward", "@type": "@id"}
|
495
|
-
},
|
496
|
-
"@id": "http://example/one",
|
497
|
-
"rev": "http://example/two"
|
498
|
-
})
|
499
|
-
},
|
500
|
-
"compact-0033" => {
|
501
|
-
input: %([
|
502
|
-
{
|
503
|
-
"@id": "http://example.com/people/markus",
|
504
|
-
"@reverse": {
|
505
|
-
"http://xmlns.com/foaf/0.1/knows": [
|
506
|
-
{
|
507
|
-
"@id": "http://example.com/people/dave",
|
508
|
-
"http://xmlns.com/foaf/0.1/name": [ { "@value": "Dave Longley" } ]
|
509
|
-
}
|
510
|
-
]
|
511
|
-
},
|
512
|
-
"http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ]
|
513
|
-
}
|
514
|
-
]),
|
515
|
-
context: %({
|
516
|
-
"name": "http://xmlns.com/foaf/0.1/name",
|
517
|
-
"isKnownBy": { "@reverse": "http://xmlns.com/foaf/0.1/knows" }
|
518
|
-
}),
|
519
|
-
output: %({
|
520
|
-
"@context": {
|
521
|
-
"name": "http://xmlns.com/foaf/0.1/name",
|
522
|
-
"isKnownBy": {
|
523
|
-
"@reverse": "http://xmlns.com/foaf/0.1/knows"
|
524
|
-
}
|
525
|
-
},
|
526
|
-
"@id": "http://example.com/people/markus",
|
527
|
-
"name": "Markus Lanthaler",
|
528
|
-
"isKnownBy": {
|
529
|
-
"@id": "http://example.com/people/dave",
|
530
|
-
"name": "Dave Longley"
|
531
|
-
}
|
532
|
-
})
|
533
|
-
}
|
534
|
-
}.each_pair do |title, params|
|
535
|
-
it(title) {run_compact(params)}
|
536
|
-
end
|
537
|
-
end
|
538
|
-
|
539
|
-
context "context as value" do
|
540
|
-
{
|
541
|
-
"includes the context in the output document" => {
|
542
|
-
input: %({
|
543
|
-
"http://example.com/": "bar"
|
544
|
-
}),
|
545
|
-
context: %({
|
546
|
-
"foo": "http://example.com/"
|
547
|
-
}),
|
548
|
-
output: %({
|
549
|
-
"@context": {
|
550
|
-
"foo": "http://example.com/"
|
551
|
-
},
|
552
|
-
"foo": "bar"
|
553
|
-
})
|
554
|
-
}
|
555
|
-
}.each_pair do |title, params|
|
556
|
-
it(title) {run_compact(params)}
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
context "context as reference" do
|
561
|
-
let(:remote_doc) do
|
562
|
-
JSON::LD::API::RemoteDocument.new(
|
563
|
-
%q({"@context": {"b": "http://example.com/b"}}),
|
564
|
-
documentUrl: "http://example.com/context")
|
565
|
-
end
|
566
|
-
it "uses referenced context" do
|
567
|
-
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
568
|
-
input = ::JSON.parse %({
|
569
|
-
"http://example.com/b": "c"
|
570
|
-
})
|
571
|
-
expected = ::JSON.parse %({
|
572
|
-
"@context": "http://example.com/context",
|
573
|
-
"b": "c"
|
574
|
-
})
|
575
|
-
allow(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
576
|
-
jld = JSON::LD::API.compact(input, "http://example.com/context", logger: logger, validate: true)
|
577
|
-
expect(jld).to produce_jsonld(expected, logger)
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
context "@list" do
|
582
|
-
{
|
583
|
-
"1 term 2 lists 2 languages" => {
|
584
|
-
input: %([{
|
585
|
-
"http://example.com/foo": [
|
586
|
-
{"@list": [{"@value": "en", "@language": "en"}]},
|
587
|
-
{"@list": [{"@value": "de", "@language": "de"}]}
|
588
|
-
]
|
589
|
-
}]),
|
590
|
-
context: %({
|
591
|
-
"foo_en": {"@id": "http://example.com/foo", "@container": "@list", "@language": "en"},
|
592
|
-
"foo_de": {"@id": "http://example.com/foo", "@container": "@list", "@language": "de"}
|
593
|
-
}),
|
594
|
-
output: %({
|
595
|
-
"@context": {
|
596
|
-
"foo_en": {"@id": "http://example.com/foo", "@container": "@list", "@language": "en"},
|
597
|
-
"foo_de": {"@id": "http://example.com/foo", "@container": "@list", "@language": "de"}
|
598
|
-
},
|
599
|
-
"foo_en": ["en"],
|
600
|
-
"foo_de": ["de"]
|
601
|
-
})
|
602
|
-
},
|
603
|
-
"1 term 2 lists 2 directions" => {
|
604
|
-
input: %([{
|
605
|
-
"http://example.com/foo": [
|
606
|
-
{"@list": [{"@value": "en", "@direction": "ltr"}]},
|
607
|
-
{"@list": [{"@value": "ar", "@direction": "rtl"}]}
|
608
|
-
]
|
609
|
-
}]),
|
610
|
-
context: %({
|
611
|
-
"foo_ltr": {"@id": "http://example.com/foo", "@container": "@list", "@direction": "ltr"},
|
612
|
-
"foo_rtl": {"@id": "http://example.com/foo", "@container": "@list", "@direction": "rtl"}
|
613
|
-
}),
|
614
|
-
output: %({
|
615
|
-
"@context": {
|
616
|
-
"foo_ltr": {"@id": "http://example.com/foo", "@container": "@list", "@direction": "ltr"},
|
617
|
-
"foo_rtl": {"@id": "http://example.com/foo", "@container": "@list", "@direction": "rtl"}
|
618
|
-
},
|
619
|
-
"foo_ltr": ["en"],
|
620
|
-
"foo_rtl": ["ar"]
|
621
|
-
})
|
622
|
-
},
|
623
|
-
"coerced @list containing an empty list" => {
|
624
|
-
input: %([{
|
625
|
-
"http://example.com/foo": [{"@list": [{"@list": []}]}]
|
626
|
-
}]),
|
627
|
-
context: %({
|
628
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
629
|
-
}),
|
630
|
-
output: %({
|
631
|
-
"@context": {"foo": {"@id": "http://example.com/foo", "@container": "@list"}},
|
632
|
-
"foo": [[]]
|
633
|
-
}),
|
634
|
-
},
|
635
|
-
"coerced @list containing a list" => {
|
636
|
-
input: %([{
|
637
|
-
"http://example.com/foo": [{"@list": [{"@list": [{"@value": "baz"}]}]}]
|
638
|
-
}]),
|
639
|
-
context: %({
|
640
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
641
|
-
}),
|
642
|
-
output: %({
|
643
|
-
"@context": {"foo": {"@id": "http://example.com/foo", "@container": "@list"}},
|
644
|
-
"foo": [["baz"]]
|
645
|
-
}),
|
646
|
-
},
|
647
|
-
"coerced @list containing an deep list" => {
|
648
|
-
input: %([{
|
649
|
-
"http://example.com/foo": [{"@list": [{"@list": [{"@list": [{"@value": "baz"}]}]}]}]
|
650
|
-
}]),
|
651
|
-
context: %({
|
652
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
653
|
-
}),
|
654
|
-
output: %({
|
655
|
-
"@context": {"foo": {"@id": "http://example.com/foo", "@container": "@list"}},
|
656
|
-
"foo": [[["baz"]]]
|
657
|
-
}),
|
658
|
-
},
|
659
|
-
"coerced @list containing multiple lists" => {
|
660
|
-
input: %([{
|
661
|
-
"http://example.com/foo": [{"@list": [
|
662
|
-
{"@list": [{"@value": "a"}]},
|
663
|
-
{"@list": [{"@value": "b"}]}
|
664
|
-
]}]
|
665
|
-
}]),
|
666
|
-
context: %({
|
667
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
668
|
-
}),
|
669
|
-
output: %({
|
670
|
-
"@context": {"foo": {"@id": "http://example.com/foo", "@container": "@list"}},
|
671
|
-
"foo": [["a"], ["b"]]
|
672
|
-
}),
|
673
|
-
},
|
674
|
-
"coerced @list containing mixed list values" => {
|
675
|
-
input: %([{
|
676
|
-
"http://example.com/foo": [{"@list": [
|
677
|
-
{"@list": [{"@value": "a"}]},
|
678
|
-
{"@value": "b"}
|
679
|
-
]}]
|
680
|
-
}]),
|
681
|
-
context: %({
|
682
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
683
|
-
}),
|
684
|
-
output: %({
|
685
|
-
"@context": {"foo": {"@id": "http://example.com/foo", "@container": "@list"}},
|
686
|
-
"foo": [["a"], "b"]
|
687
|
-
}),
|
688
|
-
},
|
689
|
-
}.each_pair do |title, params|
|
690
|
-
it(title) {run_compact(params)}
|
691
|
-
end
|
692
|
-
end
|
693
|
-
|
694
|
-
context "with @type: @json" do
|
695
|
-
{
|
696
|
-
"true": {
|
697
|
-
output: %({
|
698
|
-
"@context": {
|
699
|
-
"@version": 1.1,
|
700
|
-
"e": {"@id": "http://example.org/vocab#bool", "@type": "@json"}
|
701
|
-
},
|
702
|
-
"e": true
|
703
|
-
}),
|
704
|
-
input:%( [{
|
705
|
-
"http://example.org/vocab#bool": [{"@value": true, "@type": "@json"}]
|
706
|
-
}]),
|
707
|
-
},
|
708
|
-
"false": {
|
709
|
-
output: %({
|
710
|
-
"@context": {
|
711
|
-
"@version": 1.1,
|
712
|
-
"e": {"@id": "http://example.org/vocab#bool", "@type": "@json"}
|
713
|
-
},
|
714
|
-
"e": false
|
715
|
-
}),
|
716
|
-
input: %([{
|
717
|
-
"http://example.org/vocab#bool": [{"@value": false, "@type": "@json"}]
|
718
|
-
}]),
|
719
|
-
},
|
720
|
-
"double": {
|
721
|
-
output: %({
|
722
|
-
"@context": {
|
723
|
-
"@version": 1.1,
|
724
|
-
"e": {"@id": "http://example.org/vocab#double", "@type": "@json"}
|
725
|
-
},
|
726
|
-
"e": 1.23
|
727
|
-
}),
|
728
|
-
input: %([{
|
729
|
-
"http://example.org/vocab#double": [{"@value": 1.23, "@type": "@json"}]
|
730
|
-
}]),
|
731
|
-
},
|
732
|
-
"double-zero": {
|
733
|
-
output: %({
|
734
|
-
"@context": {
|
735
|
-
"@version": 1.1,
|
736
|
-
"e": {"@id": "http://example.org/vocab#double", "@type": "@json"}
|
737
|
-
},
|
738
|
-
"e": 0.0e0
|
739
|
-
}),
|
740
|
-
input: %([{
|
741
|
-
"http://example.org/vocab#double": [{"@value": 0.0e0, "@type": "@json"}]
|
742
|
-
}]),
|
743
|
-
},
|
744
|
-
"integer": {
|
745
|
-
output: %({
|
746
|
-
"@context": {
|
747
|
-
"@version": 1.1,
|
748
|
-
"e": {"@id": "http://example.org/vocab#integer", "@type": "@json"}
|
749
|
-
},
|
750
|
-
"e": 123
|
751
|
-
}),
|
752
|
-
input: %([{
|
753
|
-
"http://example.org/vocab#integer": [{"@value": 123, "@type": "@json"}]
|
754
|
-
}]),
|
755
|
-
},
|
756
|
-
"string": {
|
757
|
-
input: %([{
|
758
|
-
"http://example.org/vocab#string": [{
|
759
|
-
"@value": "string",
|
760
|
-
"@type": "@json"
|
761
|
-
}]
|
762
|
-
}]),
|
763
|
-
output: %({
|
764
|
-
"@context": {
|
765
|
-
"@version": 1.1,
|
766
|
-
"e": {"@id": "http://example.org/vocab#string", "@type": "@json"}
|
767
|
-
},
|
768
|
-
"e": "string"
|
769
|
-
})
|
770
|
-
},
|
771
|
-
"null": {
|
772
|
-
input: %([{
|
773
|
-
"http://example.org/vocab#null": [{
|
774
|
-
"@value": null,
|
775
|
-
"@type": "@json"
|
776
|
-
}]
|
777
|
-
}]),
|
778
|
-
output: %({
|
779
|
-
"@context": {
|
780
|
-
"@version": 1.1,
|
781
|
-
"e": {"@id": "http://example.org/vocab#null", "@type": "@json"}
|
782
|
-
},
|
783
|
-
"e": null
|
784
|
-
})
|
785
|
-
},
|
786
|
-
"object": {
|
787
|
-
output: %({
|
788
|
-
"@context": {
|
789
|
-
"@version": 1.1,
|
790
|
-
"e": {"@id": "http://example.org/vocab#object", "@type": "@json"}
|
791
|
-
},
|
792
|
-
"e": {"foo": "bar"}
|
793
|
-
}),
|
794
|
-
input: %([{
|
795
|
-
"http://example.org/vocab#object": [{"@value": {"foo": "bar"}, "@type": "@json"}]
|
796
|
-
}]),
|
797
|
-
},
|
798
|
-
"array": {
|
799
|
-
output: %({
|
800
|
-
"@context": {
|
801
|
-
"@version": 1.1,
|
802
|
-
"e": {"@id": "http://example.org/vocab#array", "@type": "@json", "@container": "@set"}
|
803
|
-
},
|
804
|
-
"e": [{"foo": "bar"}]
|
805
|
-
}),
|
806
|
-
input: %([{
|
807
|
-
"http://example.org/vocab#array": [{"@value": [{"foo": "bar"}], "@type": "@json"}]
|
808
|
-
}]),
|
809
|
-
},
|
810
|
-
"Already expanded object": {
|
811
|
-
output: %({
|
812
|
-
"@context": {"@version": 1.1},
|
813
|
-
"http://example.org/vocab#object": {"@value": {"foo": "bar"}, "@type": "@json"}
|
814
|
-
}),
|
815
|
-
input: %([{
|
816
|
-
"http://example.org/vocab#object": [{"@value": {"foo": "bar"}, "@type": "@json"}]
|
817
|
-
}]),
|
818
|
-
},
|
819
|
-
"Already expanded object with aliased keys": {
|
820
|
-
output: %({
|
821
|
-
"@context": {"@version": 1.1, "value": "@value", "type": "@type", "json": "@json"},
|
822
|
-
"http://example.org/vocab#object": {"value": {"foo": "bar"}, "type": "json"}
|
823
|
-
}),
|
824
|
-
input: %([{
|
825
|
-
"http://example.org/vocab#object": [{"@value": {"foo": "bar"}, "@type": "@json"}]
|
826
|
-
}])
|
827
|
-
},
|
828
|
-
}.each do |title, params|
|
829
|
-
it(title) {run_compact(processingMode: 'json-ld-1.1', **params)}
|
830
|
-
end
|
831
|
-
end
|
832
|
-
|
833
|
-
context "@container: @index" do
|
834
|
-
{
|
835
|
-
"compact-0029" => {
|
836
|
-
input: %([{
|
837
|
-
"@id": "http://example.com/article",
|
838
|
-
"http://example.com/vocab/author": [{
|
839
|
-
"@id": "http://example.org/person/1",
|
840
|
-
"@index": "regular"
|
841
|
-
}, {
|
842
|
-
"@id": "http://example.org/guest/cd24f329aa",
|
843
|
-
"@index": "guest"
|
844
|
-
}]
|
845
|
-
}]),
|
846
|
-
context: %({
|
847
|
-
"author": {"@id": "http://example.com/vocab/author", "@container": "@index" }
|
848
|
-
}),
|
849
|
-
output: %({
|
850
|
-
"@context": {
|
851
|
-
"author": {
|
852
|
-
"@id": "http://example.com/vocab/author",
|
853
|
-
"@container": "@index"
|
854
|
-
}
|
855
|
-
},
|
856
|
-
"@id": "http://example.com/article",
|
857
|
-
"author": {
|
858
|
-
"regular": {
|
859
|
-
"@id": "http://example.org/person/1"
|
860
|
-
},
|
861
|
-
"guest": {
|
862
|
-
"@id": "http://example.org/guest/cd24f329aa"
|
863
|
-
}
|
864
|
-
}
|
865
|
-
})
|
866
|
-
},
|
867
|
-
"simple map with @none node definition" => {
|
868
|
-
input: %([{
|
869
|
-
"@id": "http://example.com/article",
|
870
|
-
"http://example.com/vocab/author": [{
|
871
|
-
"@id": "http://example.org/person/1",
|
872
|
-
"@index": "regular"
|
873
|
-
}, {
|
874
|
-
"@id": "http://example.org/guest/cd24f329aa"
|
875
|
-
}]
|
876
|
-
}]),
|
877
|
-
context: %({
|
878
|
-
"author": {"@id": "http://example.com/vocab/author", "@container": "@index" }
|
879
|
-
}),
|
880
|
-
output: %({
|
881
|
-
"@context": {
|
882
|
-
"author": {
|
883
|
-
"@id": "http://example.com/vocab/author",
|
884
|
-
"@container": "@index"
|
885
|
-
}
|
886
|
-
},
|
887
|
-
"@id": "http://example.com/article",
|
888
|
-
"author": {
|
889
|
-
"regular": {
|
890
|
-
"@id": "http://example.org/person/1"
|
891
|
-
},
|
892
|
-
"@none": {
|
893
|
-
"@id": "http://example.org/guest/cd24f329aa"
|
894
|
-
}
|
895
|
-
}
|
896
|
-
}),
|
897
|
-
processingMode: 'json-ld-1.1'
|
898
|
-
},
|
899
|
-
"simple map with @none value" => {
|
900
|
-
input: %([{
|
901
|
-
"@id": "http://example.com/article",
|
902
|
-
"http://example.com/vocab/author": [{
|
903
|
-
"@value": "Gregg",
|
904
|
-
"@index": "regular"
|
905
|
-
}, {
|
906
|
-
"@value": "Manu"
|
907
|
-
}]
|
908
|
-
}]),
|
909
|
-
context: %({
|
910
|
-
"author": {"@id": "http://example.com/vocab/author", "@container": "@index" }
|
911
|
-
}),
|
912
|
-
output: %({
|
913
|
-
"@context": {
|
914
|
-
"author": {
|
915
|
-
"@id": "http://example.com/vocab/author",
|
916
|
-
"@container": "@index"
|
917
|
-
}
|
918
|
-
},
|
919
|
-
"@id": "http://example.com/article",
|
920
|
-
"author": {
|
921
|
-
"regular": "Gregg",
|
922
|
-
"@none": "Manu"
|
923
|
-
}
|
924
|
-
}),
|
925
|
-
processingMode: 'json-ld-1.1'
|
926
|
-
},
|
927
|
-
"simple map with @none value using alias of @none" => {
|
928
|
-
input: %([{
|
929
|
-
"@id": "http://example.com/article",
|
930
|
-
"http://example.com/vocab/author": [{
|
931
|
-
"@value": "Gregg",
|
932
|
-
"@index": "regular"
|
933
|
-
}, {
|
934
|
-
"@value": "Manu"
|
935
|
-
}]
|
936
|
-
}]),
|
937
|
-
context: %({
|
938
|
-
"author": {"@id": "http://example.com/vocab/author", "@container": "@index" },
|
939
|
-
"none": "@none"
|
940
|
-
}),
|
941
|
-
output: %({
|
942
|
-
"@context": {
|
943
|
-
"author": {
|
944
|
-
"@id": "http://example.com/vocab/author",
|
945
|
-
"@container": "@index"
|
946
|
-
},
|
947
|
-
"none": "@none"
|
948
|
-
},
|
949
|
-
"@id": "http://example.com/article",
|
950
|
-
"author": {
|
951
|
-
"regular": "Gregg",
|
952
|
-
"none": "Manu"
|
953
|
-
}
|
954
|
-
}),
|
955
|
-
processingMode: 'json-ld-1.1'
|
956
|
-
},
|
957
|
-
"issue-514": {
|
958
|
-
input: %({
|
959
|
-
"http://example.org/ns/prop": [{
|
960
|
-
"@id": "http://example.org/ns/bar",
|
961
|
-
"http://example.org/ns/name": "bar"
|
962
|
-
}, {
|
963
|
-
"@id": "http://example.org/ns/foo",
|
964
|
-
"http://example.org/ns/name": "foo"
|
965
|
-
}]
|
966
|
-
}),
|
967
|
-
context: %({
|
968
|
-
"@context": {
|
969
|
-
"ex": "http://example.org/ns/",
|
970
|
-
"prop": {
|
971
|
-
"@id": "ex:prop",
|
972
|
-
"@container": "@index",
|
973
|
-
"@index": "ex:name"
|
974
|
-
}
|
975
|
-
}
|
976
|
-
}),
|
977
|
-
output: %({
|
978
|
-
"@context": {
|
979
|
-
"ex": "http://example.org/ns/",
|
980
|
-
"prop": {
|
981
|
-
"@id": "ex:prop",
|
982
|
-
"@container": "@index",
|
983
|
-
"@index": "ex:name"
|
984
|
-
}
|
985
|
-
},
|
986
|
-
"prop": {
|
987
|
-
"foo": { "@id": "ex:foo"},
|
988
|
-
"bar": { "@id": "ex:bar"}
|
989
|
-
}
|
990
|
-
})
|
991
|
-
},
|
992
|
-
"issue-514b": {
|
993
|
-
input: %({
|
994
|
-
"http://example.org/ns/prop": [{
|
995
|
-
"@id": "http://example.org/ns/bar",
|
996
|
-
"http://example.org/ns/name": "bar"
|
997
|
-
}, {
|
998
|
-
"@id": "http://example.org/ns/foo",
|
999
|
-
"http://example.org/ns/name": "foo"
|
1000
|
-
}]
|
1001
|
-
}),
|
1002
|
-
context: %({
|
1003
|
-
"@context": {
|
1004
|
-
"ex": "http://example.org/ns/",
|
1005
|
-
"prop": {
|
1006
|
-
"@id": "ex:prop",
|
1007
|
-
"@container": "@index",
|
1008
|
-
"@index": "http://example.org/ns/name"
|
1009
|
-
}
|
1010
|
-
}
|
1011
|
-
}),
|
1012
|
-
output: %({
|
1013
|
-
"@context": {
|
1014
|
-
"ex": "http://example.org/ns/",
|
1015
|
-
"prop": {
|
1016
|
-
"@id": "ex:prop",
|
1017
|
-
"@container": "@index",
|
1018
|
-
"@index": "http://example.org/ns/name"
|
1019
|
-
}
|
1020
|
-
},
|
1021
|
-
"prop": {
|
1022
|
-
"foo": { "@id": "ex:foo"},
|
1023
|
-
"bar": { "@id": "ex:bar"}
|
1024
|
-
}
|
1025
|
-
})
|
1026
|
-
},
|
1027
|
-
}.each_pair do |title, params|
|
1028
|
-
it(title) {run_compact(params)}
|
1029
|
-
end
|
1030
|
-
|
1031
|
-
context "@index: property" do
|
1032
|
-
{
|
1033
|
-
"property-valued index indexes property value, instead of property (value)": {
|
1034
|
-
output: %({
|
1035
|
-
"@context": {
|
1036
|
-
"@version": 1.1,
|
1037
|
-
"@base": "http://example.com/",
|
1038
|
-
"@vocab": "http://example.com/",
|
1039
|
-
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
|
1040
|
-
},
|
1041
|
-
"@id": "article",
|
1042
|
-
"author": {
|
1043
|
-
"regular": {"@id": "person/1"},
|
1044
|
-
"guest": [{"@id": "person/2"}, {"@id": "person/3"}]
|
1045
|
-
}
|
1046
|
-
}),
|
1047
|
-
input: %([{
|
1048
|
-
"@id": "http://example.com/article",
|
1049
|
-
"http://example.com/author": [
|
1050
|
-
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}]},
|
1051
|
-
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}]},
|
1052
|
-
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}]}
|
1053
|
-
]
|
1054
|
-
}])
|
1055
|
-
},
|
1056
|
-
"property-valued index indexes property value, instead of @index (multiple values)": {
|
1057
|
-
output: %({
|
1058
|
-
"@context": {
|
1059
|
-
"@version": 1.1,
|
1060
|
-
"@base": "http://example.com/",
|
1061
|
-
"@vocab": "http://example.com/",
|
1062
|
-
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
|
1063
|
-
},
|
1064
|
-
"@id": "article",
|
1065
|
-
"author": {
|
1066
|
-
"regular": {"@id": "person/1", "prop": "foo"},
|
1067
|
-
"guest": [
|
1068
|
-
{"@id": "person/2", "prop": "foo"},
|
1069
|
-
{"@id": "person/3", "prop": "foo"}
|
1070
|
-
]
|
1071
|
-
}
|
1072
|
-
}),
|
1073
|
-
input: %([{
|
1074
|
-
"@id": "http://example.com/article",
|
1075
|
-
"http://example.com/author": [
|
1076
|
-
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}, {"@value": "foo"}]},
|
1077
|
-
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]},
|
1078
|
-
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]}
|
1079
|
-
]
|
1080
|
-
}])
|
1081
|
-
},
|
1082
|
-
"property-valued index extracts property value, instead of @index (node)": {
|
1083
|
-
output: %({
|
1084
|
-
"@context": {
|
1085
|
-
"@version": 1.1,
|
1086
|
-
"@base": "http://example.com/",
|
1087
|
-
"@vocab": "http://example.com/",
|
1088
|
-
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
|
1089
|
-
"prop": {"@type": "@id"}
|
1090
|
-
},
|
1091
|
-
"@id": "article",
|
1092
|
-
"author": {
|
1093
|
-
"regular": {"@id": "person/1"},
|
1094
|
-
"guest": [
|
1095
|
-
{"@id": "person/2"},
|
1096
|
-
{"@id": "person/3"}
|
1097
|
-
]
|
1098
|
-
}
|
1099
|
-
}),
|
1100
|
-
input: %([{
|
1101
|
-
"@id": "http://example.com/article",
|
1102
|
-
"http://example.com/author": [
|
1103
|
-
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}]},
|
1104
|
-
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}]},
|
1105
|
-
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}]}
|
1106
|
-
]
|
1107
|
-
}])
|
1108
|
-
},
|
1109
|
-
"property-valued index indexes property value, instead of property (multimple nodes)": {
|
1110
|
-
output: %({
|
1111
|
-
"@context": {
|
1112
|
-
"@version": 1.1,
|
1113
|
-
"@base": "http://example.com/",
|
1114
|
-
"@vocab": "http://example.com/",
|
1115
|
-
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
|
1116
|
-
"prop": {"@type": "@id"}
|
1117
|
-
},
|
1118
|
-
"@id": "article",
|
1119
|
-
"author": {
|
1120
|
-
"regular": {"@id": "person/1", "prop": "foo"},
|
1121
|
-
"guest": [
|
1122
|
-
{"@id": "person/2", "prop": "foo"},
|
1123
|
-
{"@id": "person/3", "prop": "foo"}
|
1124
|
-
]
|
1125
|
-
}
|
1126
|
-
}),
|
1127
|
-
input: %([{
|
1128
|
-
"@id": "http://example.com/article",
|
1129
|
-
"http://example.com/author": [
|
1130
|
-
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}, {"@id": "http://example.com/foo"}]},
|
1131
|
-
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]},
|
1132
|
-
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]}
|
1133
|
-
]
|
1134
|
-
}])
|
1135
|
-
},
|
1136
|
-
"property-valued index indexes using @none if no property value exists": {
|
1137
|
-
output: %({
|
1138
|
-
"@context": {
|
1139
|
-
"@version": 1.1,
|
1140
|
-
"@base": "http://example.com/",
|
1141
|
-
"@vocab": "http://example.com/",
|
1142
|
-
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
|
1143
|
-
},
|
1144
|
-
"@id": "article",
|
1145
|
-
"author": {
|
1146
|
-
"@none": ["person/1", "person/2", "person/3"]
|
1147
|
-
}
|
1148
|
-
}),
|
1149
|
-
input: %([{
|
1150
|
-
"@id": "http://example.com/article",
|
1151
|
-
"http://example.com/author": [
|
1152
|
-
{"@id": "http://example.com/person/1"},
|
1153
|
-
{"@id": "http://example.com/person/2"},
|
1154
|
-
{"@id": "http://example.com/person/3"}
|
1155
|
-
]
|
1156
|
-
}])
|
1157
|
-
},
|
1158
|
-
"property-valued index indexes using @none if no property value does not compact to string": {
|
1159
|
-
output: %({
|
1160
|
-
"@context": {
|
1161
|
-
"@version": 1.1,
|
1162
|
-
"@base": "http://example.com/",
|
1163
|
-
"@vocab": "http://example.com/",
|
1164
|
-
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
|
1165
|
-
},
|
1166
|
-
"@id": "article",
|
1167
|
-
"author": {
|
1168
|
-
"@none": [
|
1169
|
-
{"@id": "person/1", "prop": {"@id": "regular"}},
|
1170
|
-
{"@id": "person/2", "prop": {"@id": "guest"}},
|
1171
|
-
{"@id": "person/3", "prop": {"@id": "guest"}}
|
1172
|
-
]
|
1173
|
-
}
|
1174
|
-
}),
|
1175
|
-
input: %([{
|
1176
|
-
"@id": "http://example.com/article",
|
1177
|
-
"http://example.com/author": [
|
1178
|
-
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}]},
|
1179
|
-
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}]},
|
1180
|
-
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}]}
|
1181
|
-
]
|
1182
|
-
}])
|
1183
|
-
}
|
1184
|
-
}.each do |title, params|
|
1185
|
-
it(title) {run_compact(**params)}
|
1186
|
-
end
|
1187
|
-
end
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
context "@container: @language" do
|
1191
|
-
{
|
1192
|
-
"compact-0024" => {
|
1193
|
-
input: %([
|
1194
|
-
{
|
1195
|
-
"@id": "http://example.com/queen",
|
1196
|
-
"http://example.com/vocab/label": [
|
1197
|
-
{"@value": "The Queen", "@language": "en"},
|
1198
|
-
{"@value": "Die Königin", "@language": "de"},
|
1199
|
-
{"@value": "Ihre Majestät", "@language": "de"}
|
1200
|
-
]
|
1201
|
-
}
|
1202
|
-
]),
|
1203
|
-
context: %({
|
1204
|
-
"vocab": "http://example.com/vocab/",
|
1205
|
-
"label": {"@id": "vocab:label", "@container": "@language"}
|
1206
|
-
}),
|
1207
|
-
output: %({
|
1208
|
-
"@context": {
|
1209
|
-
"vocab": "http://example.com/vocab/",
|
1210
|
-
"label": {"@id": "vocab:label", "@container": "@language"}
|
1211
|
-
},
|
1212
|
-
"@id": "http://example.com/queen",
|
1213
|
-
"label": {
|
1214
|
-
"en": "The Queen",
|
1215
|
-
"de": ["Die Königin", "Ihre Majestät"]
|
1216
|
-
}
|
1217
|
-
})
|
1218
|
-
},
|
1219
|
-
"with no @language" => {
|
1220
|
-
input: %([
|
1221
|
-
{
|
1222
|
-
"@id": "http://example.com/queen",
|
1223
|
-
"http://example.com/vocab/label": [
|
1224
|
-
{"@value": "The Queen", "@language": "en"},
|
1225
|
-
{"@value": "Die Königin", "@language": "de"},
|
1226
|
-
{"@value": "Ihre Majestät"}
|
1227
|
-
]
|
1228
|
-
}
|
1229
|
-
]),
|
1230
|
-
context: %({
|
1231
|
-
"vocab": "http://example.com/vocab/",
|
1232
|
-
"label": {"@id": "vocab:label", "@container": "@language"}
|
1233
|
-
}),
|
1234
|
-
output: %({
|
1235
|
-
"@context": {
|
1236
|
-
"vocab": "http://example.com/vocab/",
|
1237
|
-
"label": {"@id": "vocab:label", "@container": "@language"}
|
1238
|
-
},
|
1239
|
-
"@id": "http://example.com/queen",
|
1240
|
-
"label": {
|
1241
|
-
"en": "The Queen",
|
1242
|
-
"de": "Die Königin",
|
1243
|
-
"@none": "Ihre Majestät"
|
1244
|
-
}
|
1245
|
-
}),
|
1246
|
-
processingMode: "json-ld-1.1"
|
1247
|
-
},
|
1248
|
-
"with no @language using alias of @none" => {
|
1249
|
-
input: %([
|
1250
|
-
{
|
1251
|
-
"@id": "http://example.com/queen",
|
1252
|
-
"http://example.com/vocab/label": [
|
1253
|
-
{"@value": "The Queen", "@language": "en"},
|
1254
|
-
{"@value": "Die Königin", "@language": "de"},
|
1255
|
-
{"@value": "Ihre Majestät"}
|
1256
|
-
]
|
1257
|
-
}
|
1258
|
-
]),
|
1259
|
-
context: %({
|
1260
|
-
"vocab": "http://example.com/vocab/",
|
1261
|
-
"label": {"@id": "vocab:label", "@container": "@language"},
|
1262
|
-
"none": "@none"
|
1263
|
-
}),
|
1264
|
-
output: %({
|
1265
|
-
"@context": {
|
1266
|
-
"vocab": "http://example.com/vocab/",
|
1267
|
-
"label": {"@id": "vocab:label", "@container": "@language"},
|
1268
|
-
"none": "@none"
|
1269
|
-
},
|
1270
|
-
"@id": "http://example.com/queen",
|
1271
|
-
"label": {
|
1272
|
-
"en": "The Queen",
|
1273
|
-
"de": "Die Königin",
|
1274
|
-
"none": "Ihre Majestät"
|
1275
|
-
}
|
1276
|
-
}),
|
1277
|
-
processingMode: "json-ld-1.1"
|
1278
|
-
},
|
1279
|
-
"simple map with term direction": {
|
1280
|
-
input: %([
|
1281
|
-
{
|
1282
|
-
"@id": "http://example.com/queen",
|
1283
|
-
"http://example.com/vocab/label": [
|
1284
|
-
{"@value": "Die Königin", "@language": "de", "@direction": "ltr"},
|
1285
|
-
{"@value": "Ihre Majestät", "@language": "de", "@direction": "ltr"},
|
1286
|
-
{"@value": "The Queen", "@language": "en", "@direction": "ltr"}
|
1287
|
-
]
|
1288
|
-
}
|
1289
|
-
]),
|
1290
|
-
context: %({
|
1291
|
-
"@context": {
|
1292
|
-
"@version": 1.1,
|
1293
|
-
"vocab": "http://example.com/vocab/",
|
1294
|
-
"label": {
|
1295
|
-
"@id": "vocab:label",
|
1296
|
-
"@direction": "ltr",
|
1297
|
-
"@container": "@language"
|
1298
|
-
}
|
1299
|
-
}
|
1300
|
-
}),
|
1301
|
-
output: %({
|
1302
|
-
"@context": {
|
1303
|
-
"@version": 1.1,
|
1304
|
-
"vocab": "http://example.com/vocab/",
|
1305
|
-
"label": {
|
1306
|
-
"@id": "vocab:label",
|
1307
|
-
"@direction": "ltr",
|
1308
|
-
"@container": "@language"
|
1309
|
-
}
|
1310
|
-
},
|
1311
|
-
"@id": "http://example.com/queen",
|
1312
|
-
"label": {
|
1313
|
-
"en": "The Queen",
|
1314
|
-
"de": [ "Die Königin", "Ihre Majestät" ]
|
1315
|
-
}
|
1316
|
-
}),
|
1317
|
-
processingMode: "json-ld-1.1"
|
1318
|
-
},
|
1319
|
-
"simple map with overriding term direction": {
|
1320
|
-
input: %([
|
1321
|
-
{
|
1322
|
-
"@id": "http://example.com/queen",
|
1323
|
-
"http://example.com/vocab/label": [
|
1324
|
-
{"@value": "Die Königin", "@language": "de", "@direction": "ltr"},
|
1325
|
-
{"@value": "Ihre Majestät", "@language": "de", "@direction": "ltr"},
|
1326
|
-
{"@value": "The Queen", "@language": "en", "@direction": "ltr"}
|
1327
|
-
]
|
1328
|
-
}
|
1329
|
-
]),
|
1330
|
-
context: %({
|
1331
|
-
"@context": {
|
1332
|
-
"@version": 1.1,
|
1333
|
-
"@direction": "rtl",
|
1334
|
-
"vocab": "http://example.com/vocab/",
|
1335
|
-
"label": {
|
1336
|
-
"@id": "vocab:label",
|
1337
|
-
"@direction": "ltr",
|
1338
|
-
"@container": "@language"
|
1339
|
-
}
|
1340
|
-
}
|
1341
|
-
}),
|
1342
|
-
output: %({
|
1343
|
-
"@context": {
|
1344
|
-
"@version": 1.1,
|
1345
|
-
"@direction": "rtl",
|
1346
|
-
"vocab": "http://example.com/vocab/",
|
1347
|
-
"label": {
|
1348
|
-
"@id": "vocab:label",
|
1349
|
-
"@direction": "ltr",
|
1350
|
-
"@container": "@language"
|
1351
|
-
}
|
1352
|
-
},
|
1353
|
-
"@id": "http://example.com/queen",
|
1354
|
-
"label": {
|
1355
|
-
"en": "The Queen",
|
1356
|
-
"de": [ "Die Königin", "Ihre Majestät" ]
|
1357
|
-
}
|
1358
|
-
}),
|
1359
|
-
processingMode: "json-ld-1.1"
|
1360
|
-
},
|
1361
|
-
"simple map with overriding null direction": {
|
1362
|
-
input: %([
|
1363
|
-
{
|
1364
|
-
"@id": "http://example.com/queen",
|
1365
|
-
"http://example.com/vocab/label": [
|
1366
|
-
{"@value": "Die Königin", "@language": "de"},
|
1367
|
-
{"@value": "Ihre Majestät", "@language": "de"},
|
1368
|
-
{"@value": "The Queen", "@language": "en"}
|
1369
|
-
]
|
1370
|
-
}
|
1371
|
-
]),
|
1372
|
-
context: %({
|
1373
|
-
"@context": {
|
1374
|
-
"@version": 1.1,
|
1375
|
-
"@direction": "rtl",
|
1376
|
-
"vocab": "http://example.com/vocab/",
|
1377
|
-
"label": {
|
1378
|
-
"@id": "vocab:label",
|
1379
|
-
"@direction": null,
|
1380
|
-
"@container": "@language"
|
1381
|
-
}
|
1382
|
-
}
|
1383
|
-
}),
|
1384
|
-
output: %({
|
1385
|
-
"@context": {
|
1386
|
-
"@version": 1.1,
|
1387
|
-
"@direction": "rtl",
|
1388
|
-
"vocab": "http://example.com/vocab/",
|
1389
|
-
"label": {
|
1390
|
-
"@id": "vocab:label",
|
1391
|
-
"@direction": null,
|
1392
|
-
"@container": "@language"
|
1393
|
-
}
|
1394
|
-
},
|
1395
|
-
"@id": "http://example.com/queen",
|
1396
|
-
"label": {
|
1397
|
-
"en": "The Queen",
|
1398
|
-
"de": [ "Die Königin", "Ihre Majestät" ]
|
1399
|
-
}
|
1400
|
-
}),
|
1401
|
-
processingMode: "json-ld-1.1"
|
1402
|
-
},
|
1403
|
-
"simple map with mismatching term direction": {
|
1404
|
-
input: %([
|
1405
|
-
{
|
1406
|
-
"@id": "http://example.com/queen",
|
1407
|
-
"http://example.com/vocab/label": [
|
1408
|
-
{"@value": "Die Königin", "@language": "de"},
|
1409
|
-
{"@value": "Ihre Majestät", "@language": "de", "@direction": "ltr"},
|
1410
|
-
{"@value": "The Queen", "@language": "en", "@direction": "rtl"}
|
1411
|
-
]
|
1412
|
-
}
|
1413
|
-
]),
|
1414
|
-
context: %({
|
1415
|
-
"@context": {
|
1416
|
-
"@version": 1.1,
|
1417
|
-
"vocab": "http://example.com/vocab/",
|
1418
|
-
"label": {
|
1419
|
-
"@id": "vocab:label",
|
1420
|
-
"@direction": "rtl",
|
1421
|
-
"@container": "@language"
|
1422
|
-
}
|
1423
|
-
}
|
1424
|
-
}),
|
1425
|
-
output: %({
|
1426
|
-
"@context": {
|
1427
|
-
"@version": 1.1,
|
1428
|
-
"vocab": "http://example.com/vocab/",
|
1429
|
-
"label": {
|
1430
|
-
"@id": "vocab:label",
|
1431
|
-
"@direction": "rtl",
|
1432
|
-
"@container": "@language"
|
1433
|
-
}
|
1434
|
-
},
|
1435
|
-
"@id": "http://example.com/queen",
|
1436
|
-
"label": {
|
1437
|
-
"en": "The Queen"
|
1438
|
-
},
|
1439
|
-
"vocab:label": [
|
1440
|
-
{"@value": "Die Königin", "@language": "de"},
|
1441
|
-
{"@value": "Ihre Majestät", "@language": "de", "@direction": "ltr"}
|
1442
|
-
]
|
1443
|
-
}),
|
1444
|
-
processingMode: "json-ld-1.1"
|
1445
|
-
},
|
1446
|
-
}.each_pair do |title, params|
|
1447
|
-
it(title) {run_compact(params)}
|
1448
|
-
end
|
1449
|
-
end
|
1450
|
-
|
1451
|
-
context "@container: @id" do
|
1452
|
-
{
|
1453
|
-
"Indexes to object not having an @id" => {
|
1454
|
-
input: %([{
|
1455
|
-
"http://example/idmap": [
|
1456
|
-
{"http://example/label": [{"@value": "Object with @id _:bar"}], "@id": "_:bar"},
|
1457
|
-
{"http://example/label": [{"@value": "Object with @id <foo>"}], "@id": "http://example.org/foo"}
|
1458
|
-
]
|
1459
|
-
}]),
|
1460
|
-
context: %({
|
1461
|
-
"@vocab": "http://example/",
|
1462
|
-
"idmap": {"@container": "@id"}
|
1463
|
-
}),
|
1464
|
-
output: %({
|
1465
|
-
"@context": {
|
1466
|
-
"@vocab": "http://example/",
|
1467
|
-
"idmap": {"@container": "@id"}
|
1468
|
-
},
|
1469
|
-
"idmap": {
|
1470
|
-
"http://example.org/foo": {"label": "Object with @id <foo>"},
|
1471
|
-
"_:bar": {"label": "Object with @id _:bar"}
|
1472
|
-
}
|
1473
|
-
}),
|
1474
|
-
},
|
1475
|
-
"Indexes to object already having an @id" => {
|
1476
|
-
input: %([{
|
1477
|
-
"http://example/idmap": [
|
1478
|
-
{"@id": "_:foo", "http://example/label": [{"@value": "Object with @id _:bar"}]},
|
1479
|
-
{"@id": "http://example.org/bar", "http://example/label": [{"@value": "Object with @id <foo>"}]}
|
1480
|
-
]
|
1481
|
-
}]),
|
1482
|
-
context: %({
|
1483
|
-
"@vocab": "http://example/",
|
1484
|
-
"idmap": {"@container": "@id"}
|
1485
|
-
}),
|
1486
|
-
output: %({
|
1487
|
-
"@context": {
|
1488
|
-
"@vocab": "http://example/",
|
1489
|
-
"idmap": {"@container": "@id"}
|
1490
|
-
},
|
1491
|
-
"idmap": {
|
1492
|
-
"_:foo": {"label": "Object with @id _:bar"},
|
1493
|
-
"http://example.org/bar": {"label": "Object with @id <foo>"}
|
1494
|
-
}
|
1495
|
-
}),
|
1496
|
-
},
|
1497
|
-
"Indexes to object using compact IRI @id" => {
|
1498
|
-
input: %([{
|
1499
|
-
"http://example/idmap": [
|
1500
|
-
{"http://example/label": [{"@value": "Object with @id <foo>"}], "@id": "http://example.org/foo"}
|
1501
|
-
]
|
1502
|
-
}]),
|
1503
|
-
context: %({
|
1504
|
-
"@vocab": "http://example/",
|
1505
|
-
"ex": "http://example.org/",
|
1506
|
-
"idmap": {"@container": "@id"}
|
1507
|
-
}),
|
1508
|
-
output: %({
|
1509
|
-
"@context": {
|
1510
|
-
"@vocab": "http://example/",
|
1511
|
-
"ex": "http://example.org/",
|
1512
|
-
"idmap": {"@container": "@id"}
|
1513
|
-
},
|
1514
|
-
"idmap": {
|
1515
|
-
"ex:foo": {"label": "Object with @id <foo>"}
|
1516
|
-
}
|
1517
|
-
})
|
1518
|
-
},
|
1519
|
-
"Indexes using @none" => {
|
1520
|
-
input: %([{
|
1521
|
-
"http://example/idmap": [
|
1522
|
-
{"http://example/label": [{"@value": "Object with no @id"}]}
|
1523
|
-
]
|
1524
|
-
}]),
|
1525
|
-
context: %({
|
1526
|
-
"@vocab": "http://example/",
|
1527
|
-
"ex": "http://example.org/",
|
1528
|
-
"idmap": {"@container": "@id"}
|
1529
|
-
}),
|
1530
|
-
output: %({
|
1531
|
-
"@context": {
|
1532
|
-
"@vocab": "http://example/",
|
1533
|
-
"ex": "http://example.org/",
|
1534
|
-
"idmap": {"@container": "@id"}
|
1535
|
-
},
|
1536
|
-
"idmap": {
|
1537
|
-
"@none": {"label": "Object with no @id"}
|
1538
|
-
}
|
1539
|
-
})
|
1540
|
-
},
|
1541
|
-
"Indexes using @none with alias" => {
|
1542
|
-
input: %([{
|
1543
|
-
"http://example/idmap": [
|
1544
|
-
{"http://example/label": [{"@value": "Object with no @id"}]}
|
1545
|
-
]
|
1546
|
-
}]),
|
1547
|
-
context: %({
|
1548
|
-
"@vocab": "http://example/",
|
1549
|
-
"ex": "http://example.org/",
|
1550
|
-
"idmap": {"@container": "@id"},
|
1551
|
-
"none": "@none"
|
1552
|
-
}),
|
1553
|
-
output: %({
|
1554
|
-
"@context": {
|
1555
|
-
"@vocab": "http://example/",
|
1556
|
-
"ex": "http://example.org/",
|
1557
|
-
"idmap": {"@container": "@id"},
|
1558
|
-
"none": "@none"
|
1559
|
-
},
|
1560
|
-
"idmap": {
|
1561
|
-
"none": {"label": "Object with no @id"}
|
1562
|
-
}
|
1563
|
-
})
|
1564
|
-
},
|
1565
|
-
}.each_pair do |title, params|
|
1566
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
1567
|
-
end
|
1568
|
-
end
|
1569
|
-
|
1570
|
-
context "@container: @type" do
|
1571
|
-
{
|
1572
|
-
"Indexes to object not having an @type" => {
|
1573
|
-
input: %([{
|
1574
|
-
"http://example/typemap": [
|
1575
|
-
{"http://example/label": [{"@value": "Object with @type _:bar"}], "@type": ["_:bar"]},
|
1576
|
-
{"http://example/label": [{"@value": "Object with @type <foo>"}], "@type": ["http://example.org/foo"]}
|
1577
|
-
]
|
1578
|
-
}]),
|
1579
|
-
context: %({
|
1580
|
-
"@vocab": "http://example/",
|
1581
|
-
"typemap": {"@container": "@type"}
|
1582
|
-
}),
|
1583
|
-
output: %({
|
1584
|
-
"@context": {
|
1585
|
-
"@vocab": "http://example/",
|
1586
|
-
"typemap": {"@container": "@type"}
|
1587
|
-
},
|
1588
|
-
"typemap": {
|
1589
|
-
"http://example.org/foo": {"label": "Object with @type <foo>"},
|
1590
|
-
"_:bar": {"label": "Object with @type _:bar"}
|
1591
|
-
}
|
1592
|
-
})
|
1593
|
-
},
|
1594
|
-
"Indexes to object already having an @type" => {
|
1595
|
-
input: %([{
|
1596
|
-
"http://example/typemap": [
|
1597
|
-
{
|
1598
|
-
"@type": ["_:bar", "_:foo"],
|
1599
|
-
"http://example/label": [{"@value": "Object with @type _:bar"}]
|
1600
|
-
},
|
1601
|
-
{
|
1602
|
-
"@type": ["http://example.org/foo", "http://example.org/bar"],
|
1603
|
-
"http://example/label": [{"@value": "Object with @type <foo>"}]
|
1604
|
-
}
|
1605
|
-
]
|
1606
|
-
}]),
|
1607
|
-
context: %({
|
1608
|
-
"@vocab": "http://example/",
|
1609
|
-
"typemap": {"@container": "@type"}
|
1610
|
-
}),
|
1611
|
-
output: %({
|
1612
|
-
"@context": {
|
1613
|
-
"@vocab": "http://example/",
|
1614
|
-
"typemap": {"@container": "@type"}
|
1615
|
-
},
|
1616
|
-
"typemap": {
|
1617
|
-
"http://example.org/foo": {"@type": "http://example.org/bar", "label": "Object with @type <foo>"},
|
1618
|
-
"_:bar": {"@type": "_:foo", "label": "Object with @type _:bar"}
|
1619
|
-
}
|
1620
|
-
})
|
1621
|
-
},
|
1622
|
-
"Indexes to object already having multiple @type values" => {
|
1623
|
-
input: %([{
|
1624
|
-
"http://example/typemap": [
|
1625
|
-
{
|
1626
|
-
"@type": ["_:bar", "_:foo", "_:baz"],
|
1627
|
-
"http://example/label": [{"@value": "Object with @type _:bar"}]
|
1628
|
-
},
|
1629
|
-
{
|
1630
|
-
"@type": ["http://example.org/foo", "http://example.org/bar", "http://example.org/baz"],
|
1631
|
-
"http://example/label": [{"@value": "Object with @type <foo>"}]
|
1632
|
-
}
|
1633
|
-
]
|
1634
|
-
}]),
|
1635
|
-
context: %({
|
1636
|
-
"@vocab": "http://example/",
|
1637
|
-
"typemap": {"@container": "@type"}
|
1638
|
-
}),
|
1639
|
-
output: %({
|
1640
|
-
"@context": {
|
1641
|
-
"@vocab": "http://example/",
|
1642
|
-
"typemap": {"@container": "@type"}
|
1643
|
-
},
|
1644
|
-
"typemap": {
|
1645
|
-
"http://example.org/foo": {"@type": ["http://example.org/bar", "http://example.org/baz"], "label": "Object with @type <foo>"},
|
1646
|
-
"_:bar": {"@type": ["_:foo", "_:baz"], "label": "Object with @type _:bar"}
|
1647
|
-
}
|
1648
|
-
})
|
1649
|
-
},
|
1650
|
-
"Indexes using compacted @type" => {
|
1651
|
-
input: %([{
|
1652
|
-
"http://example/typemap": [
|
1653
|
-
{"http://example/label": [{"@value": "Object with @type <foo>"}], "@type": ["http://example/Foo"]}
|
1654
|
-
]
|
1655
|
-
}]),
|
1656
|
-
context: %({
|
1657
|
-
"@vocab": "http://example/",
|
1658
|
-
"typemap": {"@container": "@type"}
|
1659
|
-
}),
|
1660
|
-
output: %({
|
1661
|
-
"@context": {
|
1662
|
-
"@vocab": "http://example/",
|
1663
|
-
"typemap": {"@container": "@type"}
|
1664
|
-
},
|
1665
|
-
"typemap": {
|
1666
|
-
"Foo": {"label": "Object with @type <foo>"}
|
1667
|
-
}
|
1668
|
-
})
|
1669
|
-
},
|
1670
|
-
"Indexes using @none" => {
|
1671
|
-
input: %([{
|
1672
|
-
"http://example/typemap": [
|
1673
|
-
{"http://example/label": [{"@value": "Object with no @type"}]}
|
1674
|
-
]
|
1675
|
-
}]),
|
1676
|
-
context: %({
|
1677
|
-
"@vocab": "http://example/",
|
1678
|
-
"ex": "http://example.org/",
|
1679
|
-
"typemap": {"@container": "@type"}
|
1680
|
-
}),
|
1681
|
-
output: %({
|
1682
|
-
"@context": {
|
1683
|
-
"@vocab": "http://example/",
|
1684
|
-
"ex": "http://example.org/",
|
1685
|
-
"typemap": {"@container": "@type"}
|
1686
|
-
},
|
1687
|
-
"typemap": {
|
1688
|
-
"@none": {"label": "Object with no @type"}
|
1689
|
-
}
|
1690
|
-
})
|
1691
|
-
},
|
1692
|
-
"Indexes using @none with alias" => {
|
1693
|
-
input: %([{
|
1694
|
-
"http://example/typemap": [
|
1695
|
-
{"http://example/label": [{"@value": "Object with no @id"}]}
|
1696
|
-
]
|
1697
|
-
}]),
|
1698
|
-
context: %({
|
1699
|
-
"@vocab": "http://example/",
|
1700
|
-
"ex": "http://example.org/",
|
1701
|
-
"typemap": {"@container": "@type"},
|
1702
|
-
"none": "@none"
|
1703
|
-
}),
|
1704
|
-
output: %({
|
1705
|
-
"@context": {
|
1706
|
-
"@vocab": "http://example/",
|
1707
|
-
"ex": "http://example.org/",
|
1708
|
-
"typemap": {"@container": "@type"},
|
1709
|
-
"none": "@none"
|
1710
|
-
},
|
1711
|
-
"typemap": {
|
1712
|
-
"none": {"label": "Object with no @id"}
|
1713
|
-
}
|
1714
|
-
})
|
1715
|
-
},
|
1716
|
-
}.each_pair do |title, params|
|
1717
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
1718
|
-
end
|
1719
|
-
end
|
1720
|
-
|
1721
|
-
context "@container: @graph" do
|
1722
|
-
{
|
1723
|
-
"Compacts simple graph" => {
|
1724
|
-
input: %([{
|
1725
|
-
"http://example.org/input": [{
|
1726
|
-
"@graph": [{
|
1727
|
-
"http://example.org/value": [{"@value": "x"}]
|
1728
|
-
}]
|
1729
|
-
}]
|
1730
|
-
}]),
|
1731
|
-
context: %({
|
1732
|
-
"@vocab": "http://example.org/",
|
1733
|
-
"input": {"@container": "@graph"}
|
1734
|
-
}),
|
1735
|
-
output: %({
|
1736
|
-
"@context": {
|
1737
|
-
"@vocab": "http://example.org/",
|
1738
|
-
"input": {"@container": "@graph"}
|
1739
|
-
},
|
1740
|
-
"input": {
|
1741
|
-
"value": "x"
|
1742
|
-
}
|
1743
|
-
})
|
1744
|
-
},
|
1745
|
-
"Compacts simple graph with @set" => {
|
1746
|
-
input: %([{
|
1747
|
-
"http://example.org/input": [{
|
1748
|
-
"@graph": [{
|
1749
|
-
"http://example.org/value": [{"@value": "x"}]
|
1750
|
-
}]
|
1751
|
-
}]
|
1752
|
-
}]),
|
1753
|
-
context: %({
|
1754
|
-
"@vocab": "http://example.org/",
|
1755
|
-
"input": {"@container": ["@graph", "@set"]}
|
1756
|
-
}),
|
1757
|
-
output: %({
|
1758
|
-
"@context": {
|
1759
|
-
"@vocab": "http://example.org/",
|
1760
|
-
"input": {"@container": ["@graph", "@set"]}
|
1761
|
-
},
|
1762
|
-
"input": [{
|
1763
|
-
"value": "x"
|
1764
|
-
}]
|
1765
|
-
})
|
1766
|
-
},
|
1767
|
-
"Compacts simple graph with @index" => {
|
1768
|
-
input: %([{
|
1769
|
-
"http://example.org/input": [{
|
1770
|
-
"@graph": [{
|
1771
|
-
"http://example.org/value": [{"@value": "x"}]
|
1772
|
-
}],
|
1773
|
-
"@index": "ndx"
|
1774
|
-
}]
|
1775
|
-
}]),
|
1776
|
-
context: %({
|
1777
|
-
"@vocab": "http://example.org/",
|
1778
|
-
"input": {"@container": "@graph"}
|
1779
|
-
}),
|
1780
|
-
output: %({
|
1781
|
-
"@context": {
|
1782
|
-
"@vocab": "http://example.org/",
|
1783
|
-
"input": {"@container": "@graph"}
|
1784
|
-
},
|
1785
|
-
"input": {
|
1786
|
-
"value": "x"
|
1787
|
-
}
|
1788
|
-
})
|
1789
|
-
},
|
1790
|
-
"Compacts simple graph with @index and multiple nodes" => {
|
1791
|
-
input: %([{
|
1792
|
-
"http://example.org/input": [{
|
1793
|
-
"@graph": [{
|
1794
|
-
"http://example.org/value": [{"@value": "x"}]
|
1795
|
-
}, {
|
1796
|
-
"http://example.org/value": [{"@value": "y"}]
|
1797
|
-
}],
|
1798
|
-
"@index": "ndx"
|
1799
|
-
}]
|
1800
|
-
}]),
|
1801
|
-
context: %({
|
1802
|
-
"@vocab": "http://example.org/",
|
1803
|
-
"input": {"@container": "@graph"}
|
1804
|
-
}),
|
1805
|
-
output: %({
|
1806
|
-
"@context": {
|
1807
|
-
"@vocab": "http://example.org/",
|
1808
|
-
"input": {"@container": "@graph"}
|
1809
|
-
},
|
1810
|
-
"input": {
|
1811
|
-
"@included": [{
|
1812
|
-
"value": "x"
|
1813
|
-
}, {
|
1814
|
-
"value": "y"
|
1815
|
-
}]
|
1816
|
-
}
|
1817
|
-
})
|
1818
|
-
},
|
1819
|
-
"Does not compact graph with @id" => {
|
1820
|
-
input: %([{
|
1821
|
-
"http://example.org/input": [{
|
1822
|
-
"@graph": [{
|
1823
|
-
"http://example.org/value": [{"@value": "x"}]
|
1824
|
-
}],
|
1825
|
-
"@id": "http://example.org/id"
|
1826
|
-
}]
|
1827
|
-
}]),
|
1828
|
-
context: %({
|
1829
|
-
"@vocab": "http://example.org/",
|
1830
|
-
"input": {"@container": "@graph"}
|
1831
|
-
}),
|
1832
|
-
output: %({
|
1833
|
-
"@context": {
|
1834
|
-
"@vocab": "http://example.org/",
|
1835
|
-
"input": {"@container": "@graph"}
|
1836
|
-
},
|
1837
|
-
"input": {
|
1838
|
-
"@id": "http://example.org/id",
|
1839
|
-
"@graph": {"value": "x"}
|
1840
|
-
}
|
1841
|
-
})
|
1842
|
-
},
|
1843
|
-
"Odd framing test" => {
|
1844
|
-
input: %([
|
1845
|
-
{
|
1846
|
-
"http://example.org/claim": [
|
1847
|
-
{
|
1848
|
-
"@graph": [
|
1849
|
-
{
|
1850
|
-
"@id": "http://example.org/1",
|
1851
|
-
"https://example.com#test": [
|
1852
|
-
{
|
1853
|
-
"@value": "foo"
|
1854
|
-
}
|
1855
|
-
]
|
1856
|
-
}
|
1857
|
-
]
|
1858
|
-
}
|
1859
|
-
]
|
1860
|
-
}
|
1861
|
-
]
|
1862
|
-
),
|
1863
|
-
context: %( {
|
1864
|
-
"@version": 1.1,
|
1865
|
-
"@vocab": "https://example.com#",
|
1866
|
-
"ex": "http://example.org/",
|
1867
|
-
"claim": {
|
1868
|
-
"@id": "ex:claim",
|
1869
|
-
"@container": "@graph"
|
1870
|
-
},
|
1871
|
-
"id": "@id"
|
1872
|
-
}),
|
1873
|
-
output: %({
|
1874
|
-
"@context": {
|
1875
|
-
"@version": 1.1,
|
1876
|
-
"@vocab": "https://example.com#",
|
1877
|
-
"ex": "http://example.org/",
|
1878
|
-
"claim": {
|
1879
|
-
"@id": "ex:claim",
|
1880
|
-
"@container": "@graph"
|
1881
|
-
},
|
1882
|
-
"id": "@id"
|
1883
|
-
},
|
1884
|
-
"claim": {
|
1885
|
-
"id": "ex:1",
|
1886
|
-
"test": "foo"
|
1887
|
-
}
|
1888
|
-
})
|
1889
|
-
}
|
1890
|
-
}.each_pair do |title, params|
|
1891
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
1892
|
-
end
|
1893
|
-
|
1894
|
-
context "+ @index" do
|
1895
|
-
{
|
1896
|
-
"Compacts simple graph" => {
|
1897
|
-
input: %([{
|
1898
|
-
"http://example.org/input": [{
|
1899
|
-
"@index": "g1",
|
1900
|
-
"@graph": [{
|
1901
|
-
"http://example.org/value": [{"@value": "x"}]
|
1902
|
-
}]
|
1903
|
-
}]
|
1904
|
-
}]),
|
1905
|
-
context: %({
|
1906
|
-
"@vocab": "http://example.org/",
|
1907
|
-
"input": {"@container": ["@graph", "@index"]}
|
1908
|
-
}),
|
1909
|
-
output: %({
|
1910
|
-
"@context": {
|
1911
|
-
"@vocab": "http://example.org/",
|
1912
|
-
"input": {"@container": ["@graph", "@index"]}
|
1913
|
-
},
|
1914
|
-
"input": {
|
1915
|
-
"g1": {"value": "x"}
|
1916
|
-
}
|
1917
|
-
})
|
1918
|
-
},
|
1919
|
-
"Compacts simple graph with @set" => {
|
1920
|
-
input: %([{
|
1921
|
-
"http://example.org/input": [{
|
1922
|
-
"@index": "g1",
|
1923
|
-
"@graph": [{
|
1924
|
-
"http://example.org/value": [{"@value": "x"}]
|
1925
|
-
}]
|
1926
|
-
}]
|
1927
|
-
}]),
|
1928
|
-
context: %({
|
1929
|
-
"@vocab": "http://example.org/",
|
1930
|
-
"input": {"@container": ["@graph", "@index", "@set"]}
|
1931
|
-
}),
|
1932
|
-
output: %({
|
1933
|
-
"@context": {
|
1934
|
-
"@vocab": "http://example.org/",
|
1935
|
-
"input": {"@container": ["@graph", "@index", "@set"]}
|
1936
|
-
},
|
1937
|
-
"input": {
|
1938
|
-
"g1": [{"value": "x"}]
|
1939
|
-
}
|
1940
|
-
})
|
1941
|
-
},
|
1942
|
-
"Compacts simple graph with no @index" => {
|
1943
|
-
input: %([{
|
1944
|
-
"http://example.org/input": [{
|
1945
|
-
"@graph": [{
|
1946
|
-
"http://example.org/value": [{"@value": "x"}]
|
1947
|
-
}]
|
1948
|
-
}]
|
1949
|
-
}]),
|
1950
|
-
context: %({
|
1951
|
-
"@vocab": "http://example.org/",
|
1952
|
-
"input": {"@container": ["@graph", "@index", "@set"]}
|
1953
|
-
}),
|
1954
|
-
output: %({
|
1955
|
-
"@context": {
|
1956
|
-
"@vocab": "http://example.org/",
|
1957
|
-
"input": {"@container": ["@graph", "@index", "@set"]}
|
1958
|
-
},
|
1959
|
-
"input": {
|
1960
|
-
"@none": [{"value": "x"}]
|
1961
|
-
}
|
1962
|
-
})
|
1963
|
-
},
|
1964
|
-
"Does not compact graph with @id" => {
|
1965
|
-
input: %([{
|
1966
|
-
"http://example.org/input": [{
|
1967
|
-
"@graph": [{
|
1968
|
-
"http://example.org/value": [{"@value": "x"}]
|
1969
|
-
}],
|
1970
|
-
"@index": "g1",
|
1971
|
-
"@id": "http://example.org/id"
|
1972
|
-
}]
|
1973
|
-
}]),
|
1974
|
-
context: %({
|
1975
|
-
"@vocab": "http://example.org/",
|
1976
|
-
"input": {"@container": ["@graph", "@index"]}
|
1977
|
-
}),
|
1978
|
-
output: %({
|
1979
|
-
"@context": {
|
1980
|
-
"@vocab": "http://example.org/",
|
1981
|
-
"input": {"@container": ["@graph", "@index"]}
|
1982
|
-
},
|
1983
|
-
"input": {
|
1984
|
-
"@id": "http://example.org/id",
|
1985
|
-
"@index": "g1",
|
1986
|
-
"@graph": {"value": "x"}
|
1987
|
-
}
|
1988
|
-
})
|
1989
|
-
},
|
1990
|
-
}.each_pair do |title, params|
|
1991
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
1992
|
-
end
|
1993
|
-
end
|
1994
|
-
|
1995
|
-
context "+ @id" do
|
1996
|
-
{
|
1997
|
-
"Compacts simple graph" => {
|
1998
|
-
input: %([{
|
1999
|
-
"http://example.org/input": [{
|
2000
|
-
"@graph": [{
|
2001
|
-
"http://example.org/value": [{"@value": "x"}]
|
2002
|
-
}]
|
2003
|
-
}]
|
2004
|
-
}]),
|
2005
|
-
context: %({
|
2006
|
-
"@vocab": "http://example.org/",
|
2007
|
-
"input": {"@container": ["@graph", "@id"]}
|
2008
|
-
}),
|
2009
|
-
output: %({
|
2010
|
-
"@context": {
|
2011
|
-
"@vocab": "http://example.org/",
|
2012
|
-
"input": {"@container": ["@graph", "@id"]}
|
2013
|
-
},
|
2014
|
-
"input": {
|
2015
|
-
"@none": {"value": "x"}
|
2016
|
-
}
|
2017
|
-
})
|
2018
|
-
},
|
2019
|
-
"Compacts simple graph with @set" => {
|
2020
|
-
input: %([{
|
2021
|
-
"http://example.org/input": [{
|
2022
|
-
"@graph": [{
|
2023
|
-
"http://example.org/value": [{"@value": "x"}]
|
2024
|
-
}]
|
2025
|
-
}]
|
2026
|
-
}]),
|
2027
|
-
context: %({
|
2028
|
-
"@vocab": "http://example.org/",
|
2029
|
-
"input": {"@container": ["@graph", "@id", "@set"]}
|
2030
|
-
}),
|
2031
|
-
output: %({
|
2032
|
-
"@context": {
|
2033
|
-
"@vocab": "http://example.org/",
|
2034
|
-
"input": {"@container": ["@graph", "@id", "@set"]}
|
2035
|
-
},
|
2036
|
-
"input": {"@none": [{"value": "x"}]}
|
2037
|
-
})
|
2038
|
-
},
|
2039
|
-
"Compacts simple graph with @index" => {
|
2040
|
-
input: %([{
|
2041
|
-
"http://example.org/input": [{
|
2042
|
-
"@graph": [{
|
2043
|
-
"http://example.org/value": [{"@value": "x"}]
|
2044
|
-
}],
|
2045
|
-
"@index": "ndx"
|
2046
|
-
}]
|
2047
|
-
}]),
|
2048
|
-
context: %({
|
2049
|
-
"@vocab": "http://example.org/",
|
2050
|
-
"input": {"@container": ["@graph", "@id"]}
|
2051
|
-
}),
|
2052
|
-
output: %({
|
2053
|
-
"@context": {
|
2054
|
-
"@vocab": "http://example.org/",
|
2055
|
-
"input": {"@container": ["@graph", "@id"]}
|
2056
|
-
},
|
2057
|
-
"input": {
|
2058
|
-
"@none": {"value": "x"}
|
2059
|
-
}
|
2060
|
-
})
|
2061
|
-
},
|
2062
|
-
"Compacts graph with @id" => {
|
2063
|
-
input: %([{
|
2064
|
-
"http://example.org/input": [{
|
2065
|
-
"@graph": [{
|
2066
|
-
"http://example.org/value": [{"@value": "x"}]
|
2067
|
-
}],
|
2068
|
-
"@id": "http://example.org/id"
|
2069
|
-
}]
|
2070
|
-
}]),
|
2071
|
-
context: %({
|
2072
|
-
"@vocab": "http://example.org/",
|
2073
|
-
"input": {"@container": ["@graph", "@id"]}
|
2074
|
-
}),
|
2075
|
-
output: %({
|
2076
|
-
"@context": {
|
2077
|
-
"@vocab": "http://example.org/",
|
2078
|
-
"input": {"@container": ["@graph", "@id"]}
|
2079
|
-
},
|
2080
|
-
"input": {
|
2081
|
-
"http://example.org/id" : {"value": "x"}
|
2082
|
-
}
|
2083
|
-
})
|
2084
|
-
},
|
2085
|
-
"Compacts graph with @id and @set" => {
|
2086
|
-
input: %([{
|
2087
|
-
"http://example.org/input": [{
|
2088
|
-
"@graph": [{
|
2089
|
-
"http://example.org/value": [{"@value": "x"}]
|
2090
|
-
}],
|
2091
|
-
"@id": "http://example.org/id"
|
2092
|
-
}]
|
2093
|
-
}]),
|
2094
|
-
context: %({
|
2095
|
-
"@vocab": "http://example.org/",
|
2096
|
-
"input": {"@container": ["@graph", "@id", "@set"]}
|
2097
|
-
}),
|
2098
|
-
output: %({
|
2099
|
-
"@context": {
|
2100
|
-
"@vocab": "http://example.org/",
|
2101
|
-
"input": {"@container": ["@graph", "@id", "@set"]}
|
2102
|
-
},
|
2103
|
-
"input": {
|
2104
|
-
"http://example.org/id" : [{"value": "x"}]
|
2105
|
-
}
|
2106
|
-
})
|
2107
|
-
},
|
2108
|
-
"Compacts graph without @id" => {
|
2109
|
-
input: %([{
|
2110
|
-
"http://example.org/input": [{
|
2111
|
-
"@graph": [{
|
2112
|
-
"http://example.org/value": [{"@value": "x"}]
|
2113
|
-
}]
|
2114
|
-
}]
|
2115
|
-
}]),
|
2116
|
-
context: %({
|
2117
|
-
"@vocab": "http://example.org/",
|
2118
|
-
"input": {"@container": ["@graph", "@id"]}
|
2119
|
-
}),
|
2120
|
-
output: %({
|
2121
|
-
"@context": {
|
2122
|
-
"@vocab": "http://example.org/",
|
2123
|
-
"input": {"@container": ["@graph", "@id"]}
|
2124
|
-
},
|
2125
|
-
"input": {
|
2126
|
-
"@none" : {"value": "x"}
|
2127
|
-
}
|
2128
|
-
})
|
2129
|
-
},
|
2130
|
-
"Compacts graph without @id using alias of @none" => {
|
2131
|
-
input: %([{
|
2132
|
-
"http://example.org/input": [{
|
2133
|
-
"@graph": [{
|
2134
|
-
"http://example.org/value": [{"@value": "x"}]
|
2135
|
-
}]
|
2136
|
-
}]
|
2137
|
-
}]),
|
2138
|
-
context: %({
|
2139
|
-
"@vocab": "http://example.org/",
|
2140
|
-
"input": {"@container": ["@graph", "@id"]},
|
2141
|
-
"none": "@none"
|
2142
|
-
}),
|
2143
|
-
output: %({
|
2144
|
-
"@context": {
|
2145
|
-
"@vocab": "http://example.org/",
|
2146
|
-
"input": {"@container": ["@graph", "@id"]},
|
2147
|
-
"none": "@none"
|
2148
|
-
},
|
2149
|
-
"input": {
|
2150
|
-
"none" : {"value": "x"}
|
2151
|
-
}
|
2152
|
-
})
|
2153
|
-
},
|
2154
|
-
}.each_pair do |title, params|
|
2155
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
2156
|
-
end
|
2157
|
-
end
|
2158
|
-
end
|
2159
|
-
|
2160
|
-
context "@included" do
|
2161
|
-
{
|
2162
|
-
"Basic Included array": {
|
2163
|
-
output: %({
|
2164
|
-
"@context": {
|
2165
|
-
"@version": 1.1,
|
2166
|
-
"@vocab": "http://example.org/",
|
2167
|
-
"included": {"@id": "@included", "@container": "@set"}
|
2168
|
-
},
|
2169
|
-
"prop": "value",
|
2170
|
-
"included": [{
|
2171
|
-
"prop": "value2"
|
2172
|
-
}]
|
2173
|
-
}),
|
2174
|
-
input: %([{
|
2175
|
-
"http://example.org/prop": [{"@value": "value"}],
|
2176
|
-
"@included": [{
|
2177
|
-
"http://example.org/prop": [{"@value": "value2"}]
|
2178
|
-
}]
|
2179
|
-
}])
|
2180
|
-
},
|
2181
|
-
"Basic Included object": {
|
2182
|
-
output: %({
|
2183
|
-
"@context": {
|
2184
|
-
"@version": 1.1,
|
2185
|
-
"@vocab": "http://example.org/"
|
2186
|
-
},
|
2187
|
-
"prop": "value",
|
2188
|
-
"@included": {
|
2189
|
-
"prop": "value2"
|
2190
|
-
}
|
2191
|
-
}),
|
2192
|
-
input: %([{
|
2193
|
-
"http://example.org/prop": [{"@value": "value"}],
|
2194
|
-
"@included": [{
|
2195
|
-
"http://example.org/prop": [{"@value": "value2"}]
|
2196
|
-
}]
|
2197
|
-
}])
|
2198
|
-
},
|
2199
|
-
"Multiple properties mapping to @included are folded together": {
|
2200
|
-
output: %({
|
2201
|
-
"@context": {
|
2202
|
-
"@version": 1.1,
|
2203
|
-
"@vocab": "http://example.org/",
|
2204
|
-
"included1": "@included",
|
2205
|
-
"included2": "@included"
|
2206
|
-
},
|
2207
|
-
"included1": [
|
2208
|
-
{"prop": "value1"},
|
2209
|
-
{"prop": "value2"}
|
2210
|
-
]
|
2211
|
-
}),
|
2212
|
-
input: %([{
|
2213
|
-
"@included": [
|
2214
|
-
{"http://example.org/prop": [{"@value": "value1"}]},
|
2215
|
-
{"http://example.org/prop": [{"@value": "value2"}]}
|
2216
|
-
]
|
2217
|
-
}])
|
2218
|
-
},
|
2219
|
-
"Included containing @included": {
|
2220
|
-
output: %({
|
2221
|
-
"@context": {
|
2222
|
-
"@version": 1.1,
|
2223
|
-
"@vocab": "http://example.org/"
|
2224
|
-
},
|
2225
|
-
"prop": "value",
|
2226
|
-
"@included": {
|
2227
|
-
"prop": "value2",
|
2228
|
-
"@included": {
|
2229
|
-
"prop": "value3"
|
2230
|
-
}
|
2231
|
-
}
|
2232
|
-
}),
|
2233
|
-
input: %([{
|
2234
|
-
"http://example.org/prop": [{"@value": "value"}],
|
2235
|
-
"@included": [{
|
2236
|
-
"http://example.org/prop": [{"@value": "value2"}],
|
2237
|
-
"@included": [{
|
2238
|
-
"http://example.org/prop": [{"@value": "value3"}]
|
2239
|
-
}]
|
2240
|
-
}]
|
2241
|
-
}])
|
2242
|
-
},
|
2243
|
-
"Property value with @included": {
|
2244
|
-
output: %({
|
2245
|
-
"@context": {
|
2246
|
-
"@version": 1.1,
|
2247
|
-
"@vocab": "http://example.org/"
|
2248
|
-
},
|
2249
|
-
"prop": {
|
2250
|
-
"@type": "Foo",
|
2251
|
-
"@included": {
|
2252
|
-
"@type": "Bar"
|
2253
|
-
}
|
2254
|
-
}
|
2255
|
-
}),
|
2256
|
-
input: %([{
|
2257
|
-
"http://example.org/prop": [{
|
2258
|
-
"@type": ["http://example.org/Foo"],
|
2259
|
-
"@included": [{
|
2260
|
-
"@type": ["http://example.org/Bar"]
|
2261
|
-
}]
|
2262
|
-
}]
|
2263
|
-
}])
|
2264
|
-
},
|
2265
|
-
}.each do |title, params|
|
2266
|
-
it(title) {run_compact(params)}
|
2267
|
-
end
|
2268
|
-
end
|
2269
|
-
|
2270
|
-
context "@nest" do
|
2271
|
-
{
|
2272
|
-
"Indexes to @nest for property with @nest" => {
|
2273
|
-
input: %([{
|
2274
|
-
"http://example.org/p1": [{"@value": "v1"}],
|
2275
|
-
"http://example.org/p2": [{"@value": "v2"}]
|
2276
|
-
}]),
|
2277
|
-
context: %({
|
2278
|
-
"@vocab": "http://example.org/",
|
2279
|
-
"p2": {"@nest": "@nest"}
|
2280
|
-
}),
|
2281
|
-
output: %({
|
2282
|
-
"@context": {
|
2283
|
-
"@vocab": "http://example.org/",
|
2284
|
-
"p2": {"@nest": "@nest"}
|
2285
|
-
},
|
2286
|
-
"p1": "v1",
|
2287
|
-
"@nest": {
|
2288
|
-
"p2": "v2"
|
2289
|
-
}
|
2290
|
-
})
|
2291
|
-
},
|
2292
|
-
"Indexes to @nest for all properties with @nest" => {
|
2293
|
-
input: %([{
|
2294
|
-
"http://example.org/p1": [{"@value": "v1"}],
|
2295
|
-
"http://example.org/p2": [{"@value": "v2"}]
|
2296
|
-
}]),
|
2297
|
-
context: %({
|
2298
|
-
"@vocab": "http://example.org/",
|
2299
|
-
"p1": {"@nest": "@nest"},
|
2300
|
-
"p2": {"@nest": "@nest"}
|
2301
|
-
}),
|
2302
|
-
output: %({
|
2303
|
-
"@context": {
|
2304
|
-
"@vocab": "http://example.org/",
|
2305
|
-
"p1": {"@nest": "@nest"},
|
2306
|
-
"p2": {"@nest": "@nest"}
|
2307
|
-
},
|
2308
|
-
"@nest": {
|
2309
|
-
"p1": "v1",
|
2310
|
-
"p2": "v2"
|
2311
|
-
}
|
2312
|
-
})
|
2313
|
-
},
|
2314
|
-
"Nests using alias of @nest" => {
|
2315
|
-
input: %([{
|
2316
|
-
"http://example.org/p1": [{"@value": "v1"}],
|
2317
|
-
"http://example.org/p2": [{"@value": "v2"}]
|
2318
|
-
}]),
|
2319
|
-
context: %({
|
2320
|
-
"@vocab": "http://example.org/",
|
2321
|
-
"nest": "@nest",
|
2322
|
-
"p2": {"@nest": "nest"}
|
2323
|
-
}),
|
2324
|
-
output: %({
|
2325
|
-
"@context": {
|
2326
|
-
"@vocab": "http://example.org/",
|
2327
|
-
"nest": "@nest",
|
2328
|
-
"p2": {"@nest": "nest"}
|
2329
|
-
},
|
2330
|
-
"p1": "v1",
|
2331
|
-
"nest": {
|
2332
|
-
"p2": "v2"
|
2333
|
-
}
|
2334
|
-
})
|
2335
|
-
},
|
2336
|
-
"Arrays of nested values" => {
|
2337
|
-
input: %([{
|
2338
|
-
"http://example.org/p1": [{"@value": "v1"}],
|
2339
|
-
"http://example.org/p2": [{"@value": "v2"}, {"@value": "v3"}]
|
2340
|
-
}]),
|
2341
|
-
context: %({
|
2342
|
-
"@vocab": "http://example.org/",
|
2343
|
-
"p2": {"@nest": "@nest"}
|
2344
|
-
}),
|
2345
|
-
output: %({
|
2346
|
-
"@context": {
|
2347
|
-
"@vocab": "http://example.org/",
|
2348
|
-
"p2": {"@nest": "@nest"}
|
2349
|
-
},
|
2350
|
-
"p1": "v1",
|
2351
|
-
"@nest": {
|
2352
|
-
"p2": ["v2", "v3"]
|
2353
|
-
}
|
2354
|
-
})
|
2355
|
-
},
|
2356
|
-
"Nested @container: @list" => {
|
2357
|
-
input: %([{
|
2358
|
-
"http://example.org/list": [{"@list": [
|
2359
|
-
{"@value": "a"},
|
2360
|
-
{"@value": "b"}
|
2361
|
-
]}]
|
2362
|
-
}]),
|
2363
|
-
context: %({
|
2364
|
-
"@vocab": "http://example.org/",
|
2365
|
-
"list": {"@container": "@list", "@nest": "nestedlist"},
|
2366
|
-
"nestedlist": "@nest"
|
2367
|
-
}),
|
2368
|
-
output: %({
|
2369
|
-
"@context": {
|
2370
|
-
"@vocab": "http://example.org/",
|
2371
|
-
"list": {"@container": "@list", "@nest": "nestedlist"},
|
2372
|
-
"nestedlist": "@nest"
|
2373
|
-
},
|
2374
|
-
"nestedlist": {
|
2375
|
-
"list": ["a", "b"]
|
2376
|
-
}
|
2377
|
-
}),
|
2378
|
-
},
|
2379
|
-
"Nested @container: @index" => {
|
2380
|
-
input: %([{
|
2381
|
-
"http://example.org/index": [
|
2382
|
-
{"@value": "a", "@index": "A"},
|
2383
|
-
{"@value": "b", "@index": "B"}
|
2384
|
-
]
|
2385
|
-
}]),
|
2386
|
-
context: %({
|
2387
|
-
"@vocab": "http://example.org/",
|
2388
|
-
"index": {"@container": "@index", "@nest": "nestedindex"},
|
2389
|
-
"nestedindex": "@nest"
|
2390
|
-
}),
|
2391
|
-
output: %({
|
2392
|
-
"@context": {
|
2393
|
-
"@vocab": "http://example.org/",
|
2394
|
-
"index": {"@container": "@index", "@nest": "nestedindex"},
|
2395
|
-
"nestedindex": "@nest"
|
2396
|
-
},
|
2397
|
-
"nestedindex": {
|
2398
|
-
"index": {
|
2399
|
-
"A": "a",
|
2400
|
-
"B": "b"
|
2401
|
-
}
|
2402
|
-
}
|
2403
|
-
}),
|
2404
|
-
},
|
2405
|
-
"Nested @container: @language" => {
|
2406
|
-
input: %([{
|
2407
|
-
"http://example.org/container": [
|
2408
|
-
{"@value": "Die Königin", "@language": "de"},
|
2409
|
-
{"@value": "The Queen", "@language": "en"}
|
2410
|
-
]
|
2411
|
-
}]),
|
2412
|
-
context: %({
|
2413
|
-
"@vocab": "http://example.org/",
|
2414
|
-
"container": {"@container": "@language", "@nest": "nestedlanguage"},
|
2415
|
-
"nestedlanguage": "@nest"
|
2416
|
-
}),
|
2417
|
-
output: %({
|
2418
|
-
"@context": {
|
2419
|
-
"@vocab": "http://example.org/",
|
2420
|
-
"container": {"@container": "@language", "@nest": "nestedlanguage"},
|
2421
|
-
"nestedlanguage": "@nest"
|
2422
|
-
},
|
2423
|
-
"nestedlanguage": {
|
2424
|
-
"container": {
|
2425
|
-
"en": "The Queen",
|
2426
|
-
"de": "Die Königin"
|
2427
|
-
}
|
2428
|
-
}
|
2429
|
-
})
|
2430
|
-
},
|
2431
|
-
"Nested @container: @type" => {
|
2432
|
-
input: %([{
|
2433
|
-
"http://example/typemap": [
|
2434
|
-
{"http://example/label": [{"@value": "Object with @type _:bar"}], "@type": ["_:bar"]},
|
2435
|
-
{"http://example/label": [{"@value": "Object with @type <foo>"}], "@type": ["http://example.org/foo"]}
|
2436
|
-
]
|
2437
|
-
}]),
|
2438
|
-
context: %({
|
2439
|
-
"@vocab": "http://example/",
|
2440
|
-
"typemap": {"@container": "@type", "@nest": "nestedtypemap"},
|
2441
|
-
"nestedtypemap": "@nest"
|
2442
|
-
}),
|
2443
|
-
output: %({
|
2444
|
-
"@context": {
|
2445
|
-
"@vocab": "http://example/",
|
2446
|
-
"typemap": {"@container": "@type", "@nest": "nestedtypemap"},
|
2447
|
-
"nestedtypemap": "@nest"
|
2448
|
-
},
|
2449
|
-
"nestedtypemap": {
|
2450
|
-
"typemap": {
|
2451
|
-
"_:bar": {"label": "Object with @type _:bar"},
|
2452
|
-
"http://example.org/foo": {"label": "Object with @type <foo>"}
|
2453
|
-
}
|
2454
|
-
}
|
2455
|
-
})
|
2456
|
-
},
|
2457
|
-
"Nested @container: @id" => {
|
2458
|
-
input: %([{
|
2459
|
-
"http://example/idmap": [
|
2460
|
-
{"http://example/label": [{"@value": "Object with @id _:bar"}], "@id": "_:bar"},
|
2461
|
-
{"http://example/label": [{"@value": "Object with @id <foo>"}], "@id": "http://example.org/foo"}
|
2462
|
-
]
|
2463
|
-
}]),
|
2464
|
-
context: %({
|
2465
|
-
"@vocab": "http://example/",
|
2466
|
-
"idmap": {"@container": "@id", "@nest": "nestedidmap"},
|
2467
|
-
"nestedidmap": "@nest"
|
2468
|
-
}),
|
2469
|
-
output: %({
|
2470
|
-
"@context": {
|
2471
|
-
"@vocab": "http://example/",
|
2472
|
-
"idmap": {"@container": "@id", "@nest": "nestedidmap"},
|
2473
|
-
"nestedidmap": "@nest"
|
2474
|
-
},
|
2475
|
-
"nestedidmap": {
|
2476
|
-
"idmap": {
|
2477
|
-
"http://example.org/foo": {"label": "Object with @id <foo>"},
|
2478
|
-
"_:bar": {"label": "Object with @id _:bar"}
|
2479
|
-
}
|
2480
|
-
}
|
2481
|
-
})
|
2482
|
-
},
|
2483
|
-
"Multiple nest aliases" => {
|
2484
|
-
input: %({
|
2485
|
-
"http://example.org/foo": "bar",
|
2486
|
-
"http://example.org/bar": "foo"
|
2487
|
-
}),
|
2488
|
-
context: %({
|
2489
|
-
"@vocab": "http://example.org/",
|
2490
|
-
"foonest": "@nest",
|
2491
|
-
"barnest": "@nest",
|
2492
|
-
"foo": {"@nest": "foonest"},
|
2493
|
-
"bar": {"@nest": "barnest"}
|
2494
|
-
}),
|
2495
|
-
output: %({
|
2496
|
-
"@context": {
|
2497
|
-
"@vocab": "http://example.org/",
|
2498
|
-
"foonest": "@nest",
|
2499
|
-
"barnest": "@nest",
|
2500
|
-
"foo": {"@nest": "foonest"},
|
2501
|
-
"bar": {"@nest": "barnest"}
|
2502
|
-
},
|
2503
|
-
"barnest": {"bar": "foo"},
|
2504
|
-
"foonest": {"foo": "bar"}
|
2505
|
-
})
|
2506
|
-
},
|
2507
|
-
"Nest term not defined" => {
|
2508
|
-
input: %({
|
2509
|
-
"http://example/foo": "bar"
|
2510
|
-
}),
|
2511
|
-
context: %({
|
2512
|
-
"term": {"@id": "http://example/foo", "@nest": "unknown"}
|
2513
|
-
}),
|
2514
|
-
exception: JSON::LD::JsonLdError::InvalidNestValue
|
2515
|
-
},
|
2516
|
-
}.each_pair do |title, params|
|
2517
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
2518
|
-
end
|
2519
|
-
end
|
2520
|
-
|
2521
|
-
context "@graph" do
|
2522
|
-
{
|
2523
|
-
"Uses @graph given mutliple inputs" => {
|
2524
|
-
input: %([
|
2525
|
-
{"http://example.com/foo": ["foo"]},
|
2526
|
-
{"http://example.com/bar": ["bar"]}
|
2527
|
-
]),
|
2528
|
-
context: %({"ex": "http://example.com/"}),
|
2529
|
-
output: %({
|
2530
|
-
"@context": {"ex": "http://example.com/"},
|
2531
|
-
"@graph": [
|
2532
|
-
{"ex:foo": "foo"},
|
2533
|
-
{"ex:bar": "bar"}
|
2534
|
-
]
|
2535
|
-
})
|
2536
|
-
},
|
2537
|
-
}.each_pair do |title, params|
|
2538
|
-
it(title) {run_compact(params)}
|
2539
|
-
end
|
2540
|
-
end
|
2541
|
-
|
2542
|
-
context "scoped context" do
|
2543
|
-
{
|
2544
|
-
"adding new term" => {
|
2545
|
-
input: %([{
|
2546
|
-
"http://example/foo": [{"http://example.org/bar": [{"@value": "baz"}]}]
|
2547
|
-
}]),
|
2548
|
-
context: %({
|
2549
|
-
"@vocab": "http://example/",
|
2550
|
-
"foo": {"@context": {"bar": "http://example.org/bar"}}
|
2551
|
-
}),
|
2552
|
-
output: %({
|
2553
|
-
"@context": {
|
2554
|
-
"@vocab": "http://example/",
|
2555
|
-
"foo": {"@context": {"bar": "http://example.org/bar"}}
|
2556
|
-
},
|
2557
|
-
"foo": {
|
2558
|
-
"bar": "baz"
|
2559
|
-
}
|
2560
|
-
})
|
2561
|
-
},
|
2562
|
-
"overriding a term" => {
|
2563
|
-
input: %([
|
2564
|
-
{
|
2565
|
-
"http://example/foo": [{"http://example/bar": [{"@id": "http://example/baz"}]}]
|
2566
|
-
}
|
2567
|
-
]),
|
2568
|
-
context: %({
|
2569
|
-
"@vocab": "http://example/",
|
2570
|
-
"foo": {"@context": {"bar": {"@type": "@id"}}},
|
2571
|
-
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
|
2572
|
-
}),
|
2573
|
-
output: %({
|
2574
|
-
"@context": {
|
2575
|
-
"@vocab": "http://example/",
|
2576
|
-
"foo": {"@context": {"bar": {"@type": "@id"}}},
|
2577
|
-
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
|
2578
|
-
},
|
2579
|
-
"foo": {
|
2580
|
-
"bar": "http://example/baz"
|
2581
|
-
}
|
2582
|
-
}),
|
2583
|
-
},
|
2584
|
-
"property and value with different terms mapping to the same expanded property" => {
|
2585
|
-
input: %([
|
2586
|
-
{
|
2587
|
-
"http://example/foo": [{
|
2588
|
-
"http://example/bar": [
|
2589
|
-
{"@value": "baz"}
|
2590
|
-
]}
|
2591
|
-
]
|
2592
|
-
}
|
2593
|
-
]),
|
2594
|
-
context: %({
|
2595
|
-
"@vocab": "http://example/",
|
2596
|
-
"foo": {"@context": {"Bar": {"@id": "bar"}}}
|
2597
|
-
}),
|
2598
|
-
output: %({
|
2599
|
-
"@context": {
|
2600
|
-
"@vocab": "http://example/",
|
2601
|
-
"foo": {"@context": {"Bar": {"@id": "bar"}}}
|
2602
|
-
},
|
2603
|
-
"foo": {
|
2604
|
-
"Bar": "baz"
|
2605
|
-
}
|
2606
|
-
}),
|
2607
|
-
},
|
2608
|
-
"deep @context affects nested nodes" => {
|
2609
|
-
input: %([
|
2610
|
-
{
|
2611
|
-
"http://example/foo": [{
|
2612
|
-
"http://example/bar": [{
|
2613
|
-
"http://example/baz": [{"@id": "http://example/buzz"}]
|
2614
|
-
}]
|
2615
|
-
}]
|
2616
|
-
}
|
2617
|
-
]),
|
2618
|
-
context: %({
|
2619
|
-
"@vocab": "http://example/",
|
2620
|
-
"foo": {"@context": {"baz": {"@type": "@vocab"}}}
|
2621
|
-
}),
|
2622
|
-
output: %({
|
2623
|
-
"@context": {
|
2624
|
-
"@vocab": "http://example/",
|
2625
|
-
"foo": {"@context": {"baz": {"@type": "@vocab"}}}
|
2626
|
-
},
|
2627
|
-
"foo": {
|
2628
|
-
"bar": {
|
2629
|
-
"baz": "buzz"
|
2630
|
-
}
|
2631
|
-
}
|
2632
|
-
}),
|
2633
|
-
},
|
2634
|
-
"scoped context layers on intemediate contexts" => {
|
2635
|
-
input: %([{
|
2636
|
-
"http://example/a": [{
|
2637
|
-
"http://example.com/c": [{"@value": "C in example.com"}],
|
2638
|
-
"http://example/b": [{
|
2639
|
-
"http://example.com/a": [{"@value": "A in example.com"}],
|
2640
|
-
"http://example.org/c": [{"@value": "C in example.org"}]
|
2641
|
-
}]
|
2642
|
-
}],
|
2643
|
-
"http://example/c": [{"@value": "C in example"}]
|
2644
|
-
}]),
|
2645
|
-
context: %({
|
2646
|
-
"@vocab": "http://example/",
|
2647
|
-
"b": {"@context": {"c": "http://example.org/c"}}
|
2648
|
-
}),
|
2649
|
-
output: %({
|
2650
|
-
"@context": {
|
2651
|
-
"@vocab": "http://example/",
|
2652
|
-
"b": {"@context": {"c": "http://example.org/c"}}
|
2653
|
-
},
|
2654
|
-
"a": {
|
2655
|
-
"b": {
|
2656
|
-
"c": "C in example.org",
|
2657
|
-
"http://example.com/a": "A in example.com"
|
2658
|
-
},
|
2659
|
-
"http://example.com/c": "C in example.com"
|
2660
|
-
},
|
2661
|
-
"c": "C in example"
|
2662
|
-
}),
|
2663
|
-
},
|
2664
|
-
"Raises InvalidTermDefinition if processingMode is 1.0" => {
|
2665
|
-
input: %([{
|
2666
|
-
"http://example/foo": [{"http://example.org/bar": [{"@value": "baz"}]}]
|
2667
|
-
}]),
|
2668
|
-
context: %({
|
2669
|
-
"@vocab": "http://example/",
|
2670
|
-
"foo": {"@context": {"bar": "http://example.org/bar"}}
|
2671
|
-
}),
|
2672
|
-
processingMode: 'json-ld-1.0',
|
2673
|
-
validate: true,
|
2674
|
-
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
2675
|
-
},
|
2676
|
-
"Scoped on id map": {
|
2677
|
-
output: %({
|
2678
|
-
"@context": {
|
2679
|
-
"@version": 1.1,
|
2680
|
-
"schema": "http://schema.org/",
|
2681
|
-
"name": "schema:name",
|
2682
|
-
"body": "schema:articleBody",
|
2683
|
-
"words": "schema:wordCount",
|
2684
|
-
"post": {
|
2685
|
-
"@id": "schema:blogPost",
|
2686
|
-
"@container": "@id",
|
2687
|
-
"@context": {
|
2688
|
-
"@base": "http://example.com/posts/"
|
2689
|
-
}
|
2690
|
-
}
|
2691
|
-
},
|
2692
|
-
"@id": "http://example.com/",
|
2693
|
-
"@type": "schema:Blog",
|
2694
|
-
"name": "World Financial News",
|
2695
|
-
"post": {
|
2696
|
-
"1/en": {
|
2697
|
-
"body": "World commodities were up today with heavy trading of crude oil...",
|
2698
|
-
"words": 1539
|
2699
|
-
},
|
2700
|
-
"1/de": {
|
2701
|
-
"body": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl...",
|
2702
|
-
"words": 1204
|
2703
|
-
}
|
2704
|
-
}
|
2705
|
-
}),
|
2706
|
-
input: %([{
|
2707
|
-
"@id": "http://example.com/",
|
2708
|
-
"@type": ["http://schema.org/Blog"],
|
2709
|
-
"http://schema.org/name": [{"@value": "World Financial News"}],
|
2710
|
-
"http://schema.org/blogPost": [{
|
2711
|
-
"@id": "http://example.com/posts/1/en",
|
2712
|
-
"http://schema.org/articleBody": [
|
2713
|
-
{"@value": "World commodities were up today with heavy trading of crude oil..."}
|
2714
|
-
],
|
2715
|
-
"http://schema.org/wordCount": [{"@value": 1539}]
|
2716
|
-
}, {
|
2717
|
-
"@id": "http://example.com/posts/1/de",
|
2718
|
-
"http://schema.org/articleBody": [
|
2719
|
-
{"@value": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl..."}
|
2720
|
-
],
|
2721
|
-
"http://schema.org/wordCount": [{"@value": 1204}]
|
2722
|
-
}]
|
2723
|
-
}])
|
2724
|
-
},
|
2725
|
-
}.each_pair do |title, params|
|
2726
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
2727
|
-
end
|
2728
|
-
end
|
2729
|
-
|
2730
|
-
context "scoped context on @type" do
|
2731
|
-
{
|
2732
|
-
"adding new term" => {
|
2733
|
-
input: %([
|
2734
|
-
{
|
2735
|
-
"http://example/a": [{
|
2736
|
-
"@type": ["http://example/Foo"],
|
2737
|
-
"http://example.org/bar": [{"@value": "baz"}]
|
2738
|
-
}]
|
2739
|
-
}
|
2740
|
-
]),
|
2741
|
-
context: %({
|
2742
|
-
"@vocab": "http://example/",
|
2743
|
-
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
2744
|
-
}),
|
2745
|
-
output: %({
|
2746
|
-
"@context": {
|
2747
|
-
"@vocab": "http://example/",
|
2748
|
-
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
2749
|
-
},
|
2750
|
-
"a": {"@type": "Foo", "bar": "baz"}
|
2751
|
-
})
|
2752
|
-
},
|
2753
|
-
"overriding a term" => {
|
2754
|
-
input: %([
|
2755
|
-
{
|
2756
|
-
"http://example/a": [{
|
2757
|
-
"@type": ["http://example/Foo"],
|
2758
|
-
"http://example/bar": [{"@id": "http://example/baz"}]
|
2759
|
-
}]
|
2760
|
-
}
|
2761
|
-
]),
|
2762
|
-
context: %({
|
2763
|
-
"@vocab": "http://example/",
|
2764
|
-
"Foo": {"@context": {"bar": {"@type": "@id"}}},
|
2765
|
-
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
|
2766
|
-
}),
|
2767
|
-
output: %({
|
2768
|
-
"@context": {
|
2769
|
-
"@vocab": "http://example/",
|
2770
|
-
"Foo": {"@context": {"bar": {"@type": "@id"}}},
|
2771
|
-
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
|
2772
|
-
},
|
2773
|
-
"a": {"@type": "Foo", "bar": "http://example/baz"}
|
2774
|
-
}),
|
2775
|
-
},
|
2776
|
-
"alias of @type" => {
|
2777
|
-
input: %([
|
2778
|
-
{
|
2779
|
-
"http://example/a": [{
|
2780
|
-
"@type": ["http://example/Foo"],
|
2781
|
-
"http://example.org/bar": [{"@value": "baz"}]
|
2782
|
-
}]
|
2783
|
-
}
|
2784
|
-
]),
|
2785
|
-
context: %({
|
2786
|
-
"@vocab": "http://example/",
|
2787
|
-
"type": "@type",
|
2788
|
-
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
2789
|
-
}),
|
2790
|
-
output: %({
|
2791
|
-
"@context": {
|
2792
|
-
"@vocab": "http://example/",
|
2793
|
-
"type": "@type",
|
2794
|
-
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
2795
|
-
},
|
2796
|
-
"a": {"type": "Foo", "bar": "baz"}
|
2797
|
-
}),
|
2798
|
-
},
|
2799
|
-
"deep @context does not affect nested nodes" => {
|
2800
|
-
input: %([
|
2801
|
-
{
|
2802
|
-
"@type": ["http://example/Foo"],
|
2803
|
-
"http://example/bar": [{
|
2804
|
-
"http://example/baz": [{"@id": "http://example/buzz"}]
|
2805
|
-
}]
|
2806
|
-
}
|
2807
|
-
]),
|
2808
|
-
context: %({
|
2809
|
-
"@vocab": "http://example/",
|
2810
|
-
"Foo": {"@context": {"baz": {"@type": "@vocab"}}}
|
2811
|
-
}),
|
2812
|
-
output: %({
|
2813
|
-
"@context": {
|
2814
|
-
"@vocab": "http://example/",
|
2815
|
-
"Foo": {"@context": {"baz": {"@type": "@vocab"}}}
|
2816
|
-
},
|
2817
|
-
"@type": "Foo",
|
2818
|
-
"bar": {"baz": {"@id": "http://example/buzz"}}
|
2819
|
-
}),
|
2820
|
-
},
|
2821
|
-
"scoped context layers on intemediate contexts" => {
|
2822
|
-
input: %([{
|
2823
|
-
"http://example/a": [{
|
2824
|
-
"@type": ["http://example/B"],
|
2825
|
-
"http://example.com/a": [{"@value": "A in example.com"}],
|
2826
|
-
"http://example.org/c": [{"@value": "C in example.org"}]
|
2827
|
-
}],
|
2828
|
-
"http://example/c": [{"@value": "C in example"}]
|
2829
|
-
}]),
|
2830
|
-
context: %({
|
2831
|
-
"@vocab": "http://example/",
|
2832
|
-
"B": {"@context": {"c": "http://example.org/c"}}
|
2833
|
-
}),
|
2834
|
-
output: %({
|
2835
|
-
"@context": {
|
2836
|
-
"@vocab": "http://example/",
|
2837
|
-
"B": {"@context": {"c": "http://example.org/c"}}
|
2838
|
-
},
|
2839
|
-
"a": {
|
2840
|
-
"@type": "B",
|
2841
|
-
"c": "C in example.org",
|
2842
|
-
"http://example.com/a": "A in example.com"
|
2843
|
-
},
|
2844
|
-
"c": "C in example"
|
2845
|
-
}),
|
2846
|
-
},
|
2847
|
-
"orders lexicographically" => {
|
2848
|
-
input: %([{
|
2849
|
-
"@type": ["http://example/t2", "http://example/t1"],
|
2850
|
-
"http://example.org/foo": [
|
2851
|
-
{"@id": "urn:bar"}
|
2852
|
-
]
|
2853
|
-
}]),
|
2854
|
-
context: %({
|
2855
|
-
"@vocab": "http://example/",
|
2856
|
-
"t1": {"@context": {"foo": {"@id": "http://example.com/foo"}}},
|
2857
|
-
"t2": {"@context": {"foo": {"@id": "http://example.org/foo", "@type": "@id"}}}
|
2858
|
-
}),
|
2859
|
-
output: %({
|
2860
|
-
"@context": {
|
2861
|
-
"@vocab": "http://example/",
|
2862
|
-
"t1": {"@context": {"foo": {"@id": "http://example.com/foo"}}},
|
2863
|
-
"t2": {"@context": {"foo": {"@id": "http://example.org/foo", "@type": "@id"}}}
|
2864
|
-
},
|
2865
|
-
"@type": ["t2", "t1"],
|
2866
|
-
"foo": "urn:bar"
|
2867
|
-
}),
|
2868
|
-
},
|
2869
|
-
"with @container: @type" => {
|
2870
|
-
input: %([{
|
2871
|
-
"http://example/typemap": [
|
2872
|
-
{"http://example.org/a": [{"@value": "Object with @type <Type>"}], "@type": ["http://example/Type"]}
|
2873
|
-
]
|
2874
|
-
}]),
|
2875
|
-
context: %({
|
2876
|
-
"@vocab": "http://example/",
|
2877
|
-
"typemap": {"@container": "@type"},
|
2878
|
-
"Type": {"@context": {"a": "http://example.org/a"}}
|
2879
|
-
}),
|
2880
|
-
output: %({
|
2881
|
-
"@context": {
|
2882
|
-
"@vocab": "http://example/",
|
2883
|
-
"typemap": {"@container": "@type"},
|
2884
|
-
"Type": {"@context": {"a": "http://example.org/a"}}
|
2885
|
-
},
|
2886
|
-
"typemap": {
|
2887
|
-
"Type": {"a": "Object with @type <Type>"}
|
2888
|
-
}
|
2889
|
-
})
|
2890
|
-
},
|
2891
|
-
"Raises InvalidTermDefinition if processingMode is 1.0" => {
|
2892
|
-
input: %([
|
2893
|
-
{
|
2894
|
-
"http://example/a": [{
|
2895
|
-
"@type": ["http://example/Foo"],
|
2896
|
-
"http://example.org/bar": [{"@value": "baz"}]
|
2897
|
-
}]
|
2898
|
-
}
|
2899
|
-
]),
|
2900
|
-
context: %({
|
2901
|
-
"@vocab": "http://example/",
|
2902
|
-
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
2903
|
-
}),
|
2904
|
-
processingMode: 'json-ld-1.0',
|
2905
|
-
validate: true,
|
2906
|
-
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
2907
|
-
},
|
2908
|
-
"applies context for all values" => {
|
2909
|
-
input: %([
|
2910
|
-
{
|
2911
|
-
"@id": "http://example.org/id",
|
2912
|
-
"@type": ["http://example/type"],
|
2913
|
-
"http://example/a": [{
|
2914
|
-
"@id": "http://example.org/Foo",
|
2915
|
-
"@type": ["http://example/Foo"],
|
2916
|
-
"http://example/bar": [{"@id": "http://example.org/baz"}]
|
2917
|
-
}]
|
2918
|
-
}
|
2919
|
-
]),
|
2920
|
-
context: %({
|
2921
|
-
"@vocab": "http://example/",
|
2922
|
-
"id": "@id",
|
2923
|
-
"type": "@type",
|
2924
|
-
"Foo": {"@context": {"id": null, "type": null}}
|
2925
|
-
}),
|
2926
|
-
output: %({
|
2927
|
-
"@context": {
|
2928
|
-
"@vocab": "http://example/",
|
2929
|
-
"id": "@id",
|
2930
|
-
"type": "@type",
|
2931
|
-
"Foo": {"@context": {"id": null, "type": null}}
|
2932
|
-
},
|
2933
|
-
"id": "http://example.org/id",
|
2934
|
-
"type": "http://example/type",
|
2935
|
-
"a": {
|
2936
|
-
"@id": "http://example.org/Foo",
|
2937
|
-
"@type": "Foo",
|
2938
|
-
"bar": {"@id": "http://example.org/baz"}
|
2939
|
-
}
|
2940
|
-
}),
|
2941
|
-
},
|
2942
|
-
}.each_pair do |title, params|
|
2943
|
-
it(title) {run_compact({processingMode: "json-ld-1.1"}.merge(params))}
|
2944
|
-
end
|
2945
|
-
end
|
2946
|
-
|
2947
|
-
context "compact IRI selection" do
|
2948
|
-
{
|
2949
|
-
"does not compact using expanded term in 1.0" => {
|
2950
|
-
input: %({"http://example.org/foo": "term"}),
|
2951
|
-
context: %({"ex": {"@id": "http://example.org/"}}),
|
2952
|
-
output: %({
|
2953
|
-
"@context": {"ex": {"@id": "http://example.org/"}},
|
2954
|
-
"http://example.org/foo": "term"
|
2955
|
-
}),
|
2956
|
-
processingMode: "json-ld-1.0"
|
2957
|
-
},
|
2958
|
-
"does not compact using expanded term in 1.1" => {
|
2959
|
-
input: %({"http://example.org/foo": "term"}),
|
2960
|
-
context: %({"ex": {"@id": "http://example.org/"}}),
|
2961
|
-
output: %({
|
2962
|
-
"@context": {"ex": {"@id": "http://example.org/"}},
|
2963
|
-
"http://example.org/foo": "term"
|
2964
|
-
}),
|
2965
|
-
processingMode: "json-ld-1.1"
|
2966
|
-
},
|
2967
|
-
"does not compact using simple term not ending in gen-delim" => {
|
2968
|
-
input: %({"http://example.org/foo": "term"}),
|
2969
|
-
context: %({"ex": "http://example.org/f"}),
|
2970
|
-
output: %({
|
2971
|
-
"@context": {"ex": "http://example.org/f"},
|
2972
|
-
"http://example.org/foo": "term"
|
2973
|
-
})
|
2974
|
-
},
|
2975
|
-
"compacts using simple term ending in gen-delim ('/')" => {
|
2976
|
-
input: %({"http://example.org/foo": "term"}),
|
2977
|
-
context: %({"ex": "http://example.org/"}),
|
2978
|
-
output: %({
|
2979
|
-
"@context": {"ex": "http://example.org/"},
|
2980
|
-
"ex:foo": "term"
|
2981
|
-
})
|
2982
|
-
},
|
2983
|
-
"compacts using simple term ending in gen-delim (':')" => {
|
2984
|
-
input: %({"http://example.org/foo:bar": "term"}),
|
2985
|
-
context: %({"ex": "http://example.org/foo:"}),
|
2986
|
-
output: %({
|
2987
|
-
"@context": {"ex": "http://example.org/foo:"},
|
2988
|
-
"ex:bar": "term"
|
2989
|
-
})
|
2990
|
-
},
|
2991
|
-
"compacts using simple term ending in gen-delim ('?')" => {
|
2992
|
-
input: %({"http://example.org/foo?bar": "term"}),
|
2993
|
-
context: %({"ex": "http://example.org/foo?"}),
|
2994
|
-
output: %({
|
2995
|
-
"@context": {"ex": "http://example.org/foo?"},
|
2996
|
-
"ex:bar": "term"
|
2997
|
-
})
|
2998
|
-
},
|
2999
|
-
"compacts using simple term ending in gen-delim ('#')" => {
|
3000
|
-
input: %({"http://example.org/foo#bar": "term"}),
|
3001
|
-
context: %({"ex": "http://example.org/foo#"}),
|
3002
|
-
output: %({
|
3003
|
-
"@context": {"ex": "http://example.org/foo#"},
|
3004
|
-
"ex:bar": "term"
|
3005
|
-
})
|
3006
|
-
},
|
3007
|
-
"compacts using simple term ending in gen-delim ('[')" => {
|
3008
|
-
input: %({"http://example.org/foo[bar": "term"}),
|
3009
|
-
context: %({"ex": "http://example.org/foo["}),
|
3010
|
-
output: %({
|
3011
|
-
"@context": {"ex": "http://example.org/foo["},
|
3012
|
-
"ex:bar": "term"
|
3013
|
-
})
|
3014
|
-
},
|
3015
|
-
"compacts using simple term ending in gen-delim (']')" => {
|
3016
|
-
input: %({"http://example.org/foo]bar": "term"}),
|
3017
|
-
context: %({"ex": "http://example.org/foo]"}),
|
3018
|
-
output: %({
|
3019
|
-
"@context": {"ex": "http://example.org/foo]"},
|
3020
|
-
"ex:bar": "term"
|
3021
|
-
})
|
3022
|
-
},
|
3023
|
-
"compacts using simple term ending in gen-delim ('@')" => {
|
3024
|
-
input: %({"http://example.org/foo@bar": "term"}),
|
3025
|
-
context: %({"ex": "http://example.org/foo@"}),
|
3026
|
-
output: %({
|
3027
|
-
"@context": {"ex": "http://example.org/foo@"},
|
3028
|
-
"ex:bar": "term"
|
3029
|
-
})
|
3030
|
-
},
|
3031
|
-
"compacts using base if @vocab: relative" => {
|
3032
|
-
input: %({"http://example.org/foo/bar": "term"}),
|
3033
|
-
context: %({"@base": "http://example.org/foo/", "@vocab": ""}),
|
3034
|
-
output: %({
|
3035
|
-
"@context": {"@base": "http://example.org/foo/", "@vocab": ""},
|
3036
|
-
"bar": "term"
|
3037
|
-
})
|
3038
|
-
},
|
3039
|
-
}.each do |title, params|
|
3040
|
-
it(title) {run_compact(params)}
|
3041
|
-
end
|
3042
|
-
end
|
3043
|
-
end
|
3044
|
-
|
3045
|
-
context "html" do
|
3046
|
-
{
|
3047
|
-
"Compacts embedded JSON-LD script element": {
|
3048
|
-
input: %(
|
3049
|
-
<html>
|
3050
|
-
<head>
|
3051
|
-
<script type="application/ld+json">
|
3052
|
-
{
|
3053
|
-
"@context": {
|
3054
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3055
|
-
},
|
3056
|
-
"foo": [{"@value": "bar"}]
|
3057
|
-
}
|
3058
|
-
</script>
|
3059
|
-
</head>
|
3060
|
-
</html>),
|
3061
|
-
context: %({"foo": {"@id": "http://example.com/foo", "@container": "@list"}}),
|
3062
|
-
output: %({
|
3063
|
-
"@context": {
|
3064
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3065
|
-
},
|
3066
|
-
"foo": ["bar"]
|
3067
|
-
})
|
3068
|
-
},
|
3069
|
-
"Compacts first script element": {
|
3070
|
-
input: %(
|
3071
|
-
<html>
|
3072
|
-
<head>
|
3073
|
-
<script type="application/ld+json">
|
3074
|
-
{
|
3075
|
-
"@context": {
|
3076
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3077
|
-
},
|
3078
|
-
"foo": [{"@value": "bar"}]
|
3079
|
-
}
|
3080
|
-
</script>
|
3081
|
-
<script type="application/ld+json">
|
3082
|
-
{
|
3083
|
-
"@context": {"ex": "http://example.com/"},
|
3084
|
-
"@graph": [
|
3085
|
-
{"ex:foo": {"@value": "foo"}},
|
3086
|
-
{"ex:bar": {"@value": "bar"}}
|
3087
|
-
]
|
3088
|
-
}
|
3089
|
-
</script>
|
3090
|
-
</head>
|
3091
|
-
</html>),
|
3092
|
-
context: %({"foo": {"@id": "http://example.com/foo", "@container": "@list"}}),
|
3093
|
-
output: %({
|
3094
|
-
"@context": {
|
3095
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3096
|
-
},
|
3097
|
-
"foo": ["bar"]
|
3098
|
-
})
|
3099
|
-
},
|
3100
|
-
"Compacts targeted script element": {
|
3101
|
-
input: %(
|
3102
|
-
<html>
|
3103
|
-
<head>
|
3104
|
-
<script id="first" type="application/ld+json">
|
3105
|
-
{
|
3106
|
-
"@context": {
|
3107
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3108
|
-
},
|
3109
|
-
"foo": [{"@value": "bar"}]
|
3110
|
-
}
|
3111
|
-
</script>
|
3112
|
-
<script id="second" type="application/ld+json">
|
3113
|
-
{
|
3114
|
-
"@context": {"ex": "http://example.com/"},
|
3115
|
-
"@graph": [
|
3116
|
-
{"ex:foo": {"@value": "foo"}},
|
3117
|
-
{"ex:bar": {"@value": "bar"}}
|
3118
|
-
]
|
3119
|
-
}
|
3120
|
-
</script>
|
3121
|
-
</head>
|
3122
|
-
</html>),
|
3123
|
-
context: %({"ex": "http://example.com/"}),
|
3124
|
-
output: %({
|
3125
|
-
"@context": {"ex": "http://example.com/"},
|
3126
|
-
"@graph": [
|
3127
|
-
{"ex:foo": "foo"},
|
3128
|
-
{"ex:bar": "bar"}
|
3129
|
-
]
|
3130
|
-
}),
|
3131
|
-
base: "http://example.org/doc#second"
|
3132
|
-
},
|
3133
|
-
"Compacts all script elements with extractAllScripts option": {
|
3134
|
-
input: %(
|
3135
|
-
<html>
|
3136
|
-
<head>
|
3137
|
-
<script type="application/ld+json">
|
3138
|
-
{
|
3139
|
-
"@context": {
|
3140
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3141
|
-
},
|
3142
|
-
"foo": [{"@value": "bar"}]
|
3143
|
-
}
|
3144
|
-
</script>
|
3145
|
-
<script type="application/ld+json">
|
3146
|
-
{
|
3147
|
-
"@context": {"ex": "http://example.com/"},
|
3148
|
-
"@graph": [
|
3149
|
-
{"ex:foo": {"@value": "foo"}},
|
3150
|
-
{"ex:bar": {"@value": "bar"}}
|
3151
|
-
]
|
3152
|
-
}
|
3153
|
-
</script>
|
3154
|
-
</head>
|
3155
|
-
</html>),
|
3156
|
-
context: %({
|
3157
|
-
"ex": "http://example.com/",
|
3158
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3159
|
-
}),
|
3160
|
-
output: %({
|
3161
|
-
"@context": {
|
3162
|
-
"ex": "http://example.com/",
|
3163
|
-
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
|
3164
|
-
},
|
3165
|
-
"@graph": [
|
3166
|
-
{"foo": ["bar"]},
|
3167
|
-
{
|
3168
|
-
"@graph": [
|
3169
|
-
{"ex:foo": "foo"},
|
3170
|
-
{"ex:bar": "bar"}
|
3171
|
-
]
|
3172
|
-
}
|
3173
|
-
]
|
3174
|
-
}),
|
3175
|
-
extractAllScripts: true
|
3176
|
-
},
|
3177
|
-
}.each do |title, params|
|
3178
|
-
it(title) do
|
3179
|
-
params[:input] = StringIO.new(params[:input])
|
3180
|
-
params[:input].send(:define_singleton_method, :content_type) {"text/html"}
|
3181
|
-
run_compact params.merge(validate: true)
|
3182
|
-
end
|
3183
|
-
end
|
3184
|
-
end
|
3185
|
-
|
3186
|
-
context "JSON-LD-star" do
|
3187
|
-
{
|
3188
|
-
"subject-iii": {
|
3189
|
-
input: %([{
|
3190
|
-
"@id": {
|
3191
|
-
"@id": "http://example/s1",
|
3192
|
-
"http://example/p1": [{"@id": "http://example/o1"}]
|
3193
|
-
},
|
3194
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3195
|
-
}]),
|
3196
|
-
context: %({"ex": "http://example/"}),
|
3197
|
-
output: %({
|
3198
|
-
"@context": {"ex": "http://example/"},
|
3199
|
-
"@id": {
|
3200
|
-
"@id": "ex:s1",
|
3201
|
-
"ex:p1": {"@id": "ex:o1"}
|
3202
|
-
},
|
3203
|
-
"ex:p": {"@id": "ex:o"}
|
3204
|
-
})
|
3205
|
-
},
|
3206
|
-
"subject-iib": {
|
3207
|
-
input: %([{
|
3208
|
-
"@id": {
|
3209
|
-
"@id": "http://example/s1",
|
3210
|
-
"http://example/p1": [{"@id": "_:o1"}]
|
3211
|
-
},
|
3212
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3213
|
-
}]),
|
3214
|
-
context: %({"ex": "http://example/"}),
|
3215
|
-
output: %({
|
3216
|
-
"@context": {"ex": "http://example/"},
|
3217
|
-
"@id": {
|
3218
|
-
"@id": "ex:s1",
|
3219
|
-
"ex:p1": {"@id": "_:o1"}
|
3220
|
-
},
|
3221
|
-
"ex:p": {"@id": "ex:o"}
|
3222
|
-
})
|
3223
|
-
},
|
3224
|
-
"subject-iil": {
|
3225
|
-
input: %([{
|
3226
|
-
"@id": {
|
3227
|
-
"@id": "http://example/s1",
|
3228
|
-
"http://example/p1": [{"@value": "o1"}]
|
3229
|
-
},
|
3230
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3231
|
-
}]),
|
3232
|
-
context: %({"ex": "http://example/"}),
|
3233
|
-
output: %({
|
3234
|
-
"@context": {"ex": "http://example/"},
|
3235
|
-
"@id": {
|
3236
|
-
"@id": "ex:s1",
|
3237
|
-
"ex:p1": "o1"
|
3238
|
-
},
|
3239
|
-
"ex:p": {"@id": "ex:o"}
|
3240
|
-
})
|
3241
|
-
},
|
3242
|
-
"subject-bii": {
|
3243
|
-
input: %([{
|
3244
|
-
"@id": {
|
3245
|
-
"@id": "_:s1",
|
3246
|
-
"http://example/p1": [{"@id": "http://example/o1"}]
|
3247
|
-
},
|
3248
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3249
|
-
}]),
|
3250
|
-
context: %({"ex": "http://example/"}),
|
3251
|
-
output: %({
|
3252
|
-
"@context": {"ex": "http://example/"},
|
3253
|
-
"@id": {
|
3254
|
-
"@id": "_:s1",
|
3255
|
-
"ex:p1": {"@id": "ex:o1"}
|
3256
|
-
},
|
3257
|
-
"ex:p": {"@id": "ex:o"}
|
3258
|
-
})
|
3259
|
-
},
|
3260
|
-
"subject-bib": {
|
3261
|
-
input: %([{
|
3262
|
-
"@id": {
|
3263
|
-
"@id": "_:s1",
|
3264
|
-
"http://example/p1": [{"@id": "_:o1"}]
|
3265
|
-
},
|
3266
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3267
|
-
}]),
|
3268
|
-
context: %({"ex": "http://example/"}),
|
3269
|
-
output: %({
|
3270
|
-
"@context": {"ex": "http://example/"},
|
3271
|
-
"@id": {
|
3272
|
-
"@id": "_:s1",
|
3273
|
-
"ex:p1": {"@id": "_:o1"}
|
3274
|
-
},
|
3275
|
-
"ex:p": {"@id": "ex:o"}
|
3276
|
-
})
|
3277
|
-
},
|
3278
|
-
"subject-bil": {
|
3279
|
-
input: %([{
|
3280
|
-
"@id": {
|
3281
|
-
"@id": "_:s1",
|
3282
|
-
"http://example/p1": [{"@value": "o1"}]
|
3283
|
-
},
|
3284
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3285
|
-
}]),
|
3286
|
-
context: %({"ex": "http://example/"}),
|
3287
|
-
output: %({
|
3288
|
-
"@context": {"ex": "http://example/"},
|
3289
|
-
"@id": {
|
3290
|
-
"@id": "_:s1",
|
3291
|
-
"ex:p1": "o1"
|
3292
|
-
},
|
3293
|
-
"ex:p": {"@id": "ex:o"}
|
3294
|
-
})
|
3295
|
-
},
|
3296
|
-
"object-iii": {
|
3297
|
-
input: %([{
|
3298
|
-
"@id": "http://example/s",
|
3299
|
-
"http://example/p": [{
|
3300
|
-
"@id": {
|
3301
|
-
"@id": "http://example/s1",
|
3302
|
-
"http://example/p1": [{"@id": "http://example/o1"}]
|
3303
|
-
}
|
3304
|
-
}]
|
3305
|
-
}]),
|
3306
|
-
context: %({"ex": "http://example/"}),
|
3307
|
-
output: %({
|
3308
|
-
"@context": {"ex": "http://example/"},
|
3309
|
-
"@id": "ex:s",
|
3310
|
-
"ex:p": {
|
3311
|
-
"@id": {
|
3312
|
-
"@id": "ex:s1",
|
3313
|
-
"ex:p1": {"@id": "ex:o1"}
|
3314
|
-
}
|
3315
|
-
}
|
3316
|
-
})
|
3317
|
-
},
|
3318
|
-
"object-iib": {
|
3319
|
-
input: %([{
|
3320
|
-
"@id": "http://example/s",
|
3321
|
-
"http://example/p": [{
|
3322
|
-
"@id": {
|
3323
|
-
"@id": "http://example/s1",
|
3324
|
-
"http://example/p1": [{"@id": "_:o1"}]
|
3325
|
-
}
|
3326
|
-
}]
|
3327
|
-
}]),
|
3328
|
-
context: %({"ex": "http://example/"}),
|
3329
|
-
output: %({
|
3330
|
-
"@context": {"ex": "http://example/"},
|
3331
|
-
"@id": "ex:s",
|
3332
|
-
"ex:p": {
|
3333
|
-
"@id": {
|
3334
|
-
"@id": "ex:s1",
|
3335
|
-
"ex:p1": {"@id": "_:o1"}
|
3336
|
-
}
|
3337
|
-
}
|
3338
|
-
})
|
3339
|
-
},
|
3340
|
-
"object-iil": {
|
3341
|
-
input: %([{
|
3342
|
-
"@id": "http://example/s",
|
3343
|
-
"http://example/p": [{
|
3344
|
-
"@id": {
|
3345
|
-
"@id": "http://example/s1",
|
3346
|
-
"http://example/p1": [{"@value": "o1"}]
|
3347
|
-
}
|
3348
|
-
}]
|
3349
|
-
}]),
|
3350
|
-
context: %({"ex": "http://example/"}),
|
3351
|
-
output: %({
|
3352
|
-
"@context": {"ex": "http://example/"},
|
3353
|
-
"@id": "ex:s",
|
3354
|
-
"ex:p": {
|
3355
|
-
"@id": {
|
3356
|
-
"@id": "ex:s1",
|
3357
|
-
"ex:p1": "o1"
|
3358
|
-
}
|
3359
|
-
}
|
3360
|
-
})
|
3361
|
-
},
|
3362
|
-
"recursive-subject": {
|
3363
|
-
input: %([{
|
3364
|
-
"@id": {
|
3365
|
-
"@id": {
|
3366
|
-
"@id": "http://example/s2",
|
3367
|
-
"http://example/p2": [{"@id": "http://example/o2"}]
|
3368
|
-
},
|
3369
|
-
"http://example/p1": [{"@id": "http://example/o1"}]
|
3370
|
-
},
|
3371
|
-
"http://example/p": [{"@id": "http://example/o"}]
|
3372
|
-
}]),
|
3373
|
-
context: %({"ex": "http://example/"}),
|
3374
|
-
output: %({
|
3375
|
-
"@context": {"ex": "http://example/"},
|
3376
|
-
"@id": {
|
3377
|
-
"@id": {
|
3378
|
-
"@id": "ex:s2",
|
3379
|
-
"ex:p2": {"@id": "ex:o2"}
|
3380
|
-
},
|
3381
|
-
"ex:p1": {"@id": "ex:o1"}
|
3382
|
-
},
|
3383
|
-
"ex:p": {"@id": "ex:o"}
|
3384
|
-
})
|
3385
|
-
},
|
3386
|
-
}.each do |name, params|
|
3387
|
-
it(name) {run_compact(params.merge(rdfstar: true))}
|
3388
|
-
end
|
3389
|
-
end
|
3390
|
-
|
3391
|
-
context "problem cases" do
|
3392
|
-
{
|
3393
|
-
"issue json-ld-framing#64": {
|
3394
|
-
input: %({
|
3395
|
-
"@context": {
|
3396
|
-
"@version": 1.1,
|
3397
|
-
"@vocab": "http://example.org/vocab#"
|
3398
|
-
},
|
3399
|
-
"@id": "http://example.org/1",
|
3400
|
-
"@type": "HumanMadeObject",
|
3401
|
-
"produced_by": {
|
3402
|
-
"@type": "Production",
|
3403
|
-
"_label": "Top Production",
|
3404
|
-
"part": {
|
3405
|
-
"@type": "Production",
|
3406
|
-
"_label": "Test Part"
|
3407
|
-
}
|
3408
|
-
}
|
3409
|
-
}),
|
3410
|
-
context: %({
|
3411
|
-
"@version": 1.1,
|
3412
|
-
"@vocab": "http://example.org/vocab#",
|
3413
|
-
"Production": {
|
3414
|
-
"@context": {
|
3415
|
-
"part": {
|
3416
|
-
"@type": "@id",
|
3417
|
-
"@container": "@set"
|
3418
|
-
}
|
3419
|
-
}
|
3420
|
-
}
|
3421
|
-
}),
|
3422
|
-
output: %({
|
3423
|
-
"@context": {
|
3424
|
-
"@version": 1.1,
|
3425
|
-
"@vocab": "http://example.org/vocab#",
|
3426
|
-
"Production": {
|
3427
|
-
"@context": {
|
3428
|
-
"part": {
|
3429
|
-
"@type": "@id",
|
3430
|
-
"@container": "@set"
|
3431
|
-
}
|
3432
|
-
}
|
3433
|
-
}
|
3434
|
-
},
|
3435
|
-
"@id": "http://example.org/1",
|
3436
|
-
"@type": "HumanMadeObject",
|
3437
|
-
"produced_by": {
|
3438
|
-
"@type": "Production",
|
3439
|
-
"part": [{
|
3440
|
-
"@type": "Production",
|
3441
|
-
"_label": "Test Part"
|
3442
|
-
}],
|
3443
|
-
"_label": "Top Production"
|
3444
|
-
}
|
3445
|
-
}),
|
3446
|
-
processingMode: "json-ld-1.1"
|
3447
|
-
}
|
3448
|
-
}.each do |title, params|
|
3449
|
-
it title do
|
3450
|
-
run_compact(params)
|
3451
|
-
end
|
3452
|
-
end
|
3453
|
-
end
|
3454
|
-
|
3455
|
-
def run_compact(params)
|
3456
|
-
input, output, context = params[:input], params[:output], params[:context]
|
3457
|
-
params[:base] ||= nil
|
3458
|
-
context ||= output # Since it will have the context
|
3459
|
-
input = ::JSON.parse(input) if input.is_a?(String)
|
3460
|
-
output = ::JSON.parse(output) if output.is_a?(String)
|
3461
|
-
context = ::JSON.parse(context) if context.is_a?(String)
|
3462
|
-
context = context['@context'] if context.key?('@context')
|
3463
|
-
pending params.fetch(:pending, "test implementation") unless input
|
3464
|
-
if params[:exception]
|
3465
|
-
expect {JSON::LD::API.compact(input, context, logger: logger, **params)}.to raise_error(params[:exception])
|
3466
|
-
else
|
3467
|
-
jld = nil
|
3468
|
-
if params[:write]
|
3469
|
-
expect{jld = JSON::LD::API.compact(input, context, logger: logger, **params)}.to write(params[:write]).to(:error)
|
3470
|
-
else
|
3471
|
-
expect{jld = JSON::LD::API.compact(input, context, logger: logger, **params)}.not_to write.to(:error)
|
3472
|
-
end
|
3473
|
-
|
3474
|
-
expect(jld).to produce_jsonld(output, logger)
|
3475
|
-
|
3476
|
-
# Compare expanded jld/output too to make sure list values remain ordered
|
3477
|
-
exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
|
3478
|
-
exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
|
3479
|
-
expect(exp_jld).to produce_jsonld(exp_output, logger)
|
3480
|
-
end
|
3481
|
-
end
|
3482
|
-
end
|