json-ld 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +5 -4
- data/lib/json/ld/context.rb +1 -1
- data/lib/json/ld/from_rdf.rb +1 -1
- data/spec/suite_helper.rb +87 -88
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODMzNjFiMDVhYTdjNTk1OGQ3NTFiMzQwZjE0ZDViM2I1Mjk1YWI2Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGYyMDRhMjNiMWJkNDY1ODAyODk4Y2RkZTY2N2U2OGY3NWQ4YzM2OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTM0NTI4MzRmMzA1OTI2MDM1MzQ2ZTFkYWQ4MWM0OTM4MjkwMGE0NGU3ZGQ4
|
10
|
+
ZmFlNjM5MzBlNGZkZjkyMjgyYmIzM2U3MWU5OTUxOTNmZGUwMjc3ODExYWRi
|
11
|
+
M2Q5ZjdkMjU1M2NkY2MwZTgwNWYzNTE2N2UyMWVjNmY1NmYzYjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjEyNzQ4MzM5MzNlNzc2ZGMwYTgxZjNiNjBjZDlhMWEzNWZmNzliN2E2Nzlm
|
14
|
+
N2Y2OWJjZTIwNDFmODQ0ZmFkMGM1NDQwNDRjOTQ4MjNjMjJlNTgzZGY3NWE5
|
15
|
+
NjQ3MDI4YTk4Y2RhYmQ0MmEyMDkxNDVjZmViMTM2MmNhMzM0NTQ=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.7
|
data/lib/json/ld/api.rb
CHANGED
@@ -66,8 +66,10 @@ module JSON::LD
|
|
66
66
|
# If set to "json-ld-1.0", the JSON-LD processor must produce exactly the same results as the algorithms defined in this specification. If set to another value, the JSON-LD processor is allowed to extend or modify the algorithms defined in this specification to enable application-specific optimizations. The definition of such optimizations is beyond the scope of this specification and thus not defined. Consequently, different implementations may implement different optimizations. Developers must not define modes beginning with json-ld as they are reserved for future versions of this specification.
|
67
67
|
# @option options [String] :produceGeneralizedRdf (false)
|
68
68
|
# Unless the produce generalized RDF flag is set to true, RDF triples containing a blank node predicate are excluded from output.
|
69
|
-
# @option options [Boolean] :useNativeTypes (
|
69
|
+
# @option options [Boolean] :useNativeTypes (false)
|
70
70
|
# If set to `true`, the JSON-LD processor will use native datatypes for expression xsd:integer, xsd:boolean, and xsd:double values, otherwise, it will use the expanded form.
|
71
|
+
# @option options [Boolean] :useRdfType (false)
|
72
|
+
# If set to `true`, the JSON-LD processor will treat `rdf:type` like a normal property instead of using `@type`.
|
71
73
|
# @option options [Boolean] :rename_bnodes (true)
|
72
74
|
# Rename bnodes as part of expansion, or keep them the same.
|
73
75
|
# @yield [api]
|
@@ -497,7 +499,7 @@ module JSON::LD
|
|
497
499
|
end
|
498
500
|
end
|
499
501
|
|
500
|
-
yield
|
502
|
+
return block_given? ? yield(remote_document) : remote_document
|
501
503
|
when Net::HTTPRedirection
|
502
504
|
# Follow redirection
|
503
505
|
parsed_url = ::URI.parse(response["Location"])
|
@@ -519,10 +521,9 @@ module JSON::LD
|
|
519
521
|
sub !~ /^(.*\+)?json$/
|
520
522
|
end
|
521
523
|
|
522
|
-
yield
|
524
|
+
return block_given? ? yield(remote_document) : remote_document
|
523
525
|
end
|
524
526
|
end
|
525
|
-
remote_document
|
526
527
|
end
|
527
528
|
|
528
529
|
##
|
data/lib/json/ld/context.rb
CHANGED
@@ -877,7 +877,7 @@ module JSON::LD
|
|
877
877
|
# @param [Hash, String] value
|
878
878
|
# Value (literal or IRI) to be expanded
|
879
879
|
# @param [Hash{Symbol => Object}] options
|
880
|
-
# @option options [Boolean] :useNativeTypes (
|
880
|
+
# @option options [Boolean] :useNativeTypes (false) use native representations
|
881
881
|
#
|
882
882
|
# @return [Hash] Object representation of value
|
883
883
|
# @raise [RDF::ReaderError] if the iri cannot be expanded
|
data/lib/json/ld/from_rdf.rb
CHANGED
@@ -37,7 +37,7 @@ module JSON::LD
|
|
37
37
|
statement.object.literal?
|
38
38
|
|
39
39
|
# If predicate equals rdf:type, and object is an IRI or blank node identifier, append object to the value of the @type member of node. If no such member exists, create one and initialize it to an array whose only item is object. Finally, continue to the next RDF triple.
|
40
|
-
if statement.predicate == RDF.type && statement.object.resource?
|
40
|
+
if statement.predicate == RDF.type && statement.object.resource? && !@options[:useRdfType]
|
41
41
|
merge_value(node, '@type', statement.object.to_s)
|
42
42
|
next
|
43
43
|
end
|
data/spec/suite_helper.rb
CHANGED
@@ -10,8 +10,8 @@ module Fixtures
|
|
10
10
|
class Manifest < JSON::LD::Resource
|
11
11
|
def self.open(file)
|
12
12
|
#puts "open: #{file}"
|
13
|
-
|
14
|
-
json = JSON.parse(
|
13
|
+
Fixtures::SuiteTest.documentLoader(file) do |remote|
|
14
|
+
json = JSON.parse(remote.document)
|
15
15
|
if block_given?
|
16
16
|
yield self.from_jsonld(json)
|
17
17
|
else
|
@@ -44,7 +44,7 @@ module Fixtures
|
|
44
44
|
|
45
45
|
def options
|
46
46
|
@options ||= begin
|
47
|
-
opts = {:documentLoader =>
|
47
|
+
opts = {:documentLoader => Fixtures::SuiteTest.method(:documentLoader)}
|
48
48
|
{'processingMode' => "json-ld-1.0"}.merge(property('option') || {}).each do |k, v|
|
49
49
|
opts[k.to_sym] = v
|
50
50
|
end
|
@@ -57,7 +57,7 @@ module Fixtures
|
|
57
57
|
define_method(m.to_sym) do
|
58
58
|
return nil unless property(m)
|
59
59
|
res = nil
|
60
|
-
|
60
|
+
Fixtures::SuiteTest.documentLoader("#{SUITE}tests/#{property(m)}", :safe => true) do |remote_doc|
|
61
61
|
res = remote_doc.document
|
62
62
|
end
|
63
63
|
res
|
@@ -88,7 +88,7 @@ module Fixtures
|
|
88
88
|
debug << "frame: #{frame}" if frame_loc
|
89
89
|
|
90
90
|
options = if self.options[:useDocumentLoader]
|
91
|
-
self.options.merge(:documentLoader => method(:documentLoader))
|
91
|
+
self.options.merge(:documentLoader => Fixtures::SuiteTest.method(:documentLoader))
|
92
92
|
else
|
93
93
|
self.options.dup
|
94
94
|
end
|
@@ -210,104 +210,103 @@ module Fixtures
|
|
210
210
|
string.to_s.gsub('\\', '\\\\').gsub("\t", '\\t').
|
211
211
|
gsub("\n", '\\n').gsub("\r", '\\r').gsub('"', '\\"')
|
212
212
|
end
|
213
|
+
end
|
213
214
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
215
|
+
REMOTE_PATH = "http://json-ld.org/test-suite/"
|
216
|
+
LOCAL_PATH = ::File.expand_path("../json-ld.org/test-suite", __FILE__) + '/'
|
217
|
+
##
|
218
|
+
# Document loader to use for tests having `useDocumentLoader` option
|
219
|
+
#
|
220
|
+
# @param [RDF::URI, String] url
|
221
|
+
# @param [Hash<Symbol => Object>] options
|
222
|
+
# @option options [Boolean] :validate
|
223
|
+
# Allow only appropriate content types
|
224
|
+
# @return [RemoteDocument] retrieved remote document and context information unless block given
|
225
|
+
# @yield remote_document
|
226
|
+
# @yieldparam [RemoteDocument] remote_document
|
227
|
+
# @raise [JsonLdError]
|
228
|
+
def documentLoader(url, options = {})
|
229
|
+
require 'net/http' unless defined?(Net::HTTP)
|
230
|
+
remote_document = nil
|
231
|
+
options[:headers] ||= JSON::LD::API::OPEN_OPTS[:headers]
|
231
232
|
|
232
|
-
|
233
|
+
url = url.to_s[5..-1] if url.to_s.start_with?("file:")
|
233
234
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
243
|
-
return remote_document
|
235
|
+
if url.to_s.start_with?(REMOTE_PATH) && ::File.exist?(LOCAL_PATH) && url.to_s !~ /remote-doc/
|
236
|
+
#puts "attempt to open #{filename_or_url} locally"
|
237
|
+
local_filename = url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
|
238
|
+
if ::File.exist?(local_filename)
|
239
|
+
remote_document = JSON::LD::API::RemoteDocument.new(url.to_s, ::File.read(local_filename))
|
240
|
+
return block_given? ? yield(remote_document) : remote_document
|
241
|
+
else
|
242
|
+
raise JSON::LD::JsonLdError::LoadingDocumentFailed, "no such file #{local_filename}"
|
244
243
|
end
|
244
|
+
end
|
245
245
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
246
|
+
case url.to_s
|
247
|
+
when /^http/
|
248
|
+
parsed_url = ::URI.parse(url.to_s)
|
249
|
+
until remote_document do
|
250
|
+
Net::HTTP::start(parsed_url.host, parsed_url.port) do |http|
|
251
|
+
request = Net::HTTP::Get.new(parsed_url.request_uri, options[:headers])
|
252
|
+
http.request(request) do |response|
|
253
|
+
case response
|
254
|
+
when Net::HTTPSuccess
|
255
|
+
# found object
|
256
|
+
content_type, ct_param = response.content_type.to_s.downcase.split(";")
|
257
|
+
if content_type && options[:validate]
|
258
|
+
main, sub = content_type.split("/")
|
259
|
+
raise JSON::LD::JsonLdError::LoadingDocumentFailed, "content_type: #{content_type}" if
|
260
|
+
main != 'application' ||
|
261
|
+
sub !~ /^(.*\+)?json$/
|
262
|
+
end
|
263
263
|
|
264
|
-
|
264
|
+
remote_document = JSON::LD::API::RemoteDocument.new(parsed_url.to_s, response.body)
|
265
265
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
end
|
266
|
+
unless content_type.start_with?("application/ld+json")
|
267
|
+
links = response["link"].to_s.
|
268
|
+
split(",").
|
269
|
+
map(&:strip).
|
270
|
+
select {|h| h =~ %r{rel=\"http://www.w3.org/ns/json-ld#context\"}}
|
271
|
+
case links.length
|
272
|
+
when 0 then #nothing to do
|
273
|
+
when 1
|
274
|
+
remote_document.contextUrl = links.first.match(/<([^>]*)>/) && $1
|
275
|
+
else
|
276
|
+
raise JSON::LD::JsonLdError::MultipleContextLinkHeaders,
|
277
|
+
"expected at most 1 Link header with rel=jsonld:context, got #{links.length}"
|
279
278
|
end
|
280
|
-
yield remote_document if block_given?
|
281
|
-
when Net::HTTPRedirection
|
282
|
-
# Follow redirection
|
283
|
-
parsed_url = ::URI.parse(response["Location"])
|
284
|
-
else
|
285
|
-
raise JSON::LD::JsonLdError::LoadingDocumentFailed,
|
286
|
-
"<#{parsed_url}>: #{response.msg}(#{response.code})"
|
287
279
|
end
|
280
|
+
return block_given? ? yield(remote_document) : remote_document
|
281
|
+
when Net::HTTPRedirection
|
282
|
+
# Follow redirection
|
283
|
+
parsed_url = ::URI.parse(response["Location"])
|
284
|
+
else
|
285
|
+
raise JSON::LD::JsonLdError::LoadingDocumentFailed,
|
286
|
+
"<#{parsed_url}>: #{response.msg}(#{response.code})"
|
288
287
|
end
|
289
288
|
end
|
290
289
|
end
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
yield remote_document if block_given?
|
290
|
+
end
|
291
|
+
else
|
292
|
+
# Use regular open
|
293
|
+
RDF::Util::File.open_file(url, options) do |f|
|
294
|
+
remote_document = JSON::LD::API::RemoteDocument.new(url, f.read)
|
295
|
+
content_type, ct_param = f.content_type.to_s.downcase.split(";") if f.respond_to?(:content_type)
|
296
|
+
if content_type && options[:validate]
|
297
|
+
main, sub = content_type.split("/")
|
298
|
+
raise JSON::LD::JsonLdError::LoadingDocumentFailed, "content_type: #{content_type}" if
|
299
|
+
main != 'application' ||
|
300
|
+
sub !~ /^(.*\+)?json$/
|
304
301
|
end
|
302
|
+
|
303
|
+
return block_given? ? yield(remote_document) : remote_document
|
305
304
|
end
|
306
|
-
remote_document
|
307
|
-
rescue JSON::LD::JsonLdError::LoadingDocumentFailed, JSON::LD::JsonLdError::MultipleContextLinkHeaders
|
308
|
-
raise unless options[:safe]
|
309
|
-
"don't raise error"
|
310
305
|
end
|
306
|
+
rescue JSON::LD::JsonLdError::LoadingDocumentFailed, JSON::LD::JsonLdError::MultipleContextLinkHeaders
|
307
|
+
raise unless options[:safe]
|
308
|
+
"don't raise error"
|
311
309
|
end
|
310
|
+
module_function :documentLoader
|
312
311
|
end
|
313
312
|
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: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|