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
data/spec/suite_helper.rb
DELETED
@@ -1,411 +0,0 @@
|
|
1
|
-
require 'json/ld'
|
2
|
-
|
3
|
-
# For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
|
4
|
-
module RDF::Util
|
5
|
-
module File
|
6
|
-
LOCAL_PATHS = {
|
7
|
-
"https://w3c.github.io/json-ld-api/tests/" => ::File.expand_path("../json-ld-api/tests", __FILE__) + '/',
|
8
|
-
"https://w3c.github.io/json-ld-framing/tests/" => ::File.expand_path("../json-ld-framing/tests", __FILE__) + '/',
|
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__) + '/',
|
11
|
-
"file:" => ""
|
12
|
-
}
|
13
|
-
|
14
|
-
class << self
|
15
|
-
alias_method :original_open_file, :open_file
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Override to use Patron for http and https, Kernel.open otherwise.
|
20
|
-
#
|
21
|
-
# @param [String] filename_or_url to open
|
22
|
-
# @param [Hash{Symbol => Object}] options
|
23
|
-
# @option options [Array, String] :headers
|
24
|
-
# HTTP Request headers.
|
25
|
-
# @return [IO] File stream
|
26
|
-
# @yield [IO] File stream
|
27
|
-
def self.open_file(filename_or_url, **options, &block)
|
28
|
-
LOCAL_PATHS.each do |r, l|
|
29
|
-
next unless Dir.exist?(l) && filename_or_url.start_with?(r)
|
30
|
-
#puts "attempt to open #{filename_or_url} locally"
|
31
|
-
url_no_frag_or_query = RDF::URI(filename_or_url).dup
|
32
|
-
url_no_frag_or_query.query = nil
|
33
|
-
url_no_frag_or_query.fragment = nil
|
34
|
-
localpath = url_no_frag_or_query.to_s.sub(r, l)
|
35
|
-
response = begin
|
36
|
-
::File.open(localpath)
|
37
|
-
rescue Errno::ENOENT => e
|
38
|
-
raise IOError, e.message
|
39
|
-
end
|
40
|
-
|
41
|
-
document_options = {
|
42
|
-
base_uri: RDF::URI(filename_or_url),
|
43
|
-
charset: Encoding::UTF_8,
|
44
|
-
code: 200,
|
45
|
-
headers: options.fetch(:headers, {})
|
46
|
-
}
|
47
|
-
#puts "use #{filename_or_url} locally"
|
48
|
-
document_options[:headers][:content_type] = case localpath
|
49
|
-
when /\.ttl$/ then 'text/turtle'
|
50
|
-
when /\.nq$/ then 'application/n-quads'
|
51
|
-
when /\.nt$/ then 'application/n-triples'
|
52
|
-
when /\.html$/ then 'text/html'
|
53
|
-
when /\.jsonld$/ then 'application/ld+json'
|
54
|
-
when /\.json$/ then 'application/json'
|
55
|
-
else 'unknown'
|
56
|
-
end
|
57
|
-
|
58
|
-
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
|
59
|
-
# For overriding content type from test data
|
60
|
-
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
|
61
|
-
|
62
|
-
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
|
63
|
-
response.close
|
64
|
-
if block_given?
|
65
|
-
return yield remote_document
|
66
|
-
else
|
67
|
-
return remote_document
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
original_open_file(filename_or_url, **options, &block)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
module Fixtures
|
77
|
-
module SuiteTest
|
78
|
-
SUITE = RDF::URI("https://w3c.github.io/json-ld-api/tests/")
|
79
|
-
FRAME_SUITE = RDF::URI("https://w3c.github.io/json-ld-framing/tests/")
|
80
|
-
STREAM_SUITE = RDF::URI("https://w3c.github.io/json-ld-streaming/tests/")
|
81
|
-
STAR_SUITE = RDF::URI("https://json-ld.github.io/json-ld-star/tests/")
|
82
|
-
|
83
|
-
class Manifest < JSON::LD::Resource
|
84
|
-
attr_accessor :manifest_url
|
85
|
-
|
86
|
-
def self.open(file)
|
87
|
-
RDF::Util::File.open_file(file) do |remote|
|
88
|
-
json = JSON.parse(remote.read)
|
89
|
-
if block_given?
|
90
|
-
yield self.from_jsonld(json, manifest_url: RDF::URI(file))
|
91
|
-
else
|
92
|
-
self.from_jsonld(json, manifest_url: RDF::URI(file))
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def initialize(json, manifest_url:)
|
98
|
-
@manifest_url = manifest_url
|
99
|
-
super
|
100
|
-
end
|
101
|
-
|
102
|
-
# @param [Hash] json framed JSON-LD
|
103
|
-
# @return [Array<Manifest>]
|
104
|
-
def self.from_jsonld(json, manifest_url: )
|
105
|
-
Manifest.new(json, manifest_url: manifest_url)
|
106
|
-
end
|
107
|
-
|
108
|
-
def entries
|
109
|
-
# Map entries to resources
|
110
|
-
attributes['sequence'].map do |e|
|
111
|
-
e.is_a?(String) ? Manifest.open(manifest_url.join(e).to_s) : Entry.new(e, manifest_url: manifest_url)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class Entry < JSON::LD::Resource
|
117
|
-
attr_accessor :logger
|
118
|
-
attr_accessor :manifest_url
|
119
|
-
|
120
|
-
def initialize(json, manifest_url:)
|
121
|
-
@manifest_url = manifest_url
|
122
|
-
super
|
123
|
-
end
|
124
|
-
|
125
|
-
# Base is expanded input if not specified
|
126
|
-
def base
|
127
|
-
options.fetch('base', manifest_url.join(property('input')).to_s)
|
128
|
-
end
|
129
|
-
|
130
|
-
def options
|
131
|
-
@options ||= begin
|
132
|
-
opts = {
|
133
|
-
documentLoader: Fixtures::SuiteTest.method(:documentLoader),
|
134
|
-
validate: true,
|
135
|
-
lowercaseLanguage: true,
|
136
|
-
}
|
137
|
-
{'specVersion' => "json-ld-1.1"}.merge(property('option') || {}).each do |k, v|
|
138
|
-
opts[k.to_sym] = v
|
139
|
-
end
|
140
|
-
if opts[:expandContext] && !RDF::URI(opts[:expandContext]).absolute?
|
141
|
-
# Resolve relative to manifest location
|
142
|
-
opts[:expandContext] = manifest_url.join(opts[:expandContext]).to_s
|
143
|
-
end
|
144
|
-
opts
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Alias input, context, expect and frame
|
149
|
-
%w(input context expect frame).each do |m|
|
150
|
-
define_method(m.to_sym) do
|
151
|
-
return nil unless property(m)
|
152
|
-
res = nil
|
153
|
-
file = self.send("#{m}_loc".to_sym)
|
154
|
-
|
155
|
-
dl_opts = {safe: true}
|
156
|
-
dl_opts[:contentType] = options[:contentType] if m == 'input' && options[:contentType]
|
157
|
-
RDF::Util::File.open_file(file, **dl_opts) do |remote_doc|
|
158
|
-
res = remote_doc.read
|
159
|
-
end
|
160
|
-
res
|
161
|
-
end
|
162
|
-
|
163
|
-
define_method("#{m}_loc".to_sym) do
|
164
|
-
file = property(m)
|
165
|
-
|
166
|
-
# Handle redirection internally
|
167
|
-
if m == "input" && options[:redirectTo]
|
168
|
-
file = options[:redirectTo]
|
169
|
-
end
|
170
|
-
|
171
|
-
property(m) && manifest_url.join(file).to_s
|
172
|
-
end
|
173
|
-
|
174
|
-
define_method("#{m}_json".to_sym) do
|
175
|
-
JSON.parse(self.send(m)) if property(m)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def testType
|
180
|
-
property('@type').reject {|t| t =~ /EvaluationTest|SyntaxTest/}.first
|
181
|
-
end
|
182
|
-
|
183
|
-
def evaluationTest?
|
184
|
-
property('@type').to_s.include?('EvaluationTest')
|
185
|
-
end
|
186
|
-
|
187
|
-
def positiveTest?
|
188
|
-
property('@type').to_s.include?('Positive')
|
189
|
-
end
|
190
|
-
|
191
|
-
def syntaxTest?
|
192
|
-
property('@type').to_s.include?('Syntax')
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
# Execute the test
|
197
|
-
def run(rspec_example = nil)
|
198
|
-
logger = @logger = RDF::Spec.logger
|
199
|
-
logger.info "test: #{inspect}"
|
200
|
-
logger.info "purpose: #{purpose}"
|
201
|
-
logger.info "source: #{input rescue nil}"
|
202
|
-
logger.info "context: #{context}" if context_loc
|
203
|
-
logger.info "options: #{options.inspect}" unless options.empty?
|
204
|
-
logger.info "frame: #{frame}" if frame_loc
|
205
|
-
|
206
|
-
options = self.options
|
207
|
-
if options[:specVersion] == "json-ld-1.0"
|
208
|
-
skip "1.0 test"
|
209
|
-
return
|
210
|
-
end
|
211
|
-
|
212
|
-
# Because we're doing exact comparisons when ordered.
|
213
|
-
options[:lowercaseLanguage] = true if options[:ordered]
|
214
|
-
|
215
|
-
if positiveTest?
|
216
|
-
logger.info "expected: #{expect rescue nil}" if expect_loc
|
217
|
-
begin
|
218
|
-
result = case testType
|
219
|
-
when "jld:ExpandTest"
|
220
|
-
JSON::LD::API.expand(input_loc, logger: logger, **options)
|
221
|
-
when "jld:CompactTest"
|
222
|
-
JSON::LD::API.compact(input_loc, context_json['@context'], logger: logger, **options)
|
223
|
-
when "jld:FlattenTest"
|
224
|
-
JSON::LD::API.flatten(input_loc, (context_json['@context'] if context_loc), logger: logger, **options)
|
225
|
-
when "jld:FrameTest"
|
226
|
-
JSON::LD::API.frame(input_loc, frame_loc, logger: logger, **options)
|
227
|
-
when "jld:FromRDFTest"
|
228
|
-
# Use an array, to preserve input order
|
229
|
-
repo = RDF::NQuads::Reader.open(input_loc, rdfstar: options[:rdfstar]) do |reader|
|
230
|
-
reader.each_statement.to_a
|
231
|
-
end.to_a.uniq.extend(RDF::Enumerable)
|
232
|
-
logger.info "repo: #{repo.dump(self.id == '#t0012' ? :nquads : :trig)}"
|
233
|
-
JSON::LD::API.fromRdf(repo, logger: logger, **options)
|
234
|
-
when "jld:ToRDFTest"
|
235
|
-
repo = RDF::Repository.new
|
236
|
-
if manifest_url.to_s.include?('stream')
|
237
|
-
JSON::LD::Reader.open(input_loc, stream: true, logger: logger, **options) do |statement|
|
238
|
-
repo << statement
|
239
|
-
end
|
240
|
-
else
|
241
|
-
JSON::LD::API.toRdf(input_loc, rename_bnodes: false, logger: logger, **options) do |statement|
|
242
|
-
repo << statement
|
243
|
-
end
|
244
|
-
end
|
245
|
-
logger.info "nq: #{repo.map(&:to_nquads)}"
|
246
|
-
repo
|
247
|
-
when "jld:HttpTest"
|
248
|
-
res = input_json
|
249
|
-
rspec_example.instance_eval do
|
250
|
-
# use the parsed input file as @result for Rack Test application
|
251
|
-
@results = res
|
252
|
-
get "/", {}, "HTTP_ACCEPT" => options.fetch(:httpAccept, ""), "HTTP_LINK" => options.fetch(:httpLink, nil)
|
253
|
-
expect(last_response.status).to eq 200
|
254
|
-
expect(last_response.content_type).to eq options.fetch(:contentType, "")
|
255
|
-
JSON.parse(last_response.body)
|
256
|
-
end
|
257
|
-
else
|
258
|
-
fail("Unknown test type: #{testType}")
|
259
|
-
end
|
260
|
-
if evaluationTest?
|
261
|
-
if testType == "jld:ToRDFTest"
|
262
|
-
expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect, rdfstar: options[:rdfstar], logger: [])
|
263
|
-
rspec_example.instance_eval {
|
264
|
-
expect(result).to be_equivalent_graph(expected, logger)
|
265
|
-
}
|
266
|
-
else
|
267
|
-
expected = JSON.load(expect)
|
268
|
-
|
269
|
-
# If called for, remap bnodes
|
270
|
-
result = remap_bnodes(result, expected) if options[:remap_bnodes]
|
271
|
-
|
272
|
-
if options[:ordered]
|
273
|
-
# Compare without transformation
|
274
|
-
rspec_example.instance_eval {
|
275
|
-
expect(result).to produce(expected, logger)
|
276
|
-
}
|
277
|
-
else
|
278
|
-
# Without key ordering, reorder result and expected embedded array values and compare
|
279
|
-
# If results are compacted, expand both, reorder and re-compare
|
280
|
-
rspec_example.instance_eval {
|
281
|
-
expect(result).to produce_jsonld(expected, logger)
|
282
|
-
}
|
283
|
-
|
284
|
-
# If results are compacted, expand both, reorder and re-compare
|
285
|
-
if result.to_s.include?('@context')
|
286
|
-
exp_expected = JSON::LD::API.expand(expected, **options)
|
287
|
-
exp_result = JSON::LD::API.expand(result, **options)
|
288
|
-
rspec_example.instance_eval {
|
289
|
-
expect(exp_result).to produce_jsonld(exp_expected, logger)
|
290
|
-
}
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
else
|
295
|
-
rspec_example.instance_eval {
|
296
|
-
expect(result).to_not be_nil
|
297
|
-
}
|
298
|
-
end
|
299
|
-
rescue JSON::LD::JsonLdError => e
|
300
|
-
fail("Processing error: #{e.message}")
|
301
|
-
end
|
302
|
-
else
|
303
|
-
logger.info "expected: #{property('expect')}" if property('expect')
|
304
|
-
t = self
|
305
|
-
rspec_example.instance_eval do
|
306
|
-
if t.evaluationTest?
|
307
|
-
expect do
|
308
|
-
case t.testType
|
309
|
-
when "jld:ExpandTest"
|
310
|
-
JSON::LD::API.expand(t.input_loc, logger: logger, **options)
|
311
|
-
when "jld:CompactTest"
|
312
|
-
JSON::LD::API.compact(t.input_loc, t.context_json['@context'], logger: logger, **options)
|
313
|
-
when "jld:FlattenTest"
|
314
|
-
JSON::LD::API.flatten(t.input_loc, t.context_loc, logger: logger, **options)
|
315
|
-
when "jld:FrameTest"
|
316
|
-
JSON::LD::API.frame(t.input_loc, t.frame_loc, logger: logger, **options)
|
317
|
-
when "jld:FromRDFTest"
|
318
|
-
repo = RDF::Repository.load(t.input_loc, rdfstar: options[:rdfstar])
|
319
|
-
logger.info "repo: #{repo.dump(t.id == '#t0012' ? :nquads : :trig)}"
|
320
|
-
JSON::LD::API.fromRdf(repo, logger: logger, **options)
|
321
|
-
when "jld:HttpTest"
|
322
|
-
rspec_example.instance_eval do
|
323
|
-
# use the parsed input file as @result for Rack Test application
|
324
|
-
@results = t.input_json
|
325
|
-
get "/", {}, "HTTP_ACCEPT" => options.fetch(:httpAccept, "")
|
326
|
-
expect(last_response.status).to eq t.property('expect')
|
327
|
-
expect(last_response.content_type).to eq options.fetch(:contentType, "")
|
328
|
-
raise "406" if t.property('expect') == 406
|
329
|
-
raise "Expected status #{t.property('expectErrorCode')}, not #{last_response.status}"
|
330
|
-
end
|
331
|
-
when "jld:ToRDFTest"
|
332
|
-
if t.manifest_url.to_s.include?('stream')
|
333
|
-
JSON::LD::Reader.open(t.input_loc, stream: true, logger: logger, **options).each_statement {}
|
334
|
-
else
|
335
|
-
JSON::LD::API.toRdf(t.input_loc, rename_bnodes: false, logger: logger, **options) {}
|
336
|
-
end
|
337
|
-
else
|
338
|
-
success("Unknown test type: #{testType}")
|
339
|
-
end
|
340
|
-
end.to raise_error(/#{t.property('expectErrorCode')}/)
|
341
|
-
else
|
342
|
-
fail("No support for NegativeSyntaxTest")
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
# Don't use NQuads writer so that we don't escape Unicode
|
349
|
-
def to_quad(thing)
|
350
|
-
case thing
|
351
|
-
when RDF::URI
|
352
|
-
thing.to_ntriples
|
353
|
-
when RDF::Node
|
354
|
-
escaped(thing)
|
355
|
-
when RDF::Literal::Double
|
356
|
-
thing.canonicalize.to_ntriples
|
357
|
-
when RDF::Literal
|
358
|
-
v = quoted(escaped(thing.value))
|
359
|
-
case thing.datatype
|
360
|
-
when nil, "http://www.w3.org/2001/XMLSchema#string", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
|
361
|
-
# Ignore these
|
362
|
-
else
|
363
|
-
v += "^^#{to_quad(thing.datatype)}"
|
364
|
-
end
|
365
|
-
v += "@#{thing.language}" if thing.language
|
366
|
-
v
|
367
|
-
when RDF::Statement
|
368
|
-
thing.to_quad.map {|r| to_quad(r)}.compact.join(" ") + " .\n"
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
##
|
373
|
-
# @param [String] string
|
374
|
-
# @return [String]
|
375
|
-
def quoted(string)
|
376
|
-
"\"#{string}\""
|
377
|
-
end
|
378
|
-
|
379
|
-
##
|
380
|
-
# @param [String, #to_s] string
|
381
|
-
# @return [String]
|
382
|
-
def escaped(string)
|
383
|
-
string.to_s.gsub('\\', '\\\\').gsub("\t", '\\t').
|
384
|
-
gsub("\n", '\\n').gsub("\r", '\\r').gsub('"', '\\"')
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
##
|
389
|
-
# Document loader to use for tests having `useDocumentLoader` option
|
390
|
-
#
|
391
|
-
# @param [RDF::URI, String] url
|
392
|
-
# @param [Hash<Symbol => Object>] options
|
393
|
-
# @option options [Boolean] :validate
|
394
|
-
# Allow only appropriate content types
|
395
|
-
# @return [RDF::Util::File::RemoteDocument] retrieved remote document and context information unless block given
|
396
|
-
# @yield remote_document
|
397
|
-
# @yieldparam [RDF::Util::File::RemoteDocument] remote_document
|
398
|
-
# @raise [JsonLdError]
|
399
|
-
def documentLoader(url, **options, &block)
|
400
|
-
options[:headers] ||= JSON::LD::API::OPEN_OPTS[:headers].dup
|
401
|
-
options[:headers][:link] = Array(options[:httpLink]).join(',') if options[:httpLink]
|
402
|
-
|
403
|
-
url = url.to_s[5..-1] if url.to_s.start_with?("file:")
|
404
|
-
JSON::LD::API.documentLoader(url, **options, &block)
|
405
|
-
rescue JSON::LD::JsonLdError::LoadingDocumentFailed, JSON::LD::JsonLdError::MultipleContextLinkHeaders
|
406
|
-
raise unless options[:safe]
|
407
|
-
"don't raise error"
|
408
|
-
end
|
409
|
-
module_function :documentLoader
|
410
|
-
end
|
411
|
-
end
|
data/spec/suite_html_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}html-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_http_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
require 'rack/linkeddata'
|
4
|
-
require 'rack/test'
|
5
|
-
|
6
|
-
begin
|
7
|
-
describe JSON::LD do
|
8
|
-
describe "test suite" do
|
9
|
-
require_relative 'suite_helper'
|
10
|
-
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}http-manifest.jsonld")
|
11
|
-
describe m.name do
|
12
|
-
include ::Rack::Test::Methods
|
13
|
-
before(:all) {JSON::LD::Writer.default_context = "#{Fixtures::SuiteTest::SUITE}http/default-context.jsonld"}
|
14
|
-
after(:all) {JSON::LD::Writer.default_context = nil}
|
15
|
-
let(:app) do
|
16
|
-
JSON::LD::ContentNegotiation.new(
|
17
|
-
Rack::LinkedData::ContentNegotiation.new(
|
18
|
-
double("Target Rack Application", :call => [200, {}, @results]),
|
19
|
-
{}
|
20
|
-
)
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
m.entries.each do |t|
|
25
|
-
specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
|
26
|
-
t.options[:ordered] = false
|
27
|
-
expect {t.run self}.not_to write.to(:error)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end unless ENV['CI']
|
33
|
-
rescue IOError
|
34
|
-
# Skip this until such a test suite is re-added
|
35
|
-
end
|
@@ -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}remote-doc-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_to_rdf_spec.rb
DELETED
@@ -1,30 +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}toRdf-manifest.jsonld")
|
8
|
-
describe m.name do
|
9
|
-
m.entries.each do |t|
|
10
|
-
specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
|
11
|
-
pending "Generalized RDF" if t.options[:produceGeneralizedRdf]
|
12
|
-
pending "RDF-star" if t.property('@id') == '#te122'
|
13
|
-
if %w(#t0118).include?(t.property('@id'))
|
14
|
-
expect {t.run self}.to write(/Statement .* is invalid/).to(:error)
|
15
|
-
elsif %w(#te075).include?(t.property('@id'))
|
16
|
-
expect {t.run self}.to write(/is invalid/).to(:error)
|
17
|
-
elsif %w(#te005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #te119 #te120).include?(t.property('@id'))
|
18
|
-
expect {t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
|
19
|
-
elsif %w(#te068).include?(t.property('@id'))
|
20
|
-
expect {t.run self}.to write("[DEPRECATION]").to(:error)
|
21
|
-
elsif %w(#twf05).include?(t.property('@id'))
|
22
|
-
expect {t.run self}.to write("@language must be valid BCP47").to(:error)
|
23
|
-
else
|
24
|
-
expect {t.run self}.not_to write.to(:error)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end unless ENV['CI']
|
data/spec/support/extensions.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
def equivalent_jsonld?(other, ordered: false)
|
3
|
-
self == other
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class Hash
|
8
|
-
def equivalent_jsonld?(other, ordered: false)
|
9
|
-
return false unless other.is_a?(Hash) && other.length == length
|
10
|
-
all? do |key, value|
|
11
|
-
# List values are still ordered
|
12
|
-
if key == '@language' && value.is_a?(String)
|
13
|
-
value.downcase.equivalent_jsonld?(other[key].to_s.downcase, ordered: key == '@list')
|
14
|
-
else
|
15
|
-
value.equivalent_jsonld?(other[key], ordered: key == '@list')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def diff(other)
|
21
|
-
self.keys.inject({}) do |memo, key|
|
22
|
-
unless self[key] == other[key]
|
23
|
-
memo[key] = [self[key], other[key]]
|
24
|
-
end
|
25
|
-
memo
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Array
|
31
|
-
def equivalent_jsonld?(other, ordered: false)
|
32
|
-
return false unless other.is_a?(Array) && other.length == length
|
33
|
-
if ordered
|
34
|
-
b = other.dup
|
35
|
-
# All elements must match in order
|
36
|
-
all? {|av| av.equivalent_jsonld?(b.shift)}
|
37
|
-
else
|
38
|
-
# Look for any element which matches
|
39
|
-
all? do |av|
|
40
|
-
other.any? {|bv| av.equivalent_jsonld?(bv)}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"@context": {
|
3
|
-
"avatar": "http://xmlns.com/foaf/0.1/avatar",
|
4
|
-
"homepage": "http://xmlns.com/foaf/0.1/homepage",
|
5
|
-
"name": "http://xmlns.com/foaf/0.1/name"
|
6
|
-
},
|
7
|
-
"avatar": "http://twitter.com/account/profile_image/manusporny",
|
8
|
-
"homepage": "http://manu.sporny.org/",
|
9
|
-
"name": "Manu Sporny"
|
10
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"@context": {
|
3
|
-
"name": "http://xmlns.com/foaf/0.1/name",
|
4
|
-
"homepage": "http://xmlns.com/foaf/0.1/homepage",
|
5
|
-
"avatar": "http://xmlns.com/foaf/0.1/avatar"
|
6
|
-
},
|
7
|
-
"name": "Manu Sporny",
|
8
|
-
"homepage": "http://manu.sporny.org/",
|
9
|
-
"avatar": "http://twitter.com/account/profile_image/manusporny"
|
10
|
-
}
|
@@ -1,8 +0,0 @@
|
|
1
|
-
@prefix avatar: <http://xmlns.com/foaf/0.1/avatar> .
|
2
|
-
@prefix homepage: <http://xmlns.com/foaf/0.1/homepage> .
|
3
|
-
@prefix name: <http://xmlns.com/foaf/0.1/name> .
|
4
|
-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
5
|
-
|
6
|
-
[ avatar: "http://twitter.com/account/profile_image/manusporny";
|
7
|
-
homepage: "http://manu.sporny.org/";
|
8
|
-
name: "Manu Sporny"] .
|
@@ -1,20 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"@context": {
|
3
|
-
"dc": "http://purl.org/dc/elements/1.1/",
|
4
|
-
"ex": "http://example.org/vocab#"
|
5
|
-
},
|
6
|
-
"@id": "http://example.org/library",
|
7
|
-
"@type": "ex:Library",
|
8
|
-
"ex:contains": {
|
9
|
-
"@id": "http://example.org/library/the-republic",
|
10
|
-
"@type": "ex:Book",
|
11
|
-
"dc:creator": "Plato",
|
12
|
-
"dc:title": "The Republic",
|
13
|
-
"ex:contains": {
|
14
|
-
"@id": "http://example.org/library/the-republic#introduction",
|
15
|
-
"@type": "ex:Chapter",
|
16
|
-
"dc:description": "An introductory chapter on The Republic.",
|
17
|
-
"dc:title": "The Introduction"
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
[{
|
2
|
-
"@id": "http://example.org/library",
|
3
|
-
"@type": ["http://example.org/vocab#Library"],
|
4
|
-
"http://example.org/vocab#contains": [{
|
5
|
-
"@id": "http://example.org/library/the-republic",
|
6
|
-
"@type": ["http://example.org/vocab#Book"],
|
7
|
-
"http://purl.org/dc/elements/1.1/creator": [{"@value": "Plato"}],
|
8
|
-
"http://purl.org/dc/elements/1.1/title": [{"@value": "The Republic"}],
|
9
|
-
"http://example.org/vocab#contains": [{
|
10
|
-
"@id": "http://example.org/library/the-republic#introduction",
|
11
|
-
"@type": ["http://example.org/vocab#Chapter"],
|
12
|
-
"http://purl.org/dc/elements/1.1/description": [{"@value": "An introductory chapter on The Republic."}],
|
13
|
-
"http://purl.org/dc/elements/1.1/title": [{"@value": "The Introduction"}]
|
14
|
-
}]
|
15
|
-
}]
|
16
|
-
}]
|