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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/json/ld/api.rb +807 -764
  4. data/lib/json/ld/compact.rb +304 -304
  5. data/lib/json/ld/conneg.rb +179 -161
  6. data/lib/json/ld/context.rb +2080 -1945
  7. data/lib/json/ld/expand.rb +745 -666
  8. data/lib/json/ld/extensions.rb +14 -13
  9. data/lib/json/ld/flatten.rb +257 -247
  10. data/lib/json/ld/format.rb +202 -194
  11. data/lib/json/ld/frame.rb +525 -502
  12. data/lib/json/ld/from_rdf.rb +224 -166
  13. data/lib/json/ld/html/nokogiri.rb +123 -121
  14. data/lib/json/ld/html/rexml.rb +151 -147
  15. data/lib/json/ld/reader.rb +107 -100
  16. data/lib/json/ld/resource.rb +224 -205
  17. data/lib/json/ld/streaming_reader.rb +574 -507
  18. data/lib/json/ld/streaming_writer.rb +93 -92
  19. data/lib/json/ld/to_rdf.rb +171 -167
  20. data/lib/json/ld/utils.rb +270 -264
  21. data/lib/json/ld/version.rb +24 -14
  22. data/lib/json/ld/writer.rb +334 -311
  23. data/lib/json/ld.rb +103 -96
  24. metadata +78 -209
  25. data/spec/api_spec.rb +0 -132
  26. data/spec/compact_spec.rb +0 -3482
  27. data/spec/conneg_spec.rb +0 -373
  28. data/spec/context_spec.rb +0 -2036
  29. data/spec/expand_spec.rb +0 -4496
  30. data/spec/flatten_spec.rb +0 -1203
  31. data/spec/format_spec.rb +0 -115
  32. data/spec/frame_spec.rb +0 -2498
  33. data/spec/from_rdf_spec.rb +0 -1005
  34. data/spec/matchers.rb +0 -20
  35. data/spec/rdfstar_spec.rb +0 -25
  36. data/spec/reader_spec.rb +0 -883
  37. data/spec/resource_spec.rb +0 -76
  38. data/spec/spec_helper.rb +0 -281
  39. data/spec/streaming_reader_spec.rb +0 -237
  40. data/spec/streaming_writer_spec.rb +0 -145
  41. data/spec/suite_compact_spec.rb +0 -22
  42. data/spec/suite_expand_spec.rb +0 -36
  43. data/spec/suite_flatten_spec.rb +0 -34
  44. data/spec/suite_frame_spec.rb +0 -29
  45. data/spec/suite_from_rdf_spec.rb +0 -22
  46. data/spec/suite_helper.rb +0 -411
  47. data/spec/suite_html_spec.rb +0 -22
  48. data/spec/suite_http_spec.rb +0 -35
  49. data/spec/suite_remote_doc_spec.rb +0 -22
  50. data/spec/suite_to_rdf_spec.rb +0 -30
  51. data/spec/support/extensions.rb +0 -44
  52. data/spec/test-files/test-1-compacted.jsonld +0 -10
  53. data/spec/test-files/test-1-context.jsonld +0 -7
  54. data/spec/test-files/test-1-expanded.jsonld +0 -5
  55. data/spec/test-files/test-1-input.jsonld +0 -10
  56. data/spec/test-files/test-1-rdf.ttl +0 -8
  57. data/spec/test-files/test-2-compacted.jsonld +0 -20
  58. data/spec/test-files/test-2-context.jsonld +0 -7
  59. data/spec/test-files/test-2-expanded.jsonld +0 -16
  60. data/spec/test-files/test-2-input.jsonld +0 -20
  61. data/spec/test-files/test-2-rdf.ttl +0 -14
  62. data/spec/test-files/test-3-compacted.jsonld +0 -11
  63. data/spec/test-files/test-3-context.jsonld +0 -8
  64. data/spec/test-files/test-3-expanded.jsonld +0 -10
  65. data/spec/test-files/test-3-input.jsonld +0 -11
  66. data/spec/test-files/test-3-rdf.ttl +0 -8
  67. data/spec/test-files/test-4-compacted.jsonld +0 -10
  68. data/spec/test-files/test-4-context.jsonld +0 -7
  69. data/spec/test-files/test-4-expanded.jsonld +0 -6
  70. data/spec/test-files/test-4-input.jsonld +0 -10
  71. data/spec/test-files/test-4-rdf.ttl +0 -5
  72. data/spec/test-files/test-5-compacted.jsonld +0 -13
  73. data/spec/test-files/test-5-context.jsonld +0 -7
  74. data/spec/test-files/test-5-expanded.jsonld +0 -9
  75. data/spec/test-files/test-5-input.jsonld +0 -13
  76. data/spec/test-files/test-5-rdf.ttl +0 -7
  77. data/spec/test-files/test-6-compacted.jsonld +0 -10
  78. data/spec/test-files/test-6-context.jsonld +0 -7
  79. data/spec/test-files/test-6-expanded.jsonld +0 -10
  80. data/spec/test-files/test-6-input.jsonld +0 -10
  81. data/spec/test-files/test-6-rdf.ttl +0 -6
  82. data/spec/test-files/test-7-compacted.jsonld +0 -23
  83. data/spec/test-files/test-7-context.jsonld +0 -4
  84. data/spec/test-files/test-7-expanded.jsonld +0 -20
  85. data/spec/test-files/test-7-input.jsonld +0 -23
  86. data/spec/test-files/test-7-rdf.ttl +0 -14
  87. data/spec/test-files/test-8-compacted.jsonld +0 -34
  88. data/spec/test-files/test-8-context.jsonld +0 -11
  89. data/spec/test-files/test-8-expanded.jsonld +0 -24
  90. data/spec/test-files/test-8-frame.jsonld +0 -18
  91. data/spec/test-files/test-8-framed.jsonld +0 -25
  92. data/spec/test-files/test-8-input.jsonld +0 -30
  93. data/spec/test-files/test-8-rdf.ttl +0 -15
  94. data/spec/test-files/test-9-compacted.jsonld +0 -20
  95. data/spec/test-files/test-9-context.jsonld +0 -13
  96. data/spec/test-files/test-9-expanded.jsonld +0 -14
  97. data/spec/test-files/test-9-input.jsonld +0 -12
  98. data/spec/to_rdf_spec.rb +0 -1551
  99. data/spec/writer_spec.rb +0 -427
@@ -1,1005 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
- require 'rdf/spec/writer'
4
-
5
- describe JSON::LD::API do
6
- let(:logger) {RDF::Spec.logger}
7
-
8
- describe ".fromRdf" do
9
- context "simple tests" do
10
- it "One subject IRI object" do
11
- input = %(<http://a/b> <http://a/c> <http://a/d> .)
12
- expect(serialize(input)).to produce_jsonld([
13
- {
14
- '@id' => "http://a/b",
15
- "http://a/c" => [{"@id" => "http://a/d"}]
16
- }
17
- ], logger)
18
- end
19
-
20
- it "should generate object list" do
21
- input = %(@prefix : <http://example.com/> . :b :c :d, :e .)
22
- expect(serialize(input)).
23
- to produce_jsonld([{
24
- '@id' => "http://example.com/b",
25
- "http://example.com/c" => [
26
- {"@id" => "http://example.com/d"},
27
- {"@id" => "http://example.com/e"}
28
- ]
29
- }
30
- ], logger)
31
- end
32
-
33
- it "should generate property list" do
34
- input = %(@prefix : <http://example.com/> . :b :c :d; :e :f .)
35
- expect(serialize(input)).
36
- to produce_jsonld([{
37
- '@id' => "http://example.com/b",
38
- "http://example.com/c" => [{"@id" => "http://example.com/d"}],
39
- "http://example.com/e" => [{"@id" => "http://example.com/f"}]
40
- }
41
- ], logger)
42
- end
43
-
44
- it "serializes multiple subjects" do
45
- input = %q(
46
- @prefix : <http://www.w3.org/2006/03/test-description#> .
47
- @prefix dc: <http://purl.org/dc/elements/1.1/> .
48
- <test-cases/0001> a :TestCase .
49
- <test-cases/0002> a :TestCase .
50
- )
51
- expect(serialize(input)).
52
- to produce_jsonld([
53
- {'@id' => "test-cases/0001", '@type' => ["http://www.w3.org/2006/03/test-description#TestCase"]},
54
- {'@id' => "test-cases/0002", '@type' => ["http://www.w3.org/2006/03/test-description#TestCase"]},
55
- ], logger)
56
- end
57
- end
58
-
59
- context "literals" do
60
- context "coercion" do
61
- it "typed literal" do
62
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"^^ex:d .)
63
- expect(serialize(input)).to produce_jsonld([
64
- {
65
- '@id' => "http://example.com/a",
66
- "http://example.com/b" => [{"@value" => "foo", "@type" => "http://example.com/d"}]
67
- }
68
- ], logger)
69
- end
70
-
71
- it "integer" do
72
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
73
- expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
74
- '@id' => "http://example.com/a",
75
- "http://example.com/b" => [{"@value" => 1}]
76
- }], logger)
77
- end
78
-
79
- it "integer (non-native)" do
80
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
81
- expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
82
- '@id' => "http://example.com/a",
83
- "http://example.com/b" => [{"@value" => "1","@type" => "http://www.w3.org/2001/XMLSchema#integer"}]
84
- }], logger)
85
- end
86
-
87
- it "boolean" do
88
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
89
- expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
90
- '@id' => "http://example.com/a",
91
- "http://example.com/b" => [{"@value" => true}]
92
- }], logger)
93
- end
94
-
95
- it "boolean (non-native)" do
96
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
97
- expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
98
- '@id' => "http://example.com/a",
99
- "http://example.com/b" => [{"@value" => "true","@type" => "http://www.w3.org/2001/XMLSchema#boolean"}]
100
- }], logger)
101
- end
102
-
103
- it "decmal" do
104
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0 .)
105
- expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
106
- '@id' => "http://example.com/a",
107
- "http://example.com/b" => [{"@value" => "1.0", "@type" => "http://www.w3.org/2001/XMLSchema#decimal"}]
108
- }], logger)
109
- end
110
-
111
- it "double" do
112
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
113
- expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
114
- '@id' => "http://example.com/a",
115
- "http://example.com/b" => [{"@value" => 1.0E0}]
116
- }], logger)
117
- end
118
-
119
- it "double (non-native)" do
120
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
121
- expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
122
- '@id' => "http://example.com/a",
123
- "http://example.com/b" => [{"@value" => "1.0E0","@type" => "http://www.w3.org/2001/XMLSchema#double"}]
124
- }], logger)
125
- end
126
- end
127
-
128
- context "datatyped (non-native)" do
129
- {
130
- integer: 1,
131
- unsignedInteger: 1,
132
- nonNegativeInteger: 1,
133
- float: 1,
134
- nonPositiveInteger: -1,
135
- negativeInteger: -1,
136
- }.each do |t, v|
137
- it "#{t}" do
138
- input = %(
139
- @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
140
- @prefix ex: <http://example.com/> .
141
- ex:a ex:b "#{v}"^^xsd:#{t} .
142
- )
143
- expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
144
- '@id' => "http://example.com/a",
145
- "http://example.com/b" => [{"@value" => "#{v}","@type" => "http://www.w3.org/2001/XMLSchema##{t}"}]
146
- }], logger)
147
- end
148
- end
149
- end
150
-
151
- it "encodes language literal" do
152
- input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"@en-us .)
153
- expect(serialize(input)).to produce_jsonld([{
154
- '@id' => "http://example.com/a",
155
- "http://example.com/b" => [{"@value" => "foo", "@language" => "en-us"}]
156
- }], logger)
157
- end
158
-
159
- context "with @type: @json" do
160
- {
161
- "true": {
162
- output: %([{
163
- "@id": "http://example.org/vocab#id",
164
- "http://example.org/vocab#bool": [{"@value": true, "@type": "@json"}]
165
- }]),
166
- input:%(
167
- @prefix ex: <http://example.org/vocab#> .
168
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
169
- ex:id ex:bool "true"^^rdf:JSON .
170
- )
171
- },
172
- "false": {
173
- output: %([{
174
- "@id": "http://example.org/vocab#id",
175
- "http://example.org/vocab#bool": [{"@value": false, "@type": "@json"}]
176
- }]),
177
- input: %(
178
- @prefix ex: <http://example.org/vocab#> .
179
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
180
- ex:id ex:bool "false"^^rdf:JSON .
181
- )
182
- },
183
- "double": {
184
- output: %([{
185
- "@id": "http://example.org/vocab#id",
186
- "http://example.org/vocab#double": [{"@value": 1.23E0, "@type": "@json"}]
187
- }]),
188
- input: %(
189
- @prefix ex: <http://example.org/vocab#> .
190
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
191
- ex:id ex:double "1.23E0"^^rdf:JSON .
192
- )
193
- },
194
- "double-zero": {
195
- output: %([{
196
- "@id": "http://example.org/vocab#id",
197
- "http://example.org/vocab#double": [{"@value": 0, "@type": "@json"}]
198
- }]),
199
- input: %(
200
- @prefix ex: <http://example.org/vocab#> .
201
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
202
- ex:id ex:double "0.0E0"^^rdf:JSON .
203
- )
204
- },
205
- "integer": {
206
- output: %([{
207
- "@id": "http://example.org/vocab#id",
208
- "http://example.org/vocab#integer": [{"@value": 123, "@type": "@json"}]
209
- }]),
210
- input: %(
211
- @prefix ex: <http://example.org/vocab#> .
212
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
213
- ex:id ex:integer "123"^^rdf:JSON .
214
- )
215
- },
216
- "string": {
217
- output: %([{
218
- "@id": "http://example.org/vocab#id",
219
- "http://example.org/vocab#string": [{
220
- "@value": "string",
221
- "@type": "@json"
222
- }]
223
- }]),
224
- input: %(
225
- @prefix ex: <http://example.org/vocab#> .
226
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
227
- ex:id ex:string "\\"string\\""^^rdf:JSON .
228
- )
229
- },
230
- "null": {
231
- output: %([{
232
- "@id": "http://example.org/vocab#id",
233
- "http://example.org/vocab#null": [{
234
- "@value": null,
235
- "@type": "@json"
236
- }]
237
- }]),
238
- input: %(
239
- @prefix ex: <http://example.org/vocab#> .
240
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
241
- ex:id ex:null "null"^^rdf:JSON .
242
- )
243
- },
244
- "object": {
245
- output: %([{
246
- "@id": "http://example.org/vocab#id",
247
- "http://example.org/vocab#object": [{"@value": {"foo": "bar"}, "@type": "@json"}]
248
- }]),
249
- input: %(
250
- @prefix ex: <http://example.org/vocab#> .
251
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
252
- ex:id ex:object """{"foo":"bar"}"""^^rdf:JSON .
253
- )
254
- },
255
- "array": {
256
- output: %([{
257
- "@id": "http://example.org/vocab#id",
258
- "http://example.org/vocab#array": [{"@value": [{"foo": "bar"}], "@type": "@json"}]
259
- }]),
260
- input: %(
261
- @prefix ex: <http://example.org/vocab#> .
262
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
263
- ex:id ex:array """[{"foo":"bar"}]"""^^rdf:JSON .
264
- )
265
- },
266
- }.each do |title, params|
267
- params[:input] = RDF::Graph.new << RDF::Turtle::Reader.new(params[:input])
268
- it(title) {do_fromRdf(processingMode: "json-ld-1.1", **params)}
269
- end
270
- end
271
- end
272
-
273
- context "anons" do
274
- it "should generate bare anon" do
275
- input = %(@prefix : <http://example.com/> . _:a :a :b .)
276
- expect(serialize(input)).to produce_jsonld([
277
- {
278
- "@id" => "_:a",
279
- "http://example.com/a" => [{"@id" => "http://example.com/b"}]
280
- }
281
- ], logger)
282
- end
283
-
284
- it "should generate anon as object" do
285
- input = %(@prefix : <http://example.com/> . :a :b _:a . _:a :c :d .)
286
- expect(serialize(input)).to produce_jsonld([
287
- {
288
- "@id" => "_:a",
289
- "http://example.com/c" => [{"@id" => "http://example.com/d"}]
290
- },
291
- {
292
- "@id" => "http://example.com/a",
293
- "http://example.com/b" => [{"@id" => "_:a"}]
294
- }
295
- ], logger)
296
- end
297
- end
298
-
299
- context "lists" do
300
- {
301
- "literal list" => {
302
- input: %q(
303
- @prefix : <http://example.com/> .
304
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
305
- :a :b ("apple" "banana") .
306
- ),
307
- output: [{
308
- '@id' => "http://example.com/a",
309
- "http://example.com/b" => [{
310
- "@list" => [
311
- {"@value" => "apple"},
312
- {"@value" => "banana"}
313
- ]
314
- }]
315
- }]
316
- },
317
- "iri list" => {
318
- input: %q(@prefix : <http://example.com/> . :a :b (:c) .),
319
- output: [{
320
- '@id' => "http://example.com/a",
321
- "http://example.com/b" => [{
322
- "@list" => [
323
- {"@id" => "http://example.com/c"}
324
- ]
325
- }]
326
- }]
327
- },
328
- "empty list" => {
329
- input: %q(@prefix : <http://example.com/> . :a :b () .),
330
- output: [{
331
- '@id' => "http://example.com/a",
332
- "http://example.com/b" => [{"@list" => []}]
333
- }]
334
- },
335
- "single element list" => {
336
- input: %q(@prefix : <http://example.com/> . :a :b ( "apple" ) .),
337
- output: [{
338
- '@id' => "http://example.com/a",
339
- "http://example.com/b" => [{"@list" => [{"@value" => "apple"}]}]
340
- }]
341
- },
342
- "single element list without @type" => {
343
- input: %q(@prefix : <http://example.com/> . :a :b ( _:a ) . _:a :b "foo" .),
344
- output: [
345
- {
346
- '@id' => "_:a",
347
- "http://example.com/b" => [{"@value" => "foo"}]
348
- },
349
- {
350
- '@id' => "http://example.com/a",
351
- "http://example.com/b" => [{"@list" => [{"@id" => "_:a"}]}]
352
- },
353
- ]
354
- },
355
- "multiple graphs with shared BNode" => {
356
- input: %q(
357
- <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> .
358
- _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> .
359
- _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> .
360
- _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-B" <http://www.example.com/G> .
361
- _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://www.example.com/G> .
362
- <http://www.example.com/x> <http://www.example.com/p> _:z1 <http://www.example.com/G1> .
363
- ),
364
- output: [{
365
- "@id" => "http://www.example.com/G",
366
- "@graph" => [{
367
- "@id" => "_:z0",
368
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-A"}],
369
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@id" => "_:z1"}]
370
- }, {
371
- "@id" => "_:z1",
372
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-B"}],
373
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@list" => []}]
374
- }, {
375
- "@id" => "http://www.example.com/z",
376
- "http://www.example.com/q" => [{"@id" => "_:z0"}]
377
- }]
378
- },
379
- {
380
- "@id" => "http://www.example.com/G1",
381
- "@graph" => [{
382
- "@id" => "http://www.example.com/x",
383
- "http://www.example.com/p" => [{"@id" => "_:z1"}]
384
- }]
385
- }],
386
- reader: RDF::NQuads::Reader
387
- },
388
- "multiple graphs with shared BNode (at head)" => {
389
- input: %q(
390
- <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> .
391
- _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> .
392
- _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> .
393
- _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-B" <http://www.example.com/G> .
394
- _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://www.example.com/G> .
395
- <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G1> .
396
- ),
397
- output: [{
398
- "@id" => "http://www.example.com/G",
399
- "@graph" => [{
400
- "@id" => "_:z0",
401
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-A"}],
402
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@list" => [{ "@value" => "cell-B" }]}]
403
- }, {
404
- "@id" => "http://www.example.com/z",
405
- "http://www.example.com/q" => [{"@id" => "_:z0"}]
406
- }]
407
- },
408
- {
409
- "@id" => "http://www.example.com/G1",
410
- "@graph" => [{
411
- "@id" => "http://www.example.com/z",
412
- "http://www.example.com/q" => [{"@id" => "_:z0"}]
413
- }]
414
- }],
415
- reader: RDF::NQuads::Reader
416
- },
417
- "@list containing empty @list" => {
418
- input: %(
419
- <http://example.com/a> <http://example.com/property> (()) .
420
- ),
421
- output: %([{
422
- "@id": "http://example.com/a",
423
- "http://example.com/property": [{"@list": [{"@list": []}]}]
424
- }]),
425
- reader: RDF::Turtle::Reader
426
- },
427
- "@list containing multiple lists" => {
428
- input: %(
429
- <http://example.com/a> <http://example.com/property> (("a") ("b")) .
430
- ),
431
- output: %([{
432
- "@id": "http://example.com/a",
433
- "http://example.com/property": [{"@list": [
434
- {"@list": [{"@value": "a"}]},
435
- {"@list": [{"@value": "b"}]}
436
- ]}]
437
- }]),
438
- reader: RDF::Turtle::Reader
439
- },
440
- "0008a" => {
441
- input: %(
442
- <http://example.com> <http://example.com/property> _:outerlist .
443
- _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:lista .
444
- _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b0 .
445
-
446
- _:lista <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a1" .
447
- _:lista <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a2 .
448
- _:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a2" .
449
- _:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a3 .
450
- _:a3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a3" .
451
- _:a3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
452
-
453
- _:c0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:c1 .
454
- _:c0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
455
- _:c1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c1" .
456
- _:c1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c2 .
457
- _:c2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c2" .
458
- _:c2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c3 .
459
- _:c3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c3" .
460
- _:c3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
461
-
462
- _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:b1 .
463
- _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c0 .
464
- _:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b1" .
465
- _:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b2 .
466
- _:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b2" .
467
- _:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b3 .
468
- _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b3" .
469
- _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
470
- ),
471
- output: JSON.parse(%([
472
- {
473
- "@id": "http://example.com",
474
- "http://example.com/property": [
475
- {
476
- "@list": [
477
- {"@list": [{"@value": "a1"}, {"@value": "a2"}, {"@value": "a3"}]},
478
- {"@list": [{"@value": "b1"}, {"@value": "b2"}, {"@value": "b3"}]},
479
- {"@list": [{"@value": "c1"}, {"@value": "c2"}, {"@value": "c3"}]}
480
- ]
481
- }
482
- ]
483
- }
484
- ])),
485
- reader: RDF::NQuads::Reader
486
- }
487
- }.each do |name, params|
488
- it "#{name}" do
489
- do_fromRdf(params)
490
- end
491
- end
492
- end
493
-
494
- context "quads" do
495
- {
496
- "simple named graph" => {
497
- input: %(
498
- <http://example.com/a> <http://example.com/b> <http://example.com/c> <http://example.com/U> .
499
- ),
500
- output: [
501
- {
502
- "@id" => "http://example.com/U",
503
- "@graph" => [{
504
- "@id" => "http://example.com/a",
505
- "http://example.com/b" => [{"@id" => "http://example.com/c"}]
506
- }]
507
- },
508
- ]
509
- },
510
- "with properties" => {
511
- input: %(
512
- <http://example.com/a> <http://example.com/b> <http://example.com/c> <http://example.com/U> .
513
- <http://example.com/U> <http://example.com/d> <http://example.com/e> .
514
- ),
515
- output: [
516
- {
517
- "@id" => "http://example.com/U",
518
- "@graph" => [{
519
- "@id" => "http://example.com/a",
520
- "http://example.com/b" => [{"@id" => "http://example.com/c"}]
521
- }],
522
- "http://example.com/d" => [{"@id" => "http://example.com/e"}]
523
- }
524
- ]
525
- },
526
- "with lists" => {
527
- input: %(
528
- <http://example.com/a> <http://example.com/b> _:a <http://example.com/U> .
529
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/c> <http://example.com/U> .
530
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://example.com/U> .
531
- <http://example.com/U> <http://example.com/d> _:b .
532
- _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/e> .
533
- _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
534
- ),
535
- output: [
536
- {
537
- "@id" => "http://example.com/U",
538
- "@graph" => [{
539
- "@id" => "http://example.com/a",
540
- "http://example.com/b" => [{"@list" => [{"@id" => "http://example.com/c"}]}]
541
- }],
542
- "http://example.com/d" => [{"@list" => [{"@id" => "http://example.com/e"}]}]
543
- }
544
- ]
545
- },
546
- "Two Graphs with same subject and lists" => {
547
- input: %(
548
- <http://example.com/a> <http://example.com/b> _:a <http://example.com/U> .
549
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/c> <http://example.com/U> .
550
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://example.com/U> .
551
- <http://example.com/a> <http://example.com/b> _:b <http://example.com/V> .
552
- _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/e> <http://example.com/V> .
553
- _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://example.com/V> .
554
- ),
555
- output: [
556
- {
557
- "@id" => "http://example.com/U",
558
- "@graph" => [
559
- {
560
- "@id" => "http://example.com/a",
561
- "http://example.com/b" => [{
562
- "@list" => [{"@id" => "http://example.com/c"}]
563
- }]
564
- }
565
- ]
566
- },
567
- {
568
- "@id" => "http://example.com/V",
569
- "@graph" => [
570
- {
571
- "@id" => "http://example.com/a",
572
- "http://example.com/b" => [{
573
- "@list" => [{"@id" => "http://example.com/e"}]
574
- }]
575
- }
576
- ]
577
- }
578
- ]
579
- },
580
- }.each_pair do |name, params|
581
- it "#{name}" do
582
- do_fromRdf(params.merge(reader: RDF::NQuads::Reader))
583
- end
584
- end
585
- end
586
-
587
- context "@direction" do
588
- context "rdfDirection: null" do
589
- {
590
- "no language rtl datatype": {
591
- input: %q(
592
- <http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
593
- ),
594
- output: %q([{
595
- "@id": "http://example.com/a",
596
- "http://example.org/label": [{"@value": "no language", "@type": "https://www.w3.org/ns/i18n#_rtl"}]
597
- }]),
598
- },
599
- "no language rtl compound-literal": {
600
- input: %q(
601
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
602
- <http://example.com/a> <http://example.org/label> _:cl1 .
603
-
604
- _:cl1 rdf:value "no language";
605
- rdf:direction "rtl" .
606
- ),
607
- output: %q([{
608
- "@id": "http://example.com/a",
609
- "http://example.org/label": [{"@id": "_:cl1"}]
610
- }, {
611
- "@id": "_:cl1",
612
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [{"@value": "no language"}],
613
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#direction": [{"@value": "rtl"}]
614
- }]),
615
- },
616
- "en-US rtl datatype": {
617
- input: %q(
618
- <http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-us_rtl> .
619
- ),
620
- output: %q([{
621
- "@id": "http://example.com/a",
622
- "http://example.org/label": [{"@value": "en-US", "@type": "https://www.w3.org/ns/i18n#en-us_rtl"}]
623
- }]),
624
- },
625
- "en-US rtl compound-literal": {
626
- input: %q(
627
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
628
- <http://example.com/a> <http://example.org/label> _:cl1 .
629
-
630
- _:cl1 rdf:value "en-US";
631
- rdf:language "en-us";
632
- rdf:direction "rtl" .
633
- ),
634
- output: %q([{
635
- "@id": "http://example.com/a",
636
- "http://example.org/label": [{"@id": "_:cl1"}]
637
- }, {
638
- "@id": "_:cl1",
639
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [{"@value": "en-US"}],
640
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#language": [{"@value": "en-us"}],
641
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#direction": [{"@value": "rtl"}]
642
- }]),
643
- }
644
- }.each_pair do |name, params|
645
- it name do
646
- do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: nil))
647
- end
648
- end
649
- end
650
-
651
- context "rdfDirection: i18n-datatype" do
652
- {
653
- "no language rtl datatype": {
654
- input: %q(
655
- <http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
656
- ),
657
- output: %q([{
658
- "@id": "http://example.com/a",
659
- "http://example.org/label": [{"@value": "no language", "@direction": "rtl"}]
660
- }]),
661
- },
662
- "no language rtl compound-literal": {
663
- input: %q(
664
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
665
- <http://example.com/a> <http://example.org/label> _:cl1 .
666
-
667
- _:cl1 rdf:value "no language";
668
- rdf:direction "rtl" .
669
- ),
670
- output: %q([{
671
- "@id": "http://example.com/a",
672
- "http://example.org/label": [{"@id": "_:cl1"}]
673
- }, {
674
- "@id": "_:cl1",
675
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [{"@value": "no language"}],
676
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#direction": [{"@value": "rtl"}]
677
- }]),
678
- },
679
- "en-US rtl datatype": {
680
- input: %q(
681
- <http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-US_rtl> .
682
- ),
683
- output: %q([{
684
- "@id": "http://example.com/a",
685
- "http://example.org/label": [{"@value": "en-US", "@language": "en-US", "@direction": "rtl"}]
686
- }]),
687
- },
688
- "en-US rtl compound-literal": {
689
- input: %q(
690
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
691
- <http://example.com/a> <http://example.org/label> _:cl1 .
692
-
693
- _:cl1 rdf:value "en-US";
694
- rdf:language "en-US";
695
- rdf:direction "rtl" .
696
- ),
697
- output: %q([{
698
- "@id": "http://example.com/a",
699
- "http://example.org/label": [{"@id": "_:cl1"}]
700
- }, {
701
- "@id": "_:cl1",
702
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [{"@value": "en-US"}],
703
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#language": [{"@value": "en-US"}],
704
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#direction": [{"@value": "rtl"}]
705
- }]),
706
- }
707
- }.each_pair do |name, params|
708
- it name do
709
- do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: 'i18n-datatype', processingMode: 'json-ld-1.1'))
710
- end
711
- end
712
- end
713
-
714
- context "rdfDirection: compound-literal" do
715
- {
716
- "no language rtl datatype": {
717
- input: %q(
718
- <http://example.com/a> <http://example.org/label> "no language"^^<https://www.w3.org/ns/i18n#_rtl> .
719
- ),
720
- output: %q([{
721
- "@id": "http://example.com/a",
722
- "http://example.org/label": [{"@value": "no language", "@type": "https://www.w3.org/ns/i18n#_rtl"}]
723
- }]),
724
- },
725
- "no language rtl compound-literal": {
726
- input: %q(
727
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
728
- <http://example.com/a> <http://example.org/label> _:cl1 .
729
-
730
- _:cl1 rdf:value "no language";
731
- rdf:direction "rtl" .
732
- ),
733
- output: %q([{
734
- "@id": "http://example.com/a",
735
- "http://example.org/label": [{"@value": "no language", "@direction": "rtl"}]
736
- }]),
737
- },
738
- "en-US rtl datatype": {
739
- input: %q(
740
- <http://example.com/a> <http://example.org/label> "en-US"^^<https://www.w3.org/ns/i18n#en-us_rtl> .
741
- ),
742
- output: %q([{
743
- "@id": "http://example.com/a",
744
- "http://example.org/label": [{"@value": "en-US", "@type": "https://www.w3.org/ns/i18n#en-us_rtl"}]
745
- }]),
746
- },
747
- "en-US rtl compound-literal": {
748
- input: %q(
749
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
750
- <http://example.com/a> <http://example.org/label> _:cl1 .
751
-
752
- _:cl1 rdf:value "en-US";
753
- rdf:language "en-us";
754
- rdf:direction "rtl" .
755
- ),
756
- output: %q([{
757
- "@id": "http://example.com/a",
758
- "http://example.org/label": [{"@value": "en-US", "@language": "en-us", "@direction": "rtl"}]
759
- }]),
760
- }
761
- }.each_pair do |name, params|
762
- it name do
763
- do_fromRdf(params.merge(reader: RDF::Turtle::Reader, rdfDirection: 'compound-literal', processingMode: 'json-ld-1.1'))
764
- end
765
- end
766
- end
767
- end
768
-
769
- context "RDF-star" do
770
- {
771
- "subject-iii": {
772
- input: RDF::Statement(
773
- RDF::Statement(
774
- RDF::URI('http://example/s1'),
775
- RDF::URI('http://example/p1'),
776
- RDF::URI('http://example/o1')),
777
- RDF::URI('http://example/p'),
778
- RDF::URI('http://example/o')),
779
- output: %([{
780
- "@id": {
781
- "@id": "http://example/s1",
782
- "http://example/p1": [{"@id": "http://example/o1"}]
783
- },
784
- "http://example/p": [{"@id": "http://example/o"}]
785
- }])
786
- },
787
- "subject-iib": {
788
- input: RDF::Statement(
789
- RDF::Statement(
790
- RDF::URI('http://example/s1'),
791
- RDF::URI('http://example/p1'),
792
- RDF::Node.new('o1')),
793
- RDF::URI('http://example/p'),
794
- RDF::URI('http://example/o')),
795
- output: %([{
796
- "@id": {
797
- "@id": "http://example/s1",
798
- "http://example/p1": [{"@id": "_:o1"}]
799
- },
800
- "http://example/p": [{"@id": "http://example/o"}]
801
- }])
802
- },
803
- "subject-iil": {
804
- input: RDF::Statement(
805
- RDF::Statement(
806
- RDF::URI('http://example/s1'),
807
- RDF::URI('http://example/p1'),
808
- RDF::Literal('o1')),
809
- RDF::URI('http://example/p'),
810
- RDF::URI('http://example/o')),
811
- output: %([{
812
- "@id": {
813
- "@id": "http://example/s1",
814
- "http://example/p1": [{"@value": "o1"}]
815
- },
816
- "http://example/p": [{"@id": "http://example/o"}]
817
- }])
818
- },
819
- "subject-bii": {
820
- input: RDF::Statement(
821
- RDF::Statement(
822
- RDF::Node('s1'),
823
- RDF::URI('http://example/p1'),
824
- RDF::URI('http://example/o1')),
825
- RDF::URI('http://example/p'),
826
- RDF::URI('http://example/o')),
827
- output: %([{
828
- "@id": {
829
- "@id": "_:s1",
830
- "http://example/p1": [{"@id": "http://example/o1"}]
831
- },
832
- "http://example/p": [{"@id": "http://example/o"}]
833
- }])
834
- },
835
- "subject-bib": {
836
- input: RDF::Statement(
837
- RDF::Statement(
838
- RDF::Node('s1'),
839
- RDF::URI('http://example/p1'),
840
- RDF::Node.new('o1')),
841
- RDF::URI('http://example/p'), RDF::URI('http://example/o')),
842
- output: %([{
843
- "@id": {
844
- "@id": "_:s1",
845
- "http://example/p1": [{"@id": "_:o1"}]
846
- },
847
- "http://example/p": [{"@id": "http://example/o"}]
848
- }])
849
- },
850
- "subject-bil": {
851
- input: RDF::Statement(
852
- RDF::Statement(
853
- RDF::Node('s1'),
854
- RDF::URI('http://example/p1'),
855
- RDF::Literal('o1')),
856
- RDF::URI('http://example/p'),
857
- RDF::URI('http://example/o')),
858
- output: %([{
859
- "@id": {
860
- "@id": "_:s1",
861
- "http://example/p1": [{"@value": "o1"}]
862
- },
863
- "http://example/p": [{"@id": "http://example/o"}]
864
- }])
865
- },
866
- "object-iii": {
867
- input: RDF::Statement(
868
- RDF::URI('http://example/s'),
869
- RDF::URI('http://example/p'),
870
- RDF::Statement(
871
- RDF::URI('http://example/s1'),
872
- RDF::URI('http://example/p1'),
873
- RDF::URI('http://example/o1'))),
874
- output: %([{
875
- "@id": "http://example/s",
876
- "http://example/p": [{
877
- "@id": {
878
- "@id": "http://example/s1",
879
- "http://example/p1": [{"@id": "http://example/o1"}]
880
- }
881
- }]
882
- }])
883
- },
884
- "object-iib": {
885
- input: RDF::Statement(
886
- RDF::URI('http://example/s'),
887
- RDF::URI('http://example/p'),
888
- RDF::Statement(
889
- RDF::URI('http://example/s1'),
890
- RDF::URI('http://example/p1'),
891
- RDF::Node.new('o1'))),
892
- output: %([{
893
- "@id": "http://example/s",
894
- "http://example/p": [{
895
- "@id": {
896
- "@id": "http://example/s1",
897
- "http://example/p1": [{"@id": "_:o1"}]
898
- }
899
- }]
900
- }])
901
- },
902
- "object-iil": {
903
- input: RDF::Statement(
904
- RDF::URI('http://example/s'),
905
- RDF::URI('http://example/p'),
906
- RDF::Statement(
907
- RDF::URI('http://example/s1'),
908
- RDF::URI('http://example/p1'),
909
- RDF::Literal('o1'))),
910
- output: %([{
911
- "@id": "http://example/s",
912
- "http://example/p": [{
913
- "@id": {
914
- "@id": "http://example/s1",
915
- "http://example/p1": [{"@value": "o1"}]
916
- }
917
- }]
918
- }])
919
- },
920
- "recursive-subject": {
921
- input: RDF::Statement(
922
- RDF::Statement(
923
- RDF::Statement(
924
- RDF::URI('http://example/s2'),
925
- RDF::URI('http://example/p2'),
926
- RDF::URI('http://example/o2')),
927
- RDF::URI('http://example/p1'),
928
- RDF::URI('http://example/o1')),
929
- RDF::URI('http://example/p'),
930
- RDF::URI('http://example/o')),
931
- output: %([{
932
- "@id": {
933
- "@id": {
934
- "@id": "http://example/s2",
935
- "http://example/p2": [{"@id": "http://example/o2"}]
936
- },
937
- "http://example/p1": [{"@id": "http://example/o1"}]
938
- },
939
- "http://example/p": [{"@id": "http://example/o"}]
940
- }])
941
- },
942
- }.each do |name, params|
943
- it name do
944
- graph = RDF::Graph.new {|g| g << params[:input]}
945
- do_fromRdf(params.merge(input: graph, prefixes: {ex: 'http://example/'}))
946
- end
947
- end
948
- end
949
-
950
- context "problems" do
951
- {
952
- "xsd:boolean as value" => {
953
- input: %(
954
- @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
955
- @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
956
-
957
- <http://data.wikia.com/terms#playable> rdfs:range xsd:boolean .
958
- ),
959
- output: [{
960
- "@id" => "http://data.wikia.com/terms#playable",
961
- "http://www.w3.org/2000/01/rdf-schema#range" => [
962
- { "@id" => "http://www.w3.org/2001/XMLSchema#boolean" }
963
- ]
964
- }]
965
- },
966
- }.each do |t, params|
967
- it "#{t}" do
968
- do_fromRdf(params)
969
- end
970
- end
971
- end
972
- end
973
-
974
- def parse(input, **options)
975
- reader = options[:reader] || RDF::TriG::Reader
976
- reader.new(input, **options, &:each_statement).to_a.extend(RDF::Enumerable)
977
- end
978
-
979
- # Serialize ntstr to a string and compare against regexps
980
- def serialize(ntstr, **options)
981
- logger.info ntstr if ntstr.is_a?(String)
982
- g = ntstr.is_a?(String) ? parse(ntstr, **options) : ntstr
983
- logger.info g.dump(:trig)
984
- statements = g.each_statement.to_a
985
- JSON::LD::API.fromRdf(statements, logger: logger, **options)
986
- end
987
-
988
- def do_fromRdf(params)
989
- begin
990
- input, output = params[:input], params[:output]
991
- output = ::JSON.parse(output) if output.is_a?(String)
992
- jld = nil
993
- if params[:write]
994
- expect{jld = serialize(input, **params)}.to write(params[:write]).to(:error)
995
- else
996
- expect{jld = serialize(input, **params)}.not_to write.to(:error)
997
- end
998
- expect(jld).to produce_jsonld(output, logger)
999
- rescue JSON::LD::JsonLdError => e
1000
- fail("#{e.class}: #{e.message}\n" +
1001
- "#{logger}\n" +
1002
- "Backtrace:\n#{e.backtrace.join("\n")}")
1003
- end
1004
- end
1005
- end