json-ld 3.2.4 → 3.3.0

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