json-ld 3.2.4 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/json/ld/api.rb +807 -771
  4. data/lib/json/ld/compact.rb +304 -304
  5. data/lib/json/ld/conneg.rb +179 -161
  6. data/lib/json/ld/context.rb +2080 -1913
  7. data/lib/json/ld/expand.rb +745 -666
  8. data/lib/json/ld/extensions.rb +14 -13
  9. data/lib/json/ld/flatten.rb +257 -247
  10. data/lib/json/ld/format.rb +202 -194
  11. data/lib/json/ld/frame.rb +525 -502
  12. data/lib/json/ld/from_rdf.rb +223 -204
  13. data/lib/json/ld/html/nokogiri.rb +123 -121
  14. data/lib/json/ld/html/rexml.rb +151 -147
  15. data/lib/json/ld/reader.rb +107 -100
  16. data/lib/json/ld/resource.rb +224 -205
  17. data/lib/json/ld/streaming_reader.rb +574 -507
  18. data/lib/json/ld/streaming_writer.rb +93 -92
  19. data/lib/json/ld/to_rdf.rb +171 -169
  20. data/lib/json/ld/utils.rb +270 -264
  21. data/lib/json/ld/version.rb +24 -14
  22. data/lib/json/ld/writer.rb +334 -311
  23. data/lib/json/ld.rb +103 -96
  24. metadata +55 -198
  25. data/spec/api_spec.rb +0 -132
  26. data/spec/compact_spec.rb +0 -3482
  27. data/spec/conneg_spec.rb +0 -373
  28. data/spec/context_spec.rb +0 -2056
  29. data/spec/expand_spec.rb +0 -4496
  30. data/spec/flatten_spec.rb +0 -1203
  31. data/spec/format_spec.rb +0 -115
  32. data/spec/frame_spec.rb +0 -2541
  33. data/spec/from_rdf_spec.rb +0 -1072
  34. data/spec/matchers.rb +0 -20
  35. data/spec/rdfstar_spec.rb +0 -25
  36. data/spec/reader_spec.rb +0 -883
  37. data/spec/resource_spec.rb +0 -76
  38. data/spec/spec_helper.rb +0 -281
  39. data/spec/streaming_reader_spec.rb +0 -237
  40. data/spec/streaming_writer_spec.rb +0 -145
  41. data/spec/suite_compact_spec.rb +0 -22
  42. data/spec/suite_expand_spec.rb +0 -36
  43. data/spec/suite_flatten_spec.rb +0 -34
  44. data/spec/suite_frame_spec.rb +0 -29
  45. data/spec/suite_from_rdf_spec.rb +0 -22
  46. data/spec/suite_helper.rb +0 -411
  47. data/spec/suite_html_spec.rb +0 -22
  48. data/spec/suite_http_spec.rb +0 -35
  49. data/spec/suite_remote_doc_spec.rb +0 -22
  50. data/spec/suite_to_rdf_spec.rb +0 -30
  51. data/spec/support/extensions.rb +0 -44
  52. data/spec/test-files/test-1-compacted.jsonld +0 -10
  53. data/spec/test-files/test-1-context.jsonld +0 -7
  54. data/spec/test-files/test-1-expanded.jsonld +0 -5
  55. data/spec/test-files/test-1-input.jsonld +0 -10
  56. data/spec/test-files/test-1-rdf.ttl +0 -8
  57. data/spec/test-files/test-2-compacted.jsonld +0 -20
  58. data/spec/test-files/test-2-context.jsonld +0 -7
  59. data/spec/test-files/test-2-expanded.jsonld +0 -16
  60. data/spec/test-files/test-2-input.jsonld +0 -20
  61. data/spec/test-files/test-2-rdf.ttl +0 -14
  62. data/spec/test-files/test-3-compacted.jsonld +0 -11
  63. data/spec/test-files/test-3-context.jsonld +0 -8
  64. data/spec/test-files/test-3-expanded.jsonld +0 -10
  65. data/spec/test-files/test-3-input.jsonld +0 -11
  66. data/spec/test-files/test-3-rdf.ttl +0 -8
  67. data/spec/test-files/test-4-compacted.jsonld +0 -10
  68. data/spec/test-files/test-4-context.jsonld +0 -7
  69. data/spec/test-files/test-4-expanded.jsonld +0 -6
  70. data/spec/test-files/test-4-input.jsonld +0 -10
  71. data/spec/test-files/test-4-rdf.ttl +0 -5
  72. data/spec/test-files/test-5-compacted.jsonld +0 -13
  73. data/spec/test-files/test-5-context.jsonld +0 -7
  74. data/spec/test-files/test-5-expanded.jsonld +0 -9
  75. data/spec/test-files/test-5-input.jsonld +0 -13
  76. data/spec/test-files/test-5-rdf.ttl +0 -7
  77. data/spec/test-files/test-6-compacted.jsonld +0 -10
  78. data/spec/test-files/test-6-context.jsonld +0 -7
  79. data/spec/test-files/test-6-expanded.jsonld +0 -10
  80. data/spec/test-files/test-6-input.jsonld +0 -10
  81. data/spec/test-files/test-6-rdf.ttl +0 -6
  82. data/spec/test-files/test-7-compacted.jsonld +0 -23
  83. data/spec/test-files/test-7-context.jsonld +0 -4
  84. data/spec/test-files/test-7-expanded.jsonld +0 -20
  85. data/spec/test-files/test-7-input.jsonld +0 -23
  86. data/spec/test-files/test-7-rdf.ttl +0 -14
  87. data/spec/test-files/test-8-compacted.jsonld +0 -34
  88. data/spec/test-files/test-8-context.jsonld +0 -11
  89. data/spec/test-files/test-8-expanded.jsonld +0 -24
  90. data/spec/test-files/test-8-frame.jsonld +0 -18
  91. data/spec/test-files/test-8-framed.jsonld +0 -25
  92. data/spec/test-files/test-8-input.jsonld +0 -30
  93. data/spec/test-files/test-8-rdf.ttl +0 -15
  94. data/spec/test-files/test-9-compacted.jsonld +0 -20
  95. data/spec/test-files/test-9-context.jsonld +0 -13
  96. data/spec/test-files/test-9-expanded.jsonld +0 -14
  97. data/spec/test-files/test-9-input.jsonld +0 -12
  98. data/spec/to_rdf_spec.rb +0 -1684
  99. data/spec/writer_spec.rb +0 -427
data/spec/conneg_spec.rb DELETED
@@ -1,373 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
- require 'rack/linkeddata'
4
- require 'rack/test'
5
-
6
- describe JSON::LD::ContentNegotiation do
7
- include ::Rack::Test::Methods
8
- let(:logger) {RDF::Spec.logger}
9
-
10
- let(:app) do
11
- described_class.new(double("Target Rack Application", :call => [200, {}, @results || "A String"]))
12
- end
13
-
14
- describe "#parse_accept_header" do
15
- {
16
- "application/n-triples, application/ld+json;q=0.5" => %w(application/ld+json),
17
- "application/ld+json, application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted" =>
18
- %w(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted application/ld+json),
19
- }.each do |accept, content_types|
20
- it "returns #{content_types.inspect} given #{accept.inspect}" do
21
- expect(app.send(:parse_accept_header, accept)).to eq content_types
22
- end
23
- end
24
- end
25
-
26
- describe "#find_content_type_for_media_range" do
27
- {
28
- "*/*" => "application/ld+json",
29
- "application/*" => "application/ld+json",
30
- "application/json" => "application/ld+json",
31
- "application/json;profile=http://www.w3.org/ns/json-ld#compacted" =>
32
- "application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted",
33
- "text/plain" => nil
34
- }.each do |media_range, content_type|
35
- it "returns #{content_type.inspect} for #{media_range.inspect}" do
36
- expect(app.send(:find_content_type_for_media_range, media_range)).to eq content_type
37
- end
38
- end
39
- end
40
-
41
- describe "#call" do
42
- let(:schema_context) {
43
- JSON::LD::API::RemoteDocument.new(%q({
44
- "@context": {
45
- "@vocab": "http://schema.org/",
46
- "id": "@id",
47
- "type": "@type"
48
- }
49
- }), documentUrl: "http://schema.org")
50
- }
51
- let(:frame) {
52
- JSON::LD::API::RemoteDocument.new(%q({
53
- "@context": {
54
- "dc": "http://purl.org/dc/elements/1.1/",
55
- "ex": "http://example.org/vocab#"
56
- },
57
- "@type": "ex:Library",
58
- "ex:contains": {
59
- "@type": "ex:Book",
60
- "ex:contains": {
61
- "@type": "ex:Chapter"
62
- }
63
- }
64
- }), documentUrl: "http://conneg.example.com/frame")
65
- }
66
- let(:context) {
67
- JSON::LD::API::RemoteDocument.new(%q({
68
- "@context": {
69
- "dc": "http://purl.org/dc/elements/1.1/",
70
- "ex": "http://example.org/vocab#"
71
- }
72
- }), documentUrl: "http://conneg.example.com/context")
73
- }
74
-
75
- before(:each) do
76
- allow(JSON::LD::API).to receive(:documentLoader).with("http://schema.org", any_args).and_yield(schema_context)
77
- allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/context", any_args).and_yield(context)
78
- allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/frame", any_args).and_yield(frame)
79
- end
80
-
81
- context "with text result" do
82
- it "returns text unchanged" do
83
- get '/'
84
- expect(last_response.body).to eq 'A String'
85
- end
86
- end
87
-
88
- context "with object result" do
89
- before(:each) do
90
- @results = LIBRARY_INPUT
91
- end
92
-
93
- it "returns expanded result" do
94
- get '/'
95
- expect(JSON.parse(last_response.body)).to produce_jsonld(LIBRARY_INPUT, logger)
96
- end
97
-
98
- context "with Accept" do
99
- {
100
- "application/n-triples" => "406 Not Acceptable (No appropriate combinaion of media-type and parameters found)\n",
101
- "application/json" => LIBRARY_INPUT,
102
- "application/ld+json" => LIBRARY_INPUT,
103
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#expanded) =>
104
- LIBRARY_EXPANDED,
105
-
106
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted) =>
107
- LIBRARY_COMPACTED_DEFAULT,
108
-
109
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#flattened) =>
110
- LIBRARY_FLATTENED_EXPANDED,
111
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#expanded") =>
112
- LIBRARY_FLATTENED_EXPANDED,
113
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#expanded http://www.w3.org/ns/json-ld#flattened") =>
114
- LIBRARY_FLATTENED_EXPANDED,
115
-
116
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted") =>
117
- LIBRARY_FLATTENED_COMPACTED_DEFAULT,
118
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened") =>
119
- LIBRARY_FLATTENED_COMPACTED_DEFAULT,
120
-
121
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#framed) =>
122
- "406 Not Acceptable (framed profile without a frame)\n",
123
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#framed http://www.w3.org/ns/json-ld#expanded") =>
124
- "406 Not Acceptable (framed profile without a frame)\n",
125
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#expanded http://www.w3.org/ns/json-ld#framed") =>
126
- "406 Not Acceptable (framed profile without a frame)\n",
127
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#framed http://www.w3.org/ns/json-ld#compacted") =>
128
- "406 Not Acceptable (framed profile without a frame)\n",
129
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#framed") =>
130
- "406 Not Acceptable (framed profile without a frame)\n",
131
- }.each do |accepts, result|
132
- context accepts do
133
- before(:each) do
134
- get '/', {}, {"HTTP_ACCEPT" => accepts}
135
- end
136
-
137
- it "status" do
138
- expect(last_response.status).to satisfy("be 200 or 406") {|x| [200, 406].include?(x)}
139
- end
140
-
141
- it "sets content type" do
142
- expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
143
- end
144
-
145
- it "returns serialization" do
146
- if last_response.status == 406
147
- expect(last_response.body).to eq result
148
- else
149
- expect(JSON.parse(last_response.body)).to produce_jsonld(result, logger)
150
- end
151
- end
152
- end
153
- end
154
- end
155
-
156
- context "with Link" do
157
- {
158
- "compacted with context" => {
159
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted),
160
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
161
- result: LIBRARY_COMPACTED
162
- },
163
- "flattened with context" => {
164
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#flattened),
165
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
166
- result: LIBRARY_FLATTENED_COMPACTED
167
- },
168
- "flattened and compacted with context" => {
169
- accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted"),
170
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
171
- result: LIBRARY_FLATTENED_COMPACTED
172
- },
173
- "compacted and flattened with context" => {
174
- accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened"),
175
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
176
- result: LIBRARY_FLATTENED_COMPACTED
177
- },
178
- "framed with frame" => {
179
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#framed),
180
- link: %(<http://conneg.example.com/frame> rel="http://www.w3.org/ns/json-ld#frame"),
181
- result: LIBRARY_FRAMED
182
- },
183
-
184
- "framed with context" => {
185
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#framed),
186
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
187
- result: "406 Not Acceptable (framed profile without a frame)\n"
188
- },
189
- }.each do |name, params|
190
- context name do
191
- before(:each) do
192
- get '/', {}, {"HTTP_ACCEPT" => params[:accept], "HTTP_LINK" => params[:link]}
193
- end
194
-
195
- it "status" do
196
- expect(last_response.status).to satisfy("be 200 or 406") {|x| [200, 406].include?(x)}
197
- end
198
-
199
- it "sets content type" do
200
- expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
201
- end
202
-
203
- it "returns serialization" do
204
- if last_response.status == 406
205
- expect(last_response.body).to eq params[:result]
206
- else
207
- expect(JSON.parse(last_response.body)).to produce_jsonld(params[:result], logger)
208
- end
209
- end
210
- end
211
- end
212
- end
213
- end
214
- end
215
- end
216
-
217
- describe Rack::LinkedData::ContentNegotiation do
218
- include ::Rack::Test::Methods
219
- let(:logger) {RDF::Spec.logger}
220
-
221
- let(:app) do
222
- graph = RDF::NTriples::Reader.new(%(
223
- <http://example.org/library> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Library> .
224
- <http://example.org/library> <http://example.org/vocab#contains> <http://example.org/library/the-republic> .
225
- <http://example.org/library/the-republic> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Book> .
226
- <http://example.org/library/the-republic> <http://purl.org/dc/elements/1.1/title> "The Republic" .
227
- <http://example.org/library/the-republic> <http://purl.org/dc/elements/1.1/creator> "Plato" .
228
- <http://example.org/library/the-republic> <http://example.org/vocab#contains> <http://example.org/library/the-republic#introduction> .
229
- <http://example.org/library/the-republic#introduction> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Chapter> .
230
- <http://example.org/library/the-republic#introduction> <http://purl.org/dc/elements/1.1/title> "The Introduction" .
231
- <http://example.org/library/the-republic#introduction> <http://purl.org/dc/elements/1.1/description> "An introductory chapter on The Republic." .
232
- ))
233
- Rack::LinkedData::ContentNegotiation.new(double("Target Rack Application", :call => [200, {}, graph]), {})
234
- end
235
-
236
- describe "#call" do
237
- let(:schema_context) {
238
- JSON::LD::API::RemoteDocument.new(%q({
239
- "@context": {
240
- "@vocab": "http://schema.org/",
241
- "id": "@id",
242
- "type": "@type"
243
- }
244
- }), documentUrl: "http://schema.org")
245
- }
246
- let(:frame) {
247
- JSON::LD::API::RemoteDocument.new(%q({
248
- "@context": {
249
- "dc": "http://purl.org/dc/elements/1.1/",
250
- "ex": "http://example.org/vocab#"
251
- },
252
- "@type": "ex:Library",
253
- "ex:contains": {
254
- "@type": "ex:Book",
255
- "ex:contains": {
256
- "@type": "ex:Chapter"
257
- }
258
- }
259
- }), documentUrl: "http://conneg.example.com/frame")
260
- }
261
- let(:context) {
262
- JSON::LD::API::RemoteDocument.new(%q({
263
- "@context": {
264
- "dc": "http://purl.org/dc/elements/1.1/",
265
- "ex": "http://example.org/vocab#"
266
- }
267
- }), documentUrl: "http://conneg.example.com/context")
268
- }
269
-
270
- before(:each) do
271
- allow(JSON::LD::API).to receive(:documentLoader).with("http://schema.org", any_args).and_yield(schema_context)
272
- allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/context", any_args).and_yield(context)
273
- allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/frame", any_args).and_yield(frame)
274
- end
275
-
276
- {
277
- "application/json" => LIBRARY_FLATTENED_EXPANDED,
278
- "application/ld+json" => LIBRARY_FLATTENED_EXPANDED,
279
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#expanded) =>
280
- LIBRARY_FLATTENED_EXPANDED,
281
-
282
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted) =>
283
- LIBRARY_FLATTENED_COMPACTED_DEFAULT,
284
-
285
- %(application/ld+json;profile=http://www.w3.org/ns/json-ld#flattened) =>
286
- LIBRARY_FLATTENED_EXPANDED,
287
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#expanded") =>
288
- LIBRARY_FLATTENED_EXPANDED,
289
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#expanded http://www.w3.org/ns/json-ld#flattened") =>
290
- LIBRARY_FLATTENED_EXPANDED,
291
-
292
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted") =>
293
- LIBRARY_FLATTENED_COMPACTED_DEFAULT,
294
- %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened") =>
295
- LIBRARY_FLATTENED_COMPACTED_DEFAULT,
296
-
297
- }.each do |accepts, result|
298
- context accepts do
299
- before(:each) do
300
- get '/', {}, {"HTTP_ACCEPT" => accepts}
301
- end
302
-
303
- it "status" do
304
- expect(last_response.status).to satisfy("200 or 406") {|x| [200, 406].include?(x)}
305
- end
306
-
307
- it "sets content type" do
308
- expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
309
- end
310
-
311
- it "returns serialization" do
312
- if last_response.status == 406
313
- expect(last_response.body).to eq result
314
- else
315
- expect(JSON.parse(last_response.body)).to produce_jsonld(result, logger)
316
- end
317
- end
318
- end
319
- end
320
-
321
- context "with Link" do
322
- {
323
- "with context" => {
324
- accept: %(application/ld+json),
325
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
326
- result: LIBRARY_FLATTENED_COMPACTED
327
- },
328
- "compacted with context" => {
329
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted),
330
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
331
- result: LIBRARY_FLATTENED_COMPACTED
332
- },
333
- "flattened and compacted with context" => {
334
- accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted"),
335
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
336
- result: LIBRARY_FLATTENED_COMPACTED
337
- },
338
- "compacted and flattened with context" => {
339
- accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened"),
340
- link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
341
- result: LIBRARY_FLATTENED_COMPACTED
342
- },
343
- "framed with frame" => {
344
- accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#framed),
345
- link: %(<http://conneg.example.com/frame> rel="http://www.w3.org/ns/json-ld#frame"),
346
- result: LIBRARY_FRAMED
347
- },
348
- }.each do |name, params|
349
- context name do
350
- before(:each) do
351
- get '/', {}, {"HTTP_ACCEPT" => params[:accept], "HTTP_LINK" => params[:link]}
352
- end
353
-
354
- it "status" do
355
- expect(last_response.status).to satisfy("be 200 or 406") {|x| [200, 406].include?(x)}
356
- end
357
-
358
- it "sets content type" do
359
- expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
360
- end
361
-
362
- it "returns serialization" do
363
- if last_response.status == 406
364
- expect(last_response.body).to eq params[:result]
365
- else
366
- expect(JSON.parse(last_response.body)).to produce_jsonld(params[:result], logger)
367
- end
368
- end
369
- end
370
- end
371
- end
372
- end
373
- end