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,76 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD::Resource do
5
- subject {JSON::LD::Resource.new({'@id' => '_:foo', "http://schema.org/name" => "foo"})}
6
- describe "#initialize" do
7
- specify {expect(subject).not_to be_nil}
8
- specify {expect(subject).to be_a(JSON::LD::Resource)}
9
- specify {expect(subject).not_to be_clean}
10
- specify {expect(subject).to be_anonymous}
11
- specify {expect(subject).to be_dirty}
12
- specify {expect(subject).to be_new}
13
- specify {expect(subject).not_to be_resolved}
14
- specify {expect(subject).not_to be_stub}
15
- context "schema:name property" do
16
- specify {expect(subject.property("http://schema.org/name")).to eq "foo"}
17
- end
18
-
19
- describe "compacted with context" do
20
- subject {JSON::LD::Resource.new({'@id' => '_:foo', "http://schema.org/name" => "foo"}, compact: true, context: {"@vocab" => "http://schema.org/"})}
21
- specify {expect(subject).not_to be_nil}
22
- specify {expect(subject).to be_a(JSON::LD::Resource)}
23
- specify {expect(subject).not_to be_clean}
24
- specify {expect(subject).to be_anonymous}
25
- specify {expect(subject).to be_dirty}
26
- specify {expect(subject).to be_new}
27
- specify {expect(subject).not_to be_resolved}
28
- specify {expect(subject).not_to be_stub}
29
- its(:name) {should eq "foo"}
30
- end
31
- end
32
-
33
- describe "#deresolve" do
34
- it "FIXME"
35
- end
36
-
37
- describe "#resolve" do
38
- it "FIXME"
39
- end
40
-
41
- describe "#hash" do
42
- specify {expect(subject.hash).to be_a(Integer)}
43
-
44
- it "returns the hash of the attributes" do
45
- expect(subject.hash).to eq subject.deresolve.hash
46
- end
47
- end
48
-
49
- describe "#to_json" do
50
- it "has JSON" do
51
- expect(subject.to_json).to be_a(String)
52
- expect(JSON.parse(subject.to_json)).to be_a(Hash)
53
- end
54
- it "has same ID" do
55
- expect(JSON.parse(subject.to_json)['@id']).to eq subject.id
56
- end
57
- end
58
-
59
- describe "#each" do
60
- specify {expect {|b| subject.each(&b)}.to yield_with_args(subject.statements.first)}
61
- end
62
-
63
- describe RDF::Enumerable do
64
- specify {expect(subject).to be_enumerable}
65
-
66
- it "initializes a graph" do
67
- g = RDF::Graph.new << subject
68
- expect(g.count).to eq 1
69
- expect(g.objects.first).to eq "foo"
70
- end
71
- end
72
-
73
- describe "#save" do
74
- specify {expect {subject.save}.to raise_error(NotImplementedError)}
75
- end
76
- end
data/spec/spec_helper.rb DELETED
@@ -1,281 +0,0 @@
1
- $:.unshift(File.join("../../lib", __FILE__))
2
- $:.unshift File.dirname(__FILE__)
3
-
4
- require "bundler/setup"
5
- require 'rspec'
6
- require 'rdf'
7
- require 'rdf/isomorphic'
8
- require 'rdf/nquads'
9
- require 'rdf/turtle'
10
- require 'rdf/trig'
11
- require 'rdf/vocab'
12
- require 'rdf/spec'
13
- require 'rdf/spec/matchers'
14
- require_relative 'matchers'
15
- require 'yaml'
16
- begin
17
- require 'simplecov'
18
- require 'simplecov-lcov'
19
- SimpleCov::Formatter::LcovFormatter.config do |config|
20
- #Coveralls is coverage by default/lcov. Send info results
21
- config.report_with_single_file = true
22
- config.single_report_path = 'coverage/lcov.info'
23
- end
24
-
25
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
26
- SimpleCov::Formatter::HTMLFormatter,
27
- SimpleCov::Formatter::LcovFormatter
28
- ])
29
- SimpleCov.start do
30
- add_filter "/spec/"
31
- end
32
- rescue LoadError
33
- end
34
-
35
- require 'json/ld'
36
-
37
- JSON_STATE = JSON::State.new(
38
- indent: " ",
39
- space: " ",
40
- space_before: "",
41
- object_nl: "\n",
42
- array_nl: "\n"
43
- )
44
-
45
- require 'webmock'
46
- WebMock.disable_net_connect!
47
-
48
- # Create and maintain a cache of downloaded URIs
49
- URI_CACHE = File.expand_path(File.join(File.dirname(__FILE__), "uri-cache"))
50
- Dir.mkdir(URI_CACHE) unless File.directory?(URI_CACHE)
51
- # Cache client requests
52
-
53
- ::RSpec.configure do |c|
54
- c.filter_run focus: true
55
- c.run_all_when_everything_filtered = true
56
- c.include(RDF::Spec::Matchers)
57
- end
58
-
59
- # Heuristically detect the input stream
60
- def detect_format(stream)
61
- # Got to look into the file to see
62
- if stream.respond_to?(:rewind) && stream.respond_to?(:read)
63
- stream.rewind
64
- string = stream.read(1000)
65
- stream.rewind
66
- else
67
- string = stream.to_s
68
- end
69
- case string
70
- when /<html/i then RDF::RDFa::Reader
71
- when /\{\s*\"@\"/i then JSON::LD::Reader
72
- else RDF::Turtle::Reader
73
- end
74
- end
75
-
76
- # Creates a bijection between the two objects and replaces nodes in actual from expected.
77
- def remap_bnodes(actual, expected)
78
- # Transform each to RDF and perform a blank node bijection.
79
- # Replace the blank nodes in action with the mapping from bijection.
80
- ds_actual = RDF::Repository.new << JSON::LD::API.toRdf(actual, rdfstar: true, rename_bnodes: false)
81
- ds_expected = RDF::Repository.new << JSON::LD::API.toRdf(expected, rdfstar: true, rename_bnodes: false)
82
- if bijection = ds_actual.bijection_to(ds_expected)
83
- bijection = bijection.inject({}) {|memo, (k, v)| memo.merge(k.to_s => v.to_s)}
84
-
85
- # Recursively replace blank nodes in actual with the bijection
86
- replace_nodes(actual, bijection)
87
- else
88
- actual
89
- end
90
- end
91
-
92
- def replace_nodes(object, bijection)
93
- case object
94
- when Array
95
- object.map {|o| replace_nodes(o, bijection)}
96
- when Hash
97
- object.inject({}) do |memo, (k, v)|
98
- memo.merge(bijection.fetch(k, k) => replace_nodes(v, bijection))
99
- end
100
- when String
101
- bijection.fetch(object, object)
102
- else
103
- object
104
- end
105
- end
106
-
107
-
108
- LIBRARY_INPUT = JSON.parse(%([
109
- {
110
- "@id": "http://example.org/library",
111
- "@type": "http://example.org/vocab#Library",
112
- "http://example.org/vocab#contains": {"@id": "http://example.org/library/the-republic"}
113
- }, {
114
- "@id": "http://example.org/library/the-republic",
115
- "@type": "http://example.org/vocab#Book",
116
- "http://purl.org/dc/elements/1.1/creator": "Plato",
117
- "http://purl.org/dc/elements/1.1/title": "The Republic",
118
- "http://example.org/vocab#contains": {
119
- "@id": "http://example.org/library/the-republic#introduction",
120
- "@type": "http://example.org/vocab#Chapter",
121
- "http://purl.org/dc/elements/1.1/description": "An introductory chapter on The Republic.",
122
- "http://purl.org/dc/elements/1.1/title": "The Introduction"
123
- }
124
- }
125
- ]))
126
-
127
- LIBRARY_EXPANDED = JSON.parse(%([
128
- {
129
- "@id": "http://example.org/library",
130
- "@type": ["http://example.org/vocab#Library"],
131
- "http://example.org/vocab#contains": [{"@id": "http://example.org/library/the-republic"}]
132
- }, {
133
- "@id": "http://example.org/library/the-republic",
134
- "@type": ["http://example.org/vocab#Book"],
135
- "http://purl.org/dc/elements/1.1/creator": [{"@value": "Plato"}],
136
- "http://purl.org/dc/elements/1.1/title": [{"@value": "The Republic"}],
137
- "http://example.org/vocab#contains": [{
138
- "@id": "http://example.org/library/the-republic#introduction",
139
- "@type": ["http://example.org/vocab#Chapter"],
140
- "http://purl.org/dc/elements/1.1/description": [{"@value": "An introductory chapter on The Republic."}],
141
- "http://purl.org/dc/elements/1.1/title": [{"@value": "The Introduction"}]
142
- }]
143
- }
144
- ]))
145
-
146
- LIBRARY_COMPACTED_DEFAULT = JSON.parse(%({
147
- "@context": "http://schema.org",
148
- "@graph": [
149
- {
150
- "id": "http://example.org/library",
151
- "type": "http://example.org/vocab#Library",
152
- "http://example.org/vocab#contains": {"id": "http://example.org/library/the-republic"}
153
- }, {
154
- "id": "http://example.org/library/the-republic",
155
- "type": "http://example.org/vocab#Book",
156
- "http://purl.org/dc/elements/1.1/creator": "Plato",
157
- "http://purl.org/dc/elements/1.1/title": "The Republic",
158
- "http://example.org/vocab#contains": {
159
- "id": "http://example.org/library/the-republic#introduction",
160
- "type": "http://example.org/vocab#Chapter",
161
- "http://purl.org/dc/elements/1.1/description": "An introductory chapter on The Republic.",
162
- "http://purl.org/dc/elements/1.1/title": "The Introduction"
163
- }
164
- }
165
- ]
166
- }))
167
-
168
- LIBRARY_COMPACTED = JSON.parse(%({
169
- "@context": "http://conneg.example.com/context",
170
- "@graph": [
171
- {
172
- "@id": "http://example.org/library",
173
- "@type": "ex:Library",
174
- "ex:contains": {
175
- "@id": "http://example.org/library/the-republic"
176
- }
177
- },
178
- {
179
- "@id": "http://example.org/library/the-republic",
180
- "@type": "ex:Book",
181
- "dc:creator": "Plato",
182
- "dc:title": "The Republic",
183
- "ex:contains": {
184
- "@id": "http://example.org/library/the-republic#introduction",
185
- "@type": "ex:Chapter",
186
- "dc:description": "An introductory chapter on The Republic.",
187
- "dc:title": "The Introduction"
188
- }
189
- }
190
- ]
191
- }))
192
-
193
- LIBRARY_FLATTENED_EXPANDED = JSON.parse(%([
194
- {
195
- "@id": "http://example.org/library",
196
- "@type": ["http://example.org/vocab#Library"],
197
- "http://example.org/vocab#contains": [{"@id": "http://example.org/library/the-republic"}]
198
- },
199
- {
200
- "@id": "http://example.org/library/the-republic",
201
- "@type": ["http://example.org/vocab#Book"],
202
- "http://purl.org/dc/elements/1.1/creator": [{"@value": "Plato"}],
203
- "http://purl.org/dc/elements/1.1/title": [{"@value": "The Republic"}],
204
- "http://example.org/vocab#contains": [{"@id": "http://example.org/library/the-republic#introduction"}]
205
- },
206
- {
207
- "@id": "http://example.org/library/the-republic#introduction",
208
- "@type": ["http://example.org/vocab#Chapter"],
209
- "http://purl.org/dc/elements/1.1/description": [{"@value": "An introductory chapter on The Republic."}],
210
- "http://purl.org/dc/elements/1.1/title": [{"@value": "The Introduction"}]
211
- }
212
- ]))
213
-
214
- LIBRARY_FLATTENED_COMPACTED_DEFAULT = JSON.parse(%({
215
- "@context": "http://schema.org",
216
- "@graph": [
217
- {
218
- "id": "http://example.org/library",
219
- "type": "http://example.org/vocab#Library",
220
- "http://example.org/vocab#contains": {"id": "http://example.org/library/the-republic"}
221
- },
222
- {
223
- "id": "http://example.org/library/the-republic",
224
- "type": "http://example.org/vocab#Book",
225
- "http://purl.org/dc/elements/1.1/creator": "Plato",
226
- "http://purl.org/dc/elements/1.1/title": "The Republic",
227
- "http://example.org/vocab#contains": {"id": "http://example.org/library/the-republic#introduction"}
228
- },
229
- {
230
- "id": "http://example.org/library/the-republic#introduction",
231
- "type": "http://example.org/vocab#Chapter",
232
- "http://purl.org/dc/elements/1.1/description": "An introductory chapter on The Republic.",
233
- "http://purl.org/dc/elements/1.1/title": "The Introduction"
234
- }
235
- ]
236
- }))
237
-
238
- LIBRARY_FLATTENED_COMPACTED = JSON.parse(%({
239
- "@context": "http://conneg.example.com/context",
240
- "@graph": [
241
- {
242
- "@id": "http://example.org/library",
243
- "@type": "ex:Library",
244
- "ex:contains": {"@id": "http://example.org/library/the-republic"}
245
- },
246
- {
247
- "@id": "http://example.org/library/the-republic",
248
- "@type": "ex:Book",
249
- "dc:creator": "Plato",
250
- "dc:title": "The Republic",
251
- "ex:contains": {"@id": "http://example.org/library/the-republic#introduction"}
252
- },
253
- {
254
- "@id": "http://example.org/library/the-republic#introduction",
255
- "@type": "ex:Chapter",
256
- "dc:description": "An introductory chapter on The Republic.",
257
- "dc:title": "The Introduction"
258
- }
259
- ]
260
- }))
261
-
262
- LIBRARY_FRAMED = JSON.parse(%({
263
- "@context": {
264
- "dc": "http://purl.org/dc/elements/1.1/",
265
- "ex": "http://example.org/vocab#"
266
- },
267
- "@id": "http://example.org/library",
268
- "@type": "ex:Library",
269
- "ex:contains": {
270
- "@id": "http://example.org/library/the-republic",
271
- "@type": "ex:Book",
272
- "dc:creator": "Plato",
273
- "dc:title": "The Republic",
274
- "ex:contains": {
275
- "@id": "http://example.org/library/the-republic#introduction",
276
- "@type": "ex:Chapter",
277
- "dc:description": "An introductory chapter on The Republic.",
278
- "dc:title": "The Introduction"
279
- }
280
- }
281
- }))
@@ -1,237 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
- require 'rdf/spec/reader'
4
-
5
- describe JSON::LD::Reader do
6
- let!(:doap) {File.expand_path("../../etc/doap.jsonld", __FILE__)}
7
- let!(:doap_nt) {File.expand_path("../../etc/doap.nt", __FILE__)}
8
- let!(:doap_count) {File.open(doap_nt).each_line.to_a.length}
9
- let(:logger) {RDF::Spec.logger}
10
-
11
- after(:each) {|example| puts logger.to_s if example.exception}
12
-
13
- it_behaves_like 'an RDF::Reader' do
14
- let(:reader_input) {File.read(doap)}
15
- let(:reader) {JSON::LD::Reader.new(reader_input, stream: true)}
16
- let(:reader_count) {doap_count}
17
- end
18
-
19
- context "when validating", pending: ("JRuby support for jsonlint" if RUBY_ENGINE == "jruby") do
20
- it "detects invalid JSON" do
21
- expect do |b|
22
- described_class.new(StringIO.new(%({"a": "b", "a": "c"})), validate: true, logger: false).each_statement(&b)
23
- end.to raise_error(RDF::ReaderError)
24
- end
25
- end
26
-
27
- context :interface do
28
- {
29
- plain: %q({
30
- "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
31
- "@type": "foaf:Person",
32
- "@id": "_:bnode1",
33
- "foaf:homepage": "http://example.com/bob/",
34
- "foaf:name": "Bob"
35
- }),
36
- leading_comment: %q(
37
- // A comment before content
38
- {
39
- "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
40
- "@type": "foaf:Person",
41
- "@id": "_:bnode1",
42
- "foaf:homepage": "http://example.com/bob/",
43
- "foaf:name": "Bob"
44
- }),
45
- script: %q(<script type="application/ld+json">
46
- {
47
- "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
48
- "@type": "foaf:Person",
49
- "@id": "_:bnode1",
50
- "foaf:homepage": "http://example.com/bob/",
51
- "foaf:name": "Bob"
52
- }
53
- </script>),
54
- script_comments: %q(<script type="application/ld+json">
55
- // A comment before content
56
- {
57
- "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
58
- "@type": "foaf:Person",
59
- "@id": "_:bnode1",
60
- "foaf:homepage": "http://example.com/bob/",
61
- "foaf:name": "Bob"
62
- }
63
- </script>),
64
- }.each do |variant, src|
65
- context variant do
66
- subject {src}
67
-
68
- describe "#initialize" do
69
- it "yields reader given string" do
70
- inner = double("inner")
71
- expect(inner).to receive(:called).with(JSON::LD::Reader)
72
- JSON::LD::Reader.new(subject, stream: true) do |reader|
73
- inner.called(reader.class)
74
- end
75
- end
76
-
77
- it "yields reader given IO" do
78
- inner = double("inner")
79
- expect(inner).to receive(:called).with(JSON::LD::Reader)
80
- JSON::LD::Reader.new(StringIO.new(subject), stream: true) do |reader|
81
- inner.called(reader.class)
82
- end
83
- end
84
-
85
- it "returns reader" do
86
- expect(JSON::LD::Reader.new(subject, stream: true)).to be_a(JSON::LD::Reader)
87
- end
88
- end
89
-
90
- describe "#each_statement" do
91
- it "yields statements" do
92
- inner = double("inner")
93
- expect(inner).to receive(:called).with(RDF::Statement).exactly(3)
94
- JSON::LD::Reader.new(subject, stream: true).each_statement do |statement|
95
- inner.called(statement.class)
96
- end
97
- end
98
- end
99
-
100
- describe "#each_triple" do
101
- it "yields statements" do
102
- inner = double("inner")
103
- expect(inner).to receive(:called).exactly(3)
104
- JSON::LD::Reader.new(subject, stream: true).each_triple do |subject, predicate, object|
105
- inner.called(subject.class, predicate.class, object.class)
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
112
-
113
- context "Selected toRdf tests" do
114
- {
115
- "e004": {
116
- input: %({
117
- "@context": {
118
- "mylist1": {"@id": "http://example.com/mylist1", "@container": "@list"}
119
- },
120
- "@id": "http://example.org/id",
121
- "mylist1": { "@list": [ ] },
122
- "http://example.org/list1": { "@list": [ null ] },
123
- "http://example.org/list2": { "@list": [ {"@value": null} ] }
124
- }),
125
- expect: %(
126
- <http://example.org/id> <http://example.com/mylist1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
127
- <http://example.org/id> <http://example.org/list1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
128
- <http://example.org/id> <http://example.org/list2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
129
- )
130
- },
131
- "e015": {
132
- input: %({
133
- "@context": {
134
- "myset2": {"@id": "http://example.com/myset2", "@container": "@set" }
135
- },
136
- "@id": "http://example.org/id",
137
- "myset2": [ [], { "@set": [ null ] }, [ null ] ]
138
- }),
139
- expect: %(
140
- )
141
- },
142
- "in06": {
143
- input: %({
144
- "@context": {
145
- "@version": 1.1,
146
- "@vocab": "http://example.org/vocab#",
147
- "@base": "http://example.org/base/",
148
- "id": "@id",
149
- "type": "@type",
150
- "data": "@nest",
151
- "links": "@nest",
152
- "relationships": "@nest",
153
- "self": {"@type": "@id"},
154
- "related": {"@type": "@id"}
155
- },
156
- "data": [{
157
- "type": "articles",
158
- "id": "1",
159
- "author": {
160
- "data": { "type": "people", "id": "9" }
161
- }
162
- }]
163
- }),
164
- expect: %(
165
- <http://example.org/base/1> <http://example.org/vocab#author> <http://example.org/base/9> .
166
- <http://example.org/base/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#articles> .
167
- <http://example.org/base/9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#people> .
168
- ),
169
- pending: "@nest defining @id"
170
- }
171
- }.each do |name, params|
172
- it name do
173
- run_to_rdf params
174
- end
175
- end
176
- end
177
-
178
- describe "test suite" do
179
- require_relative 'suite_helper'
180
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::STREAM_SUITE}stream-toRdf-manifest.jsonld")
181
- describe m.name do
182
- m.entries.each do |t|
183
- specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
184
- pending "Generalized RDF" if t.options[:produceGeneralizedRdf]
185
- pending "@nest defining @id" if %w(#tin06).include?(t.property('@id'))
186
- pending "double @reverse" if %w(#te043).include?(t.property('@id'))
187
- pending "graph map containing named graph" if %w(#te084 #te087 #te098 #te101 #te105 #te106).include?(t.property('@id'))
188
- pending "named graphs" if %w(#t0029 #te021).include?(t.property('@id'))
189
-
190
- if %w(#t0118).include?(t.property('@id'))
191
- expect {t.run self}.to write(/Statement .* is invalid/).to(:error)
192
- elsif %w(#twf07).include?(t.property('@id'))
193
- expect {t.run self}.to write(/skipping graph statement within invalid graph name/).to(:error)
194
- elsif %w(#te075).include?(t.property('@id'))
195
- expect {t.run self}.to write(/is invalid/).to(:error)
196
- elsif %w(#te005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #te119 #te120).include?(t.property('@id'))
197
- expect {t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
198
- elsif %w(#te068).include?(t.property('@id'))
199
- expect {t.run self}.to write("[DEPRECATION]").to(:error)
200
- elsif %w(#twf05).include?(t.property('@id'))
201
- expect {t.run self}.to write("@language must be valid BCP47").to(:error)
202
- else
203
- expect {t.run self}.not_to write.to(:error)
204
- end
205
- end
206
- end
207
- end
208
- end unless ENV['CI']
209
-
210
- def run_to_rdf(params)
211
- input = params[:input]
212
- logger.info("input: #{input}")
213
- output = RDF::Repository.new
214
- if params[:expect]
215
- RDF::NQuads::Reader.new(params[:expect], validate: false) {|r| output << r}
216
- logger.info("expect (quads): #{output.dump(:nquads, validate: false)}")
217
- else
218
- logger.info("expect: #{Regexp.new params[:exception]}")
219
- end
220
-
221
- graph = params[:graph] || RDF::Repository.new
222
- pending params.fetch(:pending, "test implementation") if !input || params[:pending]
223
- if params[:exception]
224
- expect do |b|
225
- JSON::LD::Reader.new(input, stream: true, validate: true, logger: false, **params).each_statement(&b)
226
- end.to raise_error {|er| expect(er.message).to include params[:exception]}
227
- else
228
- if params[:write]
229
- expect{JSON::LD::Reader.new(input, stream: true, logger: logger, **params) {|st| graph << st}}.to write(params[:write]).to(:error)
230
- else
231
- expect{JSON::LD::Reader.new(input, stream: true, logger: logger, **params) {|st| graph << st}}.not_to write.to(:error)
232
- end
233
- logger.info("results (quads): #{graph.dump(:nquads, validate: false)}")
234
- expect(graph).to be_equivalent_graph(output, logger: logger, inputDocument: input)
235
- end
236
- end
237
- end