json-ld 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/VERSION +1 -1
- data/bin/jsonld +3 -3
- data/lib/json/ld.rb +3 -1
- data/lib/json/ld/api.rb +22 -14
- data/lib/json/ld/compact.rb +3 -3
- data/lib/json/ld/context.rb +44 -44
- data/lib/json/ld/expand.rb +46 -8
- data/lib/json/ld/extensions.rb +4 -4
- data/lib/json/ld/flatten.rb +92 -9
- data/lib/json/ld/format.rb +1 -1
- data/lib/json/ld/frame.rb +8 -8
- data/lib/json/ld/from_rdf.rb +2 -2
- data/lib/json/ld/reader.rb +1 -0
- data/lib/json/ld/streaming_reader.rb +5 -5
- data/lib/json/ld/streaming_writer.rb +4 -4
- data/lib/json/ld/to_rdf.rb +2 -2
- data/lib/json/ld/utils.rb +13 -13
- data/lib/json/ld/writer.rb +2 -2
- data/spec/api_spec.rb +1 -1
- data/spec/compact_spec.rb +1 -1
- data/spec/expand_spec.rb +384 -1
- data/spec/flatten_spec.rb +517 -1
- data/spec/rdfstar_spec.rb +25 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/suite_flatten_spec.rb +4 -0
- data/spec/suite_frame_spec.rb +7 -0
- data/spec/suite_helper.rb +13 -7
- data/spec/to_rdf_spec.rb +3 -3
- metadata +63 -61
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe JSON::LD do
|
5
|
+
describe "test suite" do
|
6
|
+
require_relative 'suite_helper'
|
7
|
+
%w{
|
8
|
+
expand
|
9
|
+
compact
|
10
|
+
flatten
|
11
|
+
fromRdf
|
12
|
+
toRdf
|
13
|
+
}.each do |partial|
|
14
|
+
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::STAR_SUITE}#{partial}-manifest.jsonld")
|
15
|
+
describe m.name do
|
16
|
+
m.entries.each do |t|
|
17
|
+
specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
|
18
|
+
t.options[:ordered] = false
|
19
|
+
expect {t.run self}.not_to write.to(:error)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end unless ENV['CI']
|
data/spec/spec_helper.rb
CHANGED
@@ -67,6 +67,39 @@ def detect_format(stream)
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
# Creates a bijection between the two objects and replaces nodes in actual from expected.
|
71
|
+
def remap_bnodes(actual, expected)
|
72
|
+
# Transform each to RDF and perform a blank node bijection.
|
73
|
+
# Replace the blank nodes in action with the mapping from bijection.
|
74
|
+
ds_actual = RDF::Repository.new << JSON::LD::API.toRdf(actual, rdfstar: true, rename_bnodes: false)
|
75
|
+
ds_expected = RDF::Repository.new << JSON::LD::API.toRdf(expected, rdfstar: true, rename_bnodes: false)
|
76
|
+
if bijection = ds_actual.bijection_to(ds_expected)
|
77
|
+
bijection = bijection.inject({}) {|memo, (k, v)| memo.merge(k.to_s => v.to_s)}
|
78
|
+
|
79
|
+
# Recursively replace blank nodes in actual with the bijection
|
80
|
+
#require 'byebug'; byebug
|
81
|
+
replace_nodes(actual, bijection)
|
82
|
+
else
|
83
|
+
actual
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def replace_nodes(object, bijection)
|
88
|
+
case object
|
89
|
+
when Array
|
90
|
+
object.map {|o| replace_nodes(o, bijection)}
|
91
|
+
when Hash
|
92
|
+
object.inject({}) do |memo, (k, v)|
|
93
|
+
memo.merge(bijection.fetch(k, k) => replace_nodes(v, bijection))
|
94
|
+
end
|
95
|
+
when String
|
96
|
+
bijection.fetch(object, object)
|
97
|
+
else
|
98
|
+
object
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
70
103
|
LIBRARY_INPUT = JSON.parse(%([
|
71
104
|
{
|
72
105
|
"@id": "http://example.org/library",
|
data/spec/suite_flatten_spec.rb
CHANGED
@@ -7,6 +7,8 @@ describe JSON::LD do
|
|
7
7
|
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}flatten-manifest.jsonld")
|
8
8
|
describe m.name do
|
9
9
|
m.entries.each do |t|
|
10
|
+
t.options[:remap_bnodes] = %w(#t0045).include?(t.property('@id'))
|
11
|
+
|
10
12
|
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
11
13
|
t.options[:ordered] = false
|
12
14
|
if %w(#t0005).include?(t.property('@id'))
|
@@ -16,6 +18,8 @@ describe JSON::LD do
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
# Skip ordered tests when remapping bnodes
|
22
|
+
next if t.options[:remap_bnodes]
|
19
23
|
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
20
24
|
t.options[:ordered] = true
|
21
25
|
if %w(#t0005).include?(t.property('@id'))
|
data/spec/suite_frame_spec.rb
CHANGED
@@ -7,13 +7,20 @@ describe JSON::LD do
|
|
7
7
|
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld")
|
8
8
|
describe m.name do
|
9
9
|
m.entries.each do |t|
|
10
|
+
t.options[:remap_bnodes] = %w(#t0021 #tp021).include?(t.property('@id'))
|
11
|
+
|
10
12
|
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
11
13
|
t.options[:ordered] = false
|
12
14
|
expect {t.run self}.not_to write.to(:error)
|
13
15
|
end
|
14
16
|
|
17
|
+
# Skip ordered tests when remapping bnodes
|
18
|
+
next if t.options[:remap_bnodes]
|
15
19
|
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
16
20
|
t.options[:ordered] = true
|
21
|
+
if %w(#tp021).include?(t.property('@id'))
|
22
|
+
pending("changes due to blank node reordering")
|
23
|
+
end
|
17
24
|
expect {t.run self}.not_to write.to(:error)
|
18
25
|
end
|
19
26
|
end
|
data/spec/suite_helper.rb
CHANGED
@@ -7,6 +7,7 @@ module RDF::Util
|
|
7
7
|
"https://w3c.github.io/json-ld-api/tests/" => ::File.expand_path("../json-ld-api/tests", __FILE__) + '/',
|
8
8
|
"https://w3c.github.io/json-ld-framing/tests/" => ::File.expand_path("../json-ld-framing/tests", __FILE__) + '/',
|
9
9
|
"https://w3c.github.io/json-ld-streaming/tests/" => ::File.expand_path("../json-ld-streaming/tests", __FILE__) + '/',
|
10
|
+
"https://json-ld.github.io/json-ld-star/tests/" => ::File.expand_path("../json-ld-star/tests", __FILE__) + '/',
|
10
11
|
"file:" => ""
|
11
12
|
}
|
12
13
|
|
@@ -76,6 +77,7 @@ module Fixtures
|
|
76
77
|
SUITE = RDF::URI("https://w3c.github.io/json-ld-api/tests/")
|
77
78
|
FRAME_SUITE = RDF::URI("https://w3c.github.io/json-ld-framing/tests/")
|
78
79
|
STREAM_SUITE = RDF::URI("https://w3c.github.io/json-ld-streaming/tests/")
|
80
|
+
STAR_SUITE = RDF::URI("https://json-ld.github.io/json-ld-star/tests/")
|
79
81
|
|
80
82
|
class Manifest < JSON::LD::Resource
|
81
83
|
attr_accessor :manifest_url
|
@@ -201,8 +203,8 @@ module Fixtures
|
|
201
203
|
logger.info "frame: #{frame}" if frame_loc
|
202
204
|
|
203
205
|
options = self.options
|
204
|
-
|
205
|
-
skip "
|
206
|
+
if options[:specVersion] == "json-ld-1.0"
|
207
|
+
skip "1.0 test"
|
206
208
|
return
|
207
209
|
end
|
208
210
|
|
@@ -223,7 +225,7 @@ module Fixtures
|
|
223
225
|
JSON::LD::API.frame(input_loc, frame_loc, logger: logger, **options)
|
224
226
|
when "jld:FromRDFTest"
|
225
227
|
# Use an array, to preserve input order
|
226
|
-
repo = RDF::NQuads::Reader.open(input_loc) do |reader|
|
228
|
+
repo = RDF::NQuads::Reader.open(input_loc, rdfstar: options[:rdfstar]) do |reader|
|
227
229
|
reader.each_statement.to_a
|
228
230
|
end.to_a.uniq.extend(RDF::Enumerable)
|
229
231
|
logger.info "repo: #{repo.dump(self.id == '#t0012' ? :nquads : :trig)}"
|
@@ -235,7 +237,7 @@ module Fixtures
|
|
235
237
|
repo << statement
|
236
238
|
end
|
237
239
|
else
|
238
|
-
JSON::LD::API.toRdf(input_loc, logger: logger, **options) do |statement|
|
240
|
+
JSON::LD::API.toRdf(input_loc, rename_bnodes: false, logger: logger, **options) do |statement|
|
239
241
|
repo << statement
|
240
242
|
end
|
241
243
|
end
|
@@ -256,12 +258,16 @@ module Fixtures
|
|
256
258
|
end
|
257
259
|
if evaluationTest?
|
258
260
|
if testType == "jld:ToRDFTest"
|
259
|
-
expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect, logger: [])
|
261
|
+
expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect, rdfstar: options[:rdfstar], logger: [])
|
260
262
|
rspec_example.instance_eval {
|
261
263
|
expect(result).to be_equivalent_graph(expected, logger)
|
262
264
|
}
|
263
265
|
else
|
264
266
|
expected = JSON.load(expect)
|
267
|
+
|
268
|
+
# If called for, remap bnodes
|
269
|
+
result = remap_bnodes(result, expected) if options[:remap_bnodes]
|
270
|
+
|
265
271
|
if options[:ordered]
|
266
272
|
# Compare without transformation
|
267
273
|
rspec_example.instance_eval {
|
@@ -308,7 +314,7 @@ module Fixtures
|
|
308
314
|
when "jld:FrameTest"
|
309
315
|
JSON::LD::API.frame(t.input_loc, t.frame_loc, logger: logger, **options)
|
310
316
|
when "jld:FromRDFTest"
|
311
|
-
repo = RDF::Repository.load(t.input_loc)
|
317
|
+
repo = RDF::Repository.load(t.input_loc, rdfstar: options[:rdfstar])
|
312
318
|
logger.info "repo: #{repo.dump(t.id == '#t0012' ? :nquads : :trig)}"
|
313
319
|
JSON::LD::API.fromRdf(repo, logger: logger, **options)
|
314
320
|
when "jld:HttpTest"
|
@@ -325,7 +331,7 @@ module Fixtures
|
|
325
331
|
if t.manifest_url.to_s.include?('stream')
|
326
332
|
JSON::LD::Reader.open(t.input_loc, stream: true, logger: logger, **options).each_statement {}
|
327
333
|
else
|
328
|
-
JSON::LD::API.toRdf(t.input_loc, logger: logger, **options) {}
|
334
|
+
JSON::LD::API.toRdf(t.input_loc, rename_bnodes: false, logger: logger, **options) {}
|
329
335
|
end
|
330
336
|
else
|
331
337
|
success("Unknown test type: #{testType}")
|
data/spec/to_rdf_spec.rb
CHANGED
@@ -1528,7 +1528,7 @@ describe JSON::LD::API do
|
|
1528
1528
|
def parse(input, **options)
|
1529
1529
|
graph = options[:graph] || RDF::Graph.new
|
1530
1530
|
options = {logger: logger, validate: true, canonicalize: false}.merge(options)
|
1531
|
-
JSON::LD::API.toRdf(StringIO.new(input), **options) {|st| graph << st}
|
1531
|
+
JSON::LD::API.toRdf(StringIO.new(input), rename_bnodes: false, **options) {|st| graph << st}
|
1532
1532
|
graph
|
1533
1533
|
end
|
1534
1534
|
|
@@ -1541,9 +1541,9 @@ describe JSON::LD::API do
|
|
1541
1541
|
expect {JSON::LD::API.toRdf(input, **params)}.to raise_error(params[:exception])
|
1542
1542
|
else
|
1543
1543
|
if params[:write]
|
1544
|
-
expect{JSON::LD::API.toRdf(input, base: params[:base], logger: logger, **params) {|st| graph << st}}.to write(params[:write]).to(:error)
|
1544
|
+
expect{JSON::LD::API.toRdf(input, base: params[:base], logger: logger, rename_bnodes: false, **params) {|st| graph << st}}.to write(params[:write]).to(:error)
|
1545
1545
|
else
|
1546
|
-
expect{JSON::LD::API.toRdf(input, base: params[:base], logger: logger, **params) {|st| graph << st}}.not_to write.to(:error)
|
1546
|
+
expect{JSON::LD::API.toRdf(input, base: params[:base], logger: logger, rename_bnodes: false, **params) {|st| graph << st}}.not_to write.to(:error)
|
1547
1547
|
end
|
1548
1548
|
expect(graph).to be_equivalent_graph(output, logger: logger, inputDocument: input)
|
1549
1549
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-ld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -297,7 +297,7 @@ dependencies:
|
|
297
297
|
- !ruby/object:Gem::Version
|
298
298
|
version: '0.9'
|
299
299
|
description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion,
|
300
|
-
compaction and framing API interfaces.
|
300
|
+
compaction and framing API interfaces for the Ruby RDF.rb library suite.
|
301
301
|
email: public-linked-json@w3.org
|
302
302
|
executables:
|
303
303
|
- jsonld
|
@@ -340,6 +340,7 @@ files:
|
|
340
340
|
- spec/frame_spec.rb
|
341
341
|
- spec/from_rdf_spec.rb
|
342
342
|
- spec/matchers.rb
|
343
|
+
- spec/rdfstar_spec.rb
|
343
344
|
- spec/reader_spec.rb
|
344
345
|
- spec/resource_spec.rb
|
345
346
|
- spec/spec_helper.rb
|
@@ -426,85 +427,86 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
426
427
|
- !ruby/object:Gem::Version
|
427
428
|
version: '0'
|
428
429
|
requirements: []
|
429
|
-
rubygems_version: 3.
|
430
|
+
rubygems_version: 3.2.3
|
430
431
|
signing_key:
|
431
432
|
specification_version: 4
|
432
433
|
summary: JSON-LD reader/writer for Ruby.
|
433
434
|
test_files:
|
434
|
-
- spec/spec_helper.rb
|
435
|
-
- spec/matchers.rb
|
436
435
|
- spec/api_spec.rb
|
437
|
-
- spec/
|
436
|
+
- spec/compact_spec.rb
|
437
|
+
- spec/conneg_spec.rb
|
438
438
|
- spec/context_spec.rb
|
439
|
+
- spec/expand_spec.rb
|
440
|
+
- spec/flatten_spec.rb
|
441
|
+
- spec/format_spec.rb
|
442
|
+
- spec/frame_spec.rb
|
439
443
|
- spec/from_rdf_spec.rb
|
440
|
-
- spec/
|
444
|
+
- spec/matchers.rb
|
445
|
+
- spec/rdfstar_spec.rb
|
441
446
|
- spec/reader_spec.rb
|
442
|
-
- spec/streaming_writer_spec.rb
|
443
447
|
- spec/resource_spec.rb
|
444
|
-
- spec/
|
445
|
-
- spec/
|
446
|
-
- spec/
|
447
|
-
- spec/frame_spec.rb
|
448
|
-
- spec/to_rdf_spec.rb
|
449
|
-
- spec/conneg_spec.rb
|
450
|
-
- spec/support/extensions.rb
|
451
|
-
- spec/suite_html_spec.rb
|
452
|
-
- spec/flatten_spec.rb
|
453
|
-
- spec/suite_frame_spec.rb
|
448
|
+
- spec/spec_helper.rb
|
449
|
+
- spec/streaming_reader_spec.rb
|
450
|
+
- spec/streaming_writer_spec.rb
|
454
451
|
- spec/suite_compact_spec.rb
|
455
|
-
- spec/expand_spec.rb
|
456
452
|
- spec/suite_expand_spec.rb
|
457
453
|
- spec/suite_flatten_spec.rb
|
458
|
-
- spec/
|
454
|
+
- spec/suite_frame_spec.rb
|
455
|
+
- spec/suite_from_rdf_spec.rb
|
456
|
+
- spec/suite_helper.rb
|
457
|
+
- spec/suite_html_spec.rb
|
459
458
|
- spec/suite_http_spec.rb
|
460
|
-
- spec/
|
459
|
+
- spec/suite_remote_doc_spec.rb
|
460
|
+
- spec/suite_to_rdf_spec.rb
|
461
|
+
- spec/support/extensions.rb
|
462
|
+
- spec/to_rdf_spec.rb
|
461
463
|
- spec/writer_spec.rb
|
462
|
-
- spec/test-files/test-
|
463
|
-
- spec/test-files/test-
|
464
|
-
- spec/test-files/test-
|
465
|
-
- spec/test-files/test-
|
466
|
-
- spec/test-files/test-3-rdf.ttl
|
467
|
-
- spec/test-files/test-5-compacted.json
|
468
|
-
- spec/test-files/test-9-expanded.json
|
469
|
-
- spec/test-files/test-8-input.json
|
470
|
-
- spec/test-files/test-2-compacted.json
|
471
|
-
- spec/test-files/test-8-compacted.json
|
472
|
-
- spec/test-files/test-7-expanded.json
|
473
|
-
- spec/test-files/test-1-rdf.ttl
|
474
|
-
- spec/test-files/test-7-context.json
|
475
|
-
- spec/test-files/test-3-expanded.json
|
476
|
-
- spec/test-files/test-8-rdf.ttl
|
464
|
+
- spec/test-files/test-1-compacted.json
|
465
|
+
- spec/test-files/test-1-context.json
|
466
|
+
- spec/test-files/test-1-expanded.json
|
467
|
+
- spec/test-files/test-1-input.json
|
477
468
|
- spec/test-files/test-1-normalized.json
|
469
|
+
- spec/test-files/test-1-rdf.ttl
|
470
|
+
- spec/test-files/test-2-compacted.json
|
471
|
+
- spec/test-files/test-2-context.json
|
472
|
+
- spec/test-files/test-2-expanded.json
|
478
473
|
- spec/test-files/test-2-input.json
|
479
|
-
- spec/test-files/test-
|
480
|
-
- spec/test-files/test-
|
481
|
-
- spec/test-files/test-
|
482
|
-
- spec/test-files/test-
|
483
|
-
- spec/test-files/test-
|
484
|
-
- spec/test-files/test-
|
485
|
-
- spec/test-files/test-
|
486
|
-
- spec/test-files/test-
|
474
|
+
- spec/test-files/test-2-normalized.json
|
475
|
+
- spec/test-files/test-2-rdf.ttl
|
476
|
+
- spec/test-files/test-3-compacted.json
|
477
|
+
- spec/test-files/test-3-context.json
|
478
|
+
- spec/test-files/test-3-expanded.json
|
479
|
+
- spec/test-files/test-3-input.json
|
480
|
+
- spec/test-files/test-3-normalized.json
|
481
|
+
- spec/test-files/test-3-rdf.ttl
|
482
|
+
- spec/test-files/test-4-compacted.json
|
487
483
|
- spec/test-files/test-4-context.json
|
484
|
+
- spec/test-files/test-4-expanded.json
|
488
485
|
- spec/test-files/test-4-input.json
|
489
|
-
- spec/test-files/test-
|
490
|
-
- spec/test-files/test-5-
|
491
|
-
- spec/test-files/test-
|
492
|
-
- spec/test-files/test-9-input.json
|
493
|
-
- spec/test-files/test-8-framed.json
|
486
|
+
- spec/test-files/test-4-rdf.ttl
|
487
|
+
- spec/test-files/test-5-compacted.json
|
488
|
+
- spec/test-files/test-5-context.json
|
494
489
|
- spec/test-files/test-5-expanded.json
|
495
|
-
- spec/test-files/test-
|
496
|
-
- spec/test-files/test-
|
490
|
+
- spec/test-files/test-5-input.json
|
491
|
+
- spec/test-files/test-5-rdf.ttl
|
492
|
+
- spec/test-files/test-6-compacted.json
|
493
|
+
- spec/test-files/test-6-context.json
|
497
494
|
- spec/test-files/test-6-expanded.json
|
498
|
-
- spec/test-files/test-2-context.json
|
499
|
-
- spec/test-files/test-5-context.json
|
500
|
-
- spec/test-files/test-1-input.json
|
501
|
-
- spec/test-files/test-4-rdf.ttl
|
502
|
-
- spec/test-files/test-8-frame.json
|
503
495
|
- spec/test-files/test-6-input.json
|
504
|
-
- spec/test-files/test-8-context.json
|
505
|
-
- spec/test-files/test-8-expanded.json
|
506
496
|
- spec/test-files/test-6-rdf.ttl
|
497
|
+
- spec/test-files/test-7-compacted.json
|
498
|
+
- spec/test-files/test-7-context.json
|
499
|
+
- spec/test-files/test-7-expanded.json
|
500
|
+
- spec/test-files/test-7-input.json
|
507
501
|
- spec/test-files/test-7-rdf.ttl
|
508
|
-
- spec/test-files/test-
|
509
|
-
- spec/test-files/test-
|
502
|
+
- spec/test-files/test-8-compacted.json
|
503
|
+
- spec/test-files/test-8-context.json
|
504
|
+
- spec/test-files/test-8-expanded.json
|
505
|
+
- spec/test-files/test-8-frame.json
|
506
|
+
- spec/test-files/test-8-framed.json
|
507
|
+
- spec/test-files/test-8-input.json
|
508
|
+
- spec/test-files/test-8-rdf.ttl
|
509
|
+
- spec/test-files/test-9-compacted.json
|
510
510
|
- spec/test-files/test-9-context.json
|
511
|
+
- spec/test-files/test-9-expanded.json
|
512
|
+
- spec/test-files/test-9-input.json
|