json-ld 3.2.3 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -764
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1945
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +224 -166
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -167
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +78 -209
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2036
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2498
- data/spec/from_rdf_spec.rb +0 -1005
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1551
- data/spec/writer_spec.rb +0 -427
@@ -1,145 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
require 'rdf/spec/writer'
|
4
|
-
require 'json/ld/streaming_writer'
|
5
|
-
|
6
|
-
describe JSON::LD::StreamingWriter do
|
7
|
-
let(:logger) {RDF::Spec.logger}
|
8
|
-
|
9
|
-
after(:each) {|example| puts logger.to_s if example.exception}
|
10
|
-
|
11
|
-
it_behaves_like 'an RDF::Writer' do
|
12
|
-
let(:writer) {JSON::LD::Writer.new(StringIO.new(""), stream: true)}
|
13
|
-
end
|
14
|
-
|
15
|
-
context "simple tests" do
|
16
|
-
it "should use full URIs without base" do
|
17
|
-
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
18
|
-
obj = serialize(input)
|
19
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
20
|
-
expect(obj).to produce_jsonld([{
|
21
|
-
'@id' => "http://a/b",
|
22
|
-
"http://a/c" => [{"@id" => "http://a/d"}]
|
23
|
-
}], logger)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "writes multiple kinds of statements" do
|
27
|
-
input = %(
|
28
|
-
<https://senet.org/gm> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://vocab.org/frbr/core#Work> .
|
29
|
-
<https://senet.org/gm> <http://purl.org/dc/terms/title> "Rhythm Paradise"@en .
|
30
|
-
<https://senet.org/gm> <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en .
|
31
|
-
<https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
|
32
|
-
)
|
33
|
-
obj = serialize(input)
|
34
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
35
|
-
expect(obj).to eql JSON.parse(%{[{
|
36
|
-
"@id": "https://senet.org/gm",
|
37
|
-
"@type": ["http://vocab.org/frbr/core#Work"],
|
38
|
-
"http://purl.org/dc/terms/title": [{"@value": "Rhythm Paradise", "@language": "en"}],
|
39
|
-
"https://senet.org/ns#unofficialTitle": [{"@value": "Rhythm Tengoku", "@language": "en"}],
|
40
|
-
"https://senet.org/ns#urlkey": [{"@value": "rhythm-tengoku"}]
|
41
|
-
}]})
|
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/terms/> .
|
48
|
-
<http://example.com/test-cases/0001> a :TestCase .
|
49
|
-
<http://example.com/test-cases/0002> a :TestCase .
|
50
|
-
)
|
51
|
-
obj = serialize(input)
|
52
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
53
|
-
expect(obj).to contain_exactly(*JSON.parse(%{[
|
54
|
-
{"@id": "http://example.com/test-cases/0001", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]},
|
55
|
-
{"@id": "http://example.com/test-cases/0002", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]}
|
56
|
-
]}))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "Named Graphs" do
|
61
|
-
{
|
62
|
-
"default" => [
|
63
|
-
%q({<a> <b> <c> .}),
|
64
|
-
%q([{"@id": "a", "b": [{"@id": "c"}]}])
|
65
|
-
],
|
66
|
-
"named" => [
|
67
|
-
%q(<C> {<a> <b> <c> .}),
|
68
|
-
%q([{"@id" : "C", "@graph" : [{"@id": "a", "b": [{"@id": "c"}]}]}])
|
69
|
-
],
|
70
|
-
"combo" => [
|
71
|
-
%q(
|
72
|
-
<a> <b> <c> .
|
73
|
-
<C> {<A> <b> <c> .}
|
74
|
-
),
|
75
|
-
%q([
|
76
|
-
{"@id": "a", "b": [{"@id": "c"}]},
|
77
|
-
{"@id": "C", "@graph": [{"@id": "A", "b": [{"@id": "c"}]}]}
|
78
|
-
])
|
79
|
-
],
|
80
|
-
"combo with duplicated statement" => [
|
81
|
-
%q(
|
82
|
-
<a> <b> <c> .
|
83
|
-
<C> {<a> <b> <c> .}
|
84
|
-
),
|
85
|
-
%q([
|
86
|
-
{"@id": "a", "b": [{"@id": "c"}]},
|
87
|
-
{"@id": "C", "@graph": [{"@id": "a", "b": [{"@id": "c"}]}]}
|
88
|
-
])
|
89
|
-
],
|
90
|
-
}.each_pair do |title, (input, matches)|
|
91
|
-
context title do
|
92
|
-
subject {serialize(input)}
|
93
|
-
it "matches expected json" do
|
94
|
-
expect(subject).to contain_exactly(*JSON.parse(matches))
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
context "Writes fromRdf tests to isomorphic graph" do
|
102
|
-
require 'suite_helper'
|
103
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
|
104
|
-
[nil, {}].each do |ctx|
|
105
|
-
context "with context #{ctx.inspect}" do
|
106
|
-
describe m.name do
|
107
|
-
m.entries.each do |t|
|
108
|
-
next unless t.positiveTest? && !t.property('input').include?('0016')
|
109
|
-
t.logger = RDF::Spec.logger
|
110
|
-
t.logger.info "test: #{t.inspect}"
|
111
|
-
t.logger.info "source: #{t.input}"
|
112
|
-
specify "#{t.property('@id')}: #{t.name}" do
|
113
|
-
repo = RDF::Repository.load(t.input_loc, format: :nquads)
|
114
|
-
jsonld = JSON::LD::Writer.buffer(stream: true, context: ctx, logger: t.logger, **t.options) do |writer|
|
115
|
-
writer << repo
|
116
|
-
end
|
117
|
-
t.logger.info "Generated: #{jsonld}"
|
118
|
-
|
119
|
-
# And then, re-generate jsonld as RDF
|
120
|
-
expect(parse(jsonld, format: :jsonld, **t.options)).to be_equivalent_graph(repo, t)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end unless ENV['CI']
|
127
|
-
|
128
|
-
def parse(input, format: :trig, **options)
|
129
|
-
reader = RDF::Reader.for(format)
|
130
|
-
RDF::Repository.new << reader.new(input, **options)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Serialize ntstr to a string and compare against regexps
|
134
|
-
def serialize(ntstr, **options)
|
135
|
-
g = ntstr.is_a?(String) ? parse(ntstr, **options) : ntstr
|
136
|
-
logger = RDF::Spec.logger
|
137
|
-
logger.info(g.dump(:ttl))
|
138
|
-
result = JSON::LD::Writer.buffer(logger: logger, stream: true, **options) do |writer|
|
139
|
-
writer << g
|
140
|
-
end
|
141
|
-
puts result if $verbose
|
142
|
-
|
143
|
-
JSON.parse(result)
|
144
|
-
end
|
145
|
-
end
|
data/spec/suite_compact_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}compact-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
11
|
-
t.options[:ordered] = false
|
12
|
-
expect{t.run self}.not_to write.to(:error)
|
13
|
-
end
|
14
|
-
|
15
|
-
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
16
|
-
t.options[:ordered] = true
|
17
|
-
expect {t.run self}.not_to write.to(:error)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end unless ENV['CI']
|
data/spec/suite_expand_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
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
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}expand-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
# MultiJson use OJ, by default, which doesn't handle native numbers the same as the JSON gem.
|
11
|
-
t.options[:adapter] = :json_gem if %w(#tjs12).include?(t.property('@id'))
|
12
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
13
|
-
t.options[:ordered] = false
|
14
|
-
if %w(#t0068).include?(t.property('@id'))
|
15
|
-
expect{t.run self}.to write("[DEPRECATION]").to(:error)
|
16
|
-
elsif %w(#t0005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #t0119 #t0120).include?(t.property('@id'))
|
17
|
-
expect{t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
|
18
|
-
else
|
19
|
-
expect {t.run self}.not_to write.to(:error)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
24
|
-
t.options[:ordered] = true
|
25
|
-
if %w(#t0068).include?(t.property('@id'))
|
26
|
-
expect{t.run self}.to write("[DEPRECATION]").to(:error)
|
27
|
-
elsif %w(#t0005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #t0119 #t0120).include?(t.property('@id'))
|
28
|
-
expect{t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
|
29
|
-
else
|
30
|
-
expect {t.run self}.not_to write.to(:error)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end unless ENV['CI']
|
data/spec/suite_flatten_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
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
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}flatten-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
t.options[:remap_bnodes] = %w(#t0045).include?(t.property('@id'))
|
11
|
-
|
12
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
13
|
-
t.options[:ordered] = false
|
14
|
-
if %w(#t0005).include?(t.property('@id'))
|
15
|
-
expect{t.run self}.to write("Terms beginning with '@' are reserved for future use").to(:error)
|
16
|
-
else
|
17
|
-
expect {t.run self}.not_to write.to(:error)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Skip ordered tests when remapping bnodes
|
22
|
-
next if t.options[:remap_bnodes]
|
23
|
-
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
24
|
-
t.options[:ordered] = true
|
25
|
-
if %w(#t0005).include?(t.property('@id'))
|
26
|
-
expect{t.run self}.to write("Terms beginning with '@' are reserved for future use").to(:error)
|
27
|
-
else
|
28
|
-
expect {t.run self}.not_to write.to(:error)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end unless ENV['CI']
|
data/spec/suite_frame_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
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
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
t.options[:remap_bnodes] = %w(#t0021 #tp021).include?(t.property('@id'))
|
11
|
-
|
12
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
13
|
-
t.options[:ordered] = false
|
14
|
-
expect {t.run self}.not_to write.to(:error)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Skip ordered tests when remapping bnodes
|
18
|
-
next if t.options[:remap_bnodes]
|
19
|
-
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
20
|
-
t.options[:ordered] = true
|
21
|
-
if %w(#tp021).include?(t.property('@id'))
|
22
|
-
pending("changes due to blank node reordering")
|
23
|
-
end
|
24
|
-
expect {t.run self}.not_to write.to(:error)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end unless ENV['CI']
|
data/spec/suite_from_rdf_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
11
|
-
t.options[:ordered] = false
|
12
|
-
expect {t.run self}.not_to write.to(:error)
|
13
|
-
end
|
14
|
-
|
15
|
-
specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
|
16
|
-
t.options[:ordered] = true
|
17
|
-
expect {t.run self}.not_to write.to(:error)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end unless ENV['CI']
|