json-ld 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/jsonld +0 -1
- data/lib/json/ld.rb +1 -0
- data/lib/json/ld/api.rb +49 -27
- data/lib/json/ld/context.rb +62 -56
- data/lib/json/ld/frame.rb +0 -1
- data/lib/json/ld/writer.rb +5 -0
- data/spec/compact_spec.rb +157 -3
- data/spec/context_spec.rb +33 -14
- data/spec/expand_spec.rb +14 -2
- data/spec/suite_helper.rb +6 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b6c40e1f1bff540f8c175e321087f60a7a6c04
|
4
|
+
data.tar.gz: eeba4194d6cb10caa31214444882c18e8688d44c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 972abe58a807190d6cb9228f80abec5198012c4c395973025b4ca50f5ea54142170999f7210769c621861e5136704dabc2f99932ab62dc9f7c9516b7ba931ae8
|
7
|
+
data.tar.gz: db37dac97ad2569415b35bff8e1967d0126621dd978cc183e0d80e3dc998e2c4592a1e4f94bd5ffe39f35cb207867db6fe986092fb416fc9cd9266a6c103ad74
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.5
|
data/bin/jsonld
CHANGED
@@ -115,7 +115,6 @@ OPT_ARGS = [
|
|
115
115
|
["--quiet", GetoptLong::NO_ARGUMENT, "Supress most output other than progress indicators"],
|
116
116
|
["--rename_bnodes", GetoptLong::OPTIONAL_ARGUMENT,"Rename bnodes as part of expansion, or keep them the same"],
|
117
117
|
["--requireAll", GetoptLong::OPTIONAL_ARGUMENT,"Rename bnodes as part of expansion, or keep them the same"],
|
118
|
-
["--simple_compact_iris",GetoptLong::OPTIONAL_ARGUMENT,"When compacting IRIs, do not use terms with expanded term definitions"],
|
119
118
|
["--stream", GetoptLong::NO_ARGUMENT, "Use Streaming reader/writer"],
|
120
119
|
["--unique_bnodes", GetoptLong::OPTIONAL_ARGUMENT,"Use unique bnode identifiers"],
|
121
120
|
["--uri", GetoptLong::REQUIRED_ARGUMENT,"URI to be used as the document base"],
|
data/lib/json/ld.rb
CHANGED
@@ -115,6 +115,7 @@ module JSON
|
|
115
115
|
class InvalidLanguageTaggedValue < JsonLdError; @code = "invalid language-tagged value"; end
|
116
116
|
class InvalidLocalContext < JsonLdError; @code = "invalid local context"; end
|
117
117
|
class InvalidNestValue < JsonLdError; @code = "invalid @nest value"; end
|
118
|
+
class InvalidPrefixValue < JsonLdError; @code = "invalid @prefix value"; end
|
118
119
|
class InvalidRemoteContext < JsonLdError; @code = "invalid remote context"; end
|
119
120
|
class InvalidReverseProperty < JsonLdError; @code = "invalid reverse property"; end
|
120
121
|
class InvalidReversePropertyMap < JsonLdError; @code = "invalid reverse property map"; end
|
data/lib/json/ld/api.rb
CHANGED
@@ -63,6 +63,8 @@ module JSON::LD
|
|
63
63
|
# The Base IRI to use when expanding the document. This overrides the value of `input` if it is a _IRI_. If not specified and `input` is not an _IRI_, the base IRI defaults to the current document IRI if in a browser context, or the empty string if there is no document context. If not specified, and a base IRI is found from `input`, options[:base] will be modified with this value.
|
64
64
|
# @option options [Boolean] :compactArrays (true)
|
65
65
|
# If set to `true`, the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to `false`, all arrays will remain arrays even if they have just one element.
|
66
|
+
# @option options [Boolean] :compactToRelative (true)
|
67
|
+
# Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded.
|
66
68
|
# @option options [Proc] :documentLoader
|
67
69
|
# The callback of the loader to be used to retrieve remote documents and contexts. If specified, it must be used to retrieve remote documents and contexts; otherwise, if not specified, the processor's built-in loader must be used. See {documentLoader} for the method signature.
|
68
70
|
# @option options [String, #read, Hash, Array, JSON::LD::Context] :expandContext
|
@@ -79,8 +81,6 @@ module JSON::LD
|
|
79
81
|
# Rename bnodes as part of expansion, or keep them the same.
|
80
82
|
# @option options [Boolean] :unique_bnodes (false)
|
81
83
|
# Use unique bnode identifiers, defaults to using the identifier which the node was originally initialized with (if any).
|
82
|
-
# @option options [Boolean] :simple_compact_iris (false)
|
83
|
-
# When compacting IRIs, do not use terms with expanded term definitions
|
84
84
|
# @option options [Symbol] :adapter used with MultiJson
|
85
85
|
# @option options [Boolean] :validate Validate input, if a string or readable object.
|
86
86
|
# @yield [api]
|
@@ -88,20 +88,19 @@ module JSON::LD
|
|
88
88
|
# @raise [JsonLdError]
|
89
89
|
def initialize(input, context, options = {}, &block)
|
90
90
|
@options = {
|
91
|
-
compactArrays:
|
92
|
-
rename_bnodes:
|
93
|
-
documentLoader:
|
94
|
-
}
|
95
|
-
@options = @options.merge(options)
|
91
|
+
compactArrays: true,
|
92
|
+
rename_bnodes: true,
|
93
|
+
documentLoader: self.class.method(:documentLoader)
|
94
|
+
}.merge(options)
|
96
95
|
@namer = options[:unique_bnodes] ? BlankNodeUniqer.new : (@options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
|
97
96
|
|
98
97
|
# For context via Link header
|
99
|
-
context_ref = nil
|
98
|
+
remote_base, context_ref = nil, nil
|
100
99
|
|
101
100
|
@value = case input
|
102
101
|
when Array, Hash then input.dup
|
103
102
|
when IO, StringIO
|
104
|
-
@options = {base: input.base_uri}.merge
|
103
|
+
@options = {base: input.base_uri}.merge(@options) if input.respond_to?(:base_uri)
|
105
104
|
|
106
105
|
# if input impelements #links, attempt to get a contextUrl from that link
|
107
106
|
content_type = input.respond_to?(:content_type) ? input.content_type : "application/json"
|
@@ -116,8 +115,9 @@ module JSON::LD
|
|
116
115
|
when String
|
117
116
|
remote_doc = @options[:documentLoader].call(input, @options)
|
118
117
|
|
119
|
-
|
118
|
+
remote_base = remote_doc.documentUrl
|
120
119
|
context_ref = remote_doc.contextUrl
|
120
|
+
@options = {base: remote_doc.documentUrl}.merge(@options) unless @options[:no_default_base]
|
121
121
|
|
122
122
|
case remote_doc.document
|
123
123
|
when String
|
@@ -128,9 +128,6 @@ module JSON::LD
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
# Update calling context :base option, if not defined
|
132
|
-
options[:base] ||= @options[:base] if @options[:base]
|
133
|
-
|
134
131
|
# If not provided, first use context from document, or from a Link header
|
135
132
|
context ||= (@value['@context'] if @value.is_a?(Hash)) || context_ref
|
136
133
|
@context = Context.parse(context || {}, @options)
|
@@ -160,17 +157,20 @@ module JSON::LD
|
|
160
157
|
# @param [Hash{Symbol => Object}] options
|
161
158
|
# @option options (see #initialize)
|
162
159
|
# @raise [JsonLdError]
|
163
|
-
# @yield jsonld
|
160
|
+
# @yield jsonld, base_iri
|
164
161
|
# @yieldparam [Array<Hash>] jsonld
|
165
162
|
# The expanded JSON-LD document
|
163
|
+
# @yieldparam [RDF::URI] base_iri
|
164
|
+
# The document base as determined during expansion
|
166
165
|
# @yieldreturn [Object] returned object
|
167
166
|
# @return [Object, Array<Hash>]
|
168
167
|
# If a block is given, the result of evaluating the block is returned, otherwise, the expanded JSON-LD document
|
169
168
|
# @see http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
|
170
|
-
def self.expand(input, options = {})
|
171
|
-
result = nil
|
172
|
-
API.new(input, options[:expandContext], options) do
|
173
|
-
result =
|
169
|
+
def self.expand(input, options = {}, &block)
|
170
|
+
result, doc_base = nil
|
171
|
+
API.new(input, options[:expandContext], options) do
|
172
|
+
result = self.expand(self.value, nil, self.context, ordered: options.fetch(:ordered, true))
|
173
|
+
doc_base = @options[:base]
|
174
174
|
end
|
175
175
|
|
176
176
|
# If, after the algorithm outlined above is run, the resulting element is an JSON object with just a @graph property, element is set to the value of @graph's value.
|
@@ -178,7 +178,17 @@ module JSON::LD
|
|
178
178
|
|
179
179
|
# Finally, if element is a JSON object, it is wrapped into an array.
|
180
180
|
result = [result].compact unless result.is_a?(Array)
|
181
|
-
|
181
|
+
|
182
|
+
if block_given?
|
183
|
+
case block.arity
|
184
|
+
when 1 then yield(result)
|
185
|
+
when 2 then yield(result, doc_base)
|
186
|
+
else
|
187
|
+
raise "Unexpected number of yield parameters to expand"
|
188
|
+
end
|
189
|
+
else
|
190
|
+
result
|
191
|
+
end
|
182
192
|
end
|
183
193
|
|
184
194
|
##
|
@@ -204,13 +214,17 @@ module JSON::LD
|
|
204
214
|
# @raise [JsonLdError]
|
205
215
|
# @see http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm
|
206
216
|
def self.compact(input, context, options = {})
|
207
|
-
|
217
|
+
result = nil
|
218
|
+
options = {compactToRelative: true}.merge(options)
|
208
219
|
|
209
220
|
# 1) Perform the Expansion Algorithm on the JSON-LD input.
|
210
221
|
# This removes any existing context to allow the given context to be cleanly applied.
|
211
|
-
expanded_input = options[:expanded] ? input : API.expand(input, options)
|
222
|
+
expanded_input = options[:expanded] ? input : API.expand(input, options) do |result, base_iri|
|
223
|
+
options[:base] ||= base_iri if options[:compactToRelative]
|
224
|
+
result
|
225
|
+
end
|
212
226
|
|
213
|
-
API.new(expanded_input, context, options) do
|
227
|
+
API.new(expanded_input, context, options.merge(no_default_base: true)) do
|
214
228
|
log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
|
215
229
|
result = compact(value)
|
216
230
|
|
@@ -246,12 +260,16 @@ module JSON::LD
|
|
246
260
|
# @see http://json-ld.org/spec/latest/json-ld-api/#framing-algorithm
|
247
261
|
def self.flatten(input, context, options = {})
|
248
262
|
flattened = []
|
263
|
+
options = {compactToRelative: true}.merge(options)
|
249
264
|
|
250
265
|
# Expand input to simplify processing
|
251
|
-
expanded_input = options[:expanded] ? input : API.expand(input, options)
|
266
|
+
expanded_input = options[:expanded] ? input : API.expand(input, options) do |result, base_iri|
|
267
|
+
options[:base] ||= base_iri if options[:compactToRelative]
|
268
|
+
result
|
269
|
+
end
|
252
270
|
|
253
271
|
# Initialize input using
|
254
|
-
API.new(expanded_input, context, options) do
|
272
|
+
API.new(expanded_input, context, options.merge(no_default_base: true)) do
|
255
273
|
log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
|
256
274
|
|
257
275
|
# Initialize node map to a JSON object consisting of a single member whose key is @default and whose value is an empty JSON object.
|
@@ -316,13 +334,14 @@ module JSON::LD
|
|
316
334
|
options = {
|
317
335
|
base: (input if input.is_a?(String)),
|
318
336
|
compactArrays: true,
|
337
|
+
compactToRelative: true,
|
319
338
|
embed: '@last',
|
320
339
|
explicit: false,
|
321
340
|
requireAll: true,
|
322
341
|
omitDefault: false,
|
323
342
|
pruneBlankNodeIdentifiers: true,
|
324
343
|
documentLoader: method(:documentLoader)
|
325
|
-
}.merge
|
344
|
+
}.merge(options)
|
326
345
|
|
327
346
|
framing_state = {
|
328
347
|
graphMap: {},
|
@@ -344,13 +363,16 @@ module JSON::LD
|
|
344
363
|
end
|
345
364
|
|
346
365
|
# Expand input to simplify processing
|
347
|
-
expanded_input = options[:expanded] ? input : API.expand(input, options)
|
366
|
+
expanded_input = options[:expanded] ? input : API.expand(input, options) do |result, base_iri|
|
367
|
+
options[:base] ||= base_iri if options[:compactToRelative]
|
368
|
+
result
|
369
|
+
end
|
348
370
|
|
349
371
|
# Expand frame to simplify processing
|
350
372
|
expanded_frame = API.expand(frame, options.merge(processingMode: "json-ld-1.1-expand-frame"))
|
351
373
|
|
352
374
|
# Initialize input using frame as context
|
353
|
-
API.new(expanded_input, nil, options) do
|
375
|
+
API.new(expanded_input, nil, options.merge(no_default_base: true)) do
|
354
376
|
log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
|
355
377
|
|
356
378
|
# Get framing nodes from expanded input, replacing Blank Node identifiers as necessary
|
data/lib/json/ld/context.rb
CHANGED
@@ -58,6 +58,9 @@ module JSON::LD
|
|
58
58
|
# @return [Boolean]
|
59
59
|
attr_accessor :simple
|
60
60
|
|
61
|
+
# Indicate that term may be used as a prefix
|
62
|
+
attr_writer :prefix
|
63
|
+
|
61
64
|
# Term-specific context
|
62
65
|
# @return [Hash{String => Object}]
|
63
66
|
attr_accessor :context
|
@@ -66,6 +69,10 @@ module JSON::LD
|
|
66
69
|
# @return [Boolean] simple
|
67
70
|
def simple?; simple; end
|
68
71
|
|
72
|
+
# This is an appropriate term to use as the prefix of a compact IRI
|
73
|
+
# @return [Boolean] simple
|
74
|
+
def prefix?; @prefix; end
|
75
|
+
|
69
76
|
# Create a new Term Mapping with an ID
|
70
77
|
# @param [String] term
|
71
78
|
# @param [String] id
|
@@ -77,6 +84,8 @@ module JSON::LD
|
|
77
84
|
# @param [String] nest term used for nest properties
|
78
85
|
# @param [Boolean] simple
|
79
86
|
# This is a simple term definition, not an expanded term definition
|
87
|
+
# @param [Boolean] prefix
|
88
|
+
# Term may be used as a prefix
|
80
89
|
def initialize(term,
|
81
90
|
id: nil,
|
82
91
|
type_mapping: nil,
|
@@ -85,16 +94,18 @@ module JSON::LD
|
|
85
94
|
reverse_property: false,
|
86
95
|
nest: nil,
|
87
96
|
simple: false,
|
97
|
+
prefix: nil,
|
88
98
|
context: nil)
|
89
99
|
@term = term
|
90
|
-
@id = id.to_s
|
91
|
-
@type_mapping = type_mapping.to_s
|
92
|
-
self.container_mapping = container_mapping
|
93
|
-
@language_mapping = language_mapping
|
94
|
-
@reverse_property = reverse_property
|
95
|
-
@nest = nest
|
96
|
-
@simple = simple
|
97
|
-
@
|
100
|
+
@id = id.to_s unless id.nil?
|
101
|
+
@type_mapping = type_mapping.to_s unless type_mapping.nil?
|
102
|
+
self.container_mapping = container_mapping unless container_mapping.nil?
|
103
|
+
@language_mapping = language_mapping unless language_mapping.nil?
|
104
|
+
@reverse_property = reverse_property
|
105
|
+
@nest = nest unless nest.nil?
|
106
|
+
@simple = simple
|
107
|
+
@prefix = prefix unless prefix.nil?
|
108
|
+
@context = context unless context.nil?
|
98
109
|
end
|
99
110
|
|
100
111
|
# Set container mapping, from an array which may include @set
|
@@ -121,14 +132,7 @@ module JSON::LD
|
|
121
132
|
iri && iri != id ? "#{prefix}:#{id.to_s[iri.length..-1]}" : id
|
122
133
|
end
|
123
134
|
|
124
|
-
if
|
125
|
-
container_mapping.nil? &&
|
126
|
-
!as_set &&
|
127
|
-
type_mapping.nil? &&
|
128
|
-
reverse_property.nil? &&
|
129
|
-
self.context.nil? &&
|
130
|
-
nest.nil?
|
131
|
-
|
135
|
+
if simple?
|
132
136
|
cid.to_s unless cid == term && context.vocab
|
133
137
|
else
|
134
138
|
defn = {}
|
@@ -145,9 +149,10 @@ module JSON::LD
|
|
145
149
|
cm = cm.first if cm.length == 1
|
146
150
|
defn['@container'] = cm unless cm.empty?
|
147
151
|
# Language set as false to be output as null
|
148
|
-
defn['@language'] = (language_mapping ? language_mapping : nil) unless language_mapping.nil?
|
149
|
-
defn['@context'] =
|
150
|
-
defn['@nest'] =
|
152
|
+
defn['@language'] = (@language_mapping ? @language_mapping : nil) unless @language_mapping.nil?
|
153
|
+
defn['@context'] = @context if @context
|
154
|
+
defn['@nest'] = @nest if @nest
|
155
|
+
defn['@prefix'] = @prefix unless @prefix.nil? || (context.processingMode || 'json-ld-1.0') == 'json-ld-1.0'
|
151
156
|
defn
|
152
157
|
end
|
153
158
|
end
|
@@ -158,7 +163,7 @@ module JSON::LD
|
|
158
163
|
# @return [String]
|
159
164
|
def to_rb
|
160
165
|
defn = [%(TermDefinition.new\(#{term.inspect})]
|
161
|
-
%w(id type_mapping container_mapping language_mapping reverse_property nest simple context).each do |acc|
|
166
|
+
%w(id type_mapping container_mapping language_mapping reverse_property nest simple prefix context).each do |acc|
|
162
167
|
v = instance_variable_get("@#{acc}".to_sym)
|
163
168
|
v = v.to_s if v.is_a?(RDF::Term)
|
164
169
|
if acc == 'container_mapping' && as_set
|
@@ -179,6 +184,8 @@ module JSON::LD
|
|
179
184
|
v << "lang=#{language_mapping.inspect}" unless language_mapping.nil?
|
180
185
|
v << "type=#{type_mapping}" unless type_mapping.nil?
|
181
186
|
v << "nest=#{nest.inspect}" unless nest.nil?
|
187
|
+
v << "simple=true" if @simple
|
188
|
+
v << "prefix=#{@prefix.inspect}" unless @prefix.nil?
|
182
189
|
v << "has-context" unless context.nil?
|
183
190
|
v.join(" ") + "]"
|
184
191
|
end
|
@@ -194,7 +201,7 @@ module JSON::LD
|
|
194
201
|
# @return [RDF::URI] Document base IRI, to initialize `base`.
|
195
202
|
attr_reader :doc_base
|
196
203
|
|
197
|
-
# @return [RDF::URI] base IRI of the context, if loaded remotely.
|
204
|
+
# @return [RDF::URI] base IRI of the context, if loaded remotely.
|
198
205
|
attr_accessor :context_base
|
199
206
|
|
200
207
|
# Term definitions
|
@@ -252,8 +259,6 @@ module JSON::LD
|
|
252
259
|
# The callback of the loader to be used to retrieve remote documents and contexts. If specified, it must be used to retrieve remote documents and contexts; otherwise, if not specified, the processor's built-in loader must be used. See {API.documentLoader} for the method signature.
|
253
260
|
# @option options [Hash{Symbol => String}] :prefixes
|
254
261
|
# See `RDF::Reader#initialize`
|
255
|
-
# @option options [Boolean] :simple_compact_iris (false)
|
256
|
-
# When compacting IRIs, do not use terms with expanded term definitions
|
257
262
|
# @option options [String, #to_s] :vocab
|
258
263
|
# Initial value for @vocab
|
259
264
|
# @option options [String, #to_s] :language
|
@@ -281,8 +286,7 @@ module JSON::LD
|
|
281
286
|
(options[:prefixes] || {}).each_pair do |k, v|
|
282
287
|
next if k.nil?
|
283
288
|
@iri_to_term[v.to_s] = k
|
284
|
-
@term_definitions[k.to_s] = TermDefinition.new(k, id: v.to_s)
|
285
|
-
@term_definitions[k.to_s].simple = true
|
289
|
+
@term_definitions[k.to_s] = TermDefinition.new(k, id: v.to_s, simple: true, prefix: true)
|
286
290
|
end
|
287
291
|
|
288
292
|
self.vocab = options[:vocab] if options[:vocab]
|
@@ -441,7 +445,7 @@ module JSON::LD
|
|
441
445
|
end
|
442
446
|
raise JsonLdError::InvalidRemoteContext, "#{context}" unless jo.is_a?(Hash) && jo.has_key?('@context')
|
443
447
|
context = jo['@context']
|
444
|
-
if
|
448
|
+
if (processingMode || 'json-ld-1.0') <= "json-ld-1.1"
|
445
449
|
context_no_base.provided_context = context.dup
|
446
450
|
end
|
447
451
|
end
|
@@ -563,7 +567,7 @@ module JSON::LD
|
|
563
567
|
# Initialize value to a the value associated with the key term in local context.
|
564
568
|
value = local_context.fetch(term, false)
|
565
569
|
simple_term = value.is_a?(String)
|
566
|
-
value = {'@id' => value} if
|
570
|
+
value = {'@id' => value} if simple_term
|
567
571
|
|
568
572
|
case value
|
569
573
|
when nil, {'@id' => nil}
|
@@ -577,9 +581,9 @@ module JSON::LD
|
|
577
581
|
definition = TermDefinition.new(term)
|
578
582
|
definition.simple = simple_term
|
579
583
|
|
580
|
-
expected_keys = case
|
581
|
-
when "json-ld-1.0" then %w(@
|
582
|
-
else %w(@
|
584
|
+
expected_keys = case processingMode
|
585
|
+
when "json-ld-1.0", nil then %w(@container @id @language @reverse @type)
|
586
|
+
else %w(@container @context @id @language @nest @prefix @reverse @type)
|
583
587
|
end
|
584
588
|
|
585
589
|
extra_keys = value.keys - expected_keys
|
@@ -643,6 +647,11 @@ module JSON::LD
|
|
643
647
|
defined: defined)
|
644
648
|
raise JsonLdError::InvalidKeywordAlias, "expected value of @id to not be @context on term #{term.inspect}" if
|
645
649
|
definition.id == '@context'
|
650
|
+
|
651
|
+
# If id ends with a gen-delim, it may be used as a prefix
|
652
|
+
definition.prefix = true if !term.include?(':') &&
|
653
|
+
definition.id.to_s.end_with?(*%w(: / ? # [ ] @)) &&
|
654
|
+
(simple_term || ((processingMode || 'json-ld-1.0') == 'json-ld-1.0'))
|
646
655
|
elsif term.include?(':')
|
647
656
|
# If term is a compact IRI with a prefix that is a key in local context then a dependency has been found. Use this algorithm recursively passing active context, local context, the prefix as term, and defined.
|
648
657
|
prefix, suffix = term.split(':')
|
@@ -671,9 +680,6 @@ module JSON::LD
|
|
671
680
|
end
|
672
681
|
|
673
682
|
if value.has_key?('@context')
|
674
|
-
# Not supported in JSON-LD 1.0
|
675
|
-
raise JsonLdError::InvalidTermDefinition, '@context not valid in term definition for JSON-LD 1.0 on term #{term.inspect}, set processing mode using @version' if processingMode < 'json-ld-1.1'
|
676
|
-
|
677
683
|
begin
|
678
684
|
self.parse(value['@context'])
|
679
685
|
definition.context = value['@context']
|
@@ -691,12 +697,6 @@ module JSON::LD
|
|
691
697
|
end
|
692
698
|
|
693
699
|
if value.has_key?('@nest')
|
694
|
-
# Not supported in JSON-LD 1.0
|
695
|
-
raise JsonLdError::InvalidTermDefinition, '@nest not valid in term definition for JSON-LD 1.0 on term #{term.inspect}, set processing mode using @version' if processingMode < 'json-ld-1.1'
|
696
|
-
|
697
|
-
# Not supported in JSON-LD 1.0
|
698
|
-
raise JsonLdError::InvalidTermDefinition, '@nest not valid in term definition for JSON-LD 1.0 on term #{term.inspect}, set processing mode using @version' if processingMode < 'json-ld-1.1'
|
699
|
-
|
700
700
|
nest = value['@nest']
|
701
701
|
raise JsonLdError::InvalidNestValue, "nest must be a string, was #{nest.inspect}} on term #{term.inspect}" unless nest.is_a?(String)
|
702
702
|
raise JsonLdError::InvalidNestValue, "nest must not be a keyword other than @nest, was #{nest.inspect}} on term #{term.inspect}" if nest.start_with?('@') && nest != '@nest'
|
@@ -704,6 +704,16 @@ module JSON::LD
|
|
704
704
|
definition.nest = nest
|
705
705
|
end
|
706
706
|
|
707
|
+
if value.has_key?('@prefix')
|
708
|
+
raise JsonLdError::InvalidTermDefinition, "@prefix used on compact IRI term #{term.inspect}" if term.include?(':')
|
709
|
+
case pfx = value['@prefix']
|
710
|
+
when TrueClass, FalseClass
|
711
|
+
definition.prefix = pfx
|
712
|
+
else
|
713
|
+
raise JsonLdError::InvalidPrefixValue, "unknown value for '@prefix': #{pfx.inspect} on term #{term.inspect}"
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
707
717
|
term_definitions[term] = definition
|
708
718
|
defined[term] = true
|
709
719
|
else
|
@@ -839,7 +849,7 @@ module JSON::LD
|
|
839
849
|
def set_mapping(term, value)
|
840
850
|
#log_debug("") {"map #{term.inspect} to #{value.inspect}"}
|
841
851
|
term = term.to_s
|
842
|
-
term_definitions[term] = TermDefinition.new(term, id: value)
|
852
|
+
term_definitions[term] = TermDefinition.new(term, id: value, simple: true, prefix: (value.to_s.end_with?(*%w(: / ? # [ ] @))))
|
843
853
|
term_definitions[term].simple = true
|
844
854
|
|
845
855
|
term_sym = term.empty? ? "" : term.to_sym
|
@@ -1052,7 +1062,7 @@ module JSON::LD
|
|
1052
1062
|
|
1053
1063
|
if vocab && inverse_context.has_key?(iri)
|
1054
1064
|
#log_debug("") {"vocab and key in inverse context"} unless quiet
|
1055
|
-
default_language = self.default_language || @none
|
1065
|
+
default_language = self.default_language || "@none"
|
1056
1066
|
containers = []
|
1057
1067
|
tl, tl_value = "@language", "@null"
|
1058
1068
|
|
@@ -1136,7 +1146,8 @@ module JSON::LD
|
|
1136
1146
|
preferred_values.concat(%w(@id @vocab @none))
|
1137
1147
|
end
|
1138
1148
|
else
|
1139
|
-
|
1149
|
+
tl = '@any' if list?(value) && value['@list'].empty?
|
1150
|
+
preferred_values.concat([tl_value, '@none'].compact)
|
1140
1151
|
end
|
1141
1152
|
#log_debug("") {"preferred_values: #{preferred_values.inspect}"} unless quiet
|
1142
1153
|
if p_term = select_term(iri, containers, tl, preferred_values)
|
@@ -1156,21 +1167,17 @@ module JSON::LD
|
|
1156
1167
|
candidates = []
|
1157
1168
|
|
1158
1169
|
term_definitions.each do |term, td|
|
1159
|
-
next if term.include?(":")
|
1160
1170
|
next if td.nil? || td.id.nil? || td.id == iri || !iri.start_with?(td.id)
|
1161
1171
|
|
1162
|
-
#
|
1163
|
-
next
|
1172
|
+
# Skip term if `@prefix` is not true in term definition
|
1173
|
+
next unless td.prefix?
|
1164
1174
|
|
1165
1175
|
suffix = iri[td.id.length..-1]
|
1166
1176
|
ciri = "#{term}:#{suffix}"
|
1167
1177
|
candidates << ciri unless value && term_definitions.has_key?(ciri)
|
1168
1178
|
end
|
1169
1179
|
|
1170
|
-
if !candidates.empty?
|
1171
|
-
#log_debug("") {"=> compact iri: #{candidates.term_sort.first.inspect}"} unless quiet
|
1172
|
-
return candidates.term_sort.first
|
1173
|
-
end
|
1180
|
+
return candidates.term_sort.first if !candidates.empty?
|
1174
1181
|
|
1175
1182
|
# If we still don't have any terms and we're using standard_prefixes,
|
1176
1183
|
# try those, and add to mapping
|
@@ -1183,10 +1190,7 @@ module JSON::LD
|
|
1183
1190
|
iri.sub(v.to_uri.to_s, "#{prefix}:").sub(/:$/, '')
|
1184
1191
|
end
|
1185
1192
|
|
1186
|
-
if !candidates.empty?
|
1187
|
-
#log_debug("") {"=> standard prefies: #{candidates.term_sort.first.inspect}"} unless quiet
|
1188
|
-
return candidates.term_sort.first
|
1189
|
-
end
|
1193
|
+
return candidates.term_sort.first if !candidates.empty?
|
1190
1194
|
end
|
1191
1195
|
|
1192
1196
|
if !vocab
|
@@ -1483,9 +1487,11 @@ module JSON::LD
|
|
1483
1487
|
next unless td = term_definitions[term]
|
1484
1488
|
container = td.container_mapping || (td.as_set ? '@set' : '@none')
|
1485
1489
|
container_map = result[td.id.to_s] ||= {}
|
1486
|
-
tl_map = container_map[container] ||= {'@language' => {}, '@type' => {}}
|
1490
|
+
tl_map = container_map[container] ||= {'@language' => {}, '@type' => {}, '@any' => {}}
|
1487
1491
|
type_map = tl_map['@type']
|
1488
1492
|
language_map = tl_map['@language']
|
1493
|
+
any_map = tl_map['@any']
|
1494
|
+
any_map['@none'] ||= term
|
1489
1495
|
if td.reverse_property
|
1490
1496
|
type_map['@reverse'] ||= term
|
1491
1497
|
elsif td.type_mapping
|
@@ -1598,7 +1604,7 @@ module JSON::LD
|
|
1598
1604
|
# Ensure @container mapping is appropriate
|
1599
1605
|
# The result is the original container definition. For IRI containers, this is necessary to be able to determine the @type mapping for string values
|
1600
1606
|
def check_container(container, local_context, defined, term)
|
1601
|
-
if container.is_a?(Array) &&
|
1607
|
+
if container.is_a?(Array) && (processingMode || 'json-ld-1.0') < 'json-ld-1.1'
|
1602
1608
|
raise JsonLdError::InvalidContainerMapping,
|
1603
1609
|
"'@container' on term #{term.inspect} must be a string: #{container.inspect}"
|
1604
1610
|
end
|
@@ -1619,7 +1625,7 @@ module JSON::LD
|
|
1619
1625
|
when '@type', '@id', nil
|
1620
1626
|
raise JsonLdError::InvalidContainerMapping,
|
1621
1627
|
"unknown mapping for '@container' to #{container.inspect} on term #{term.inspect}" if
|
1622
|
-
|
1628
|
+
(processingMode || 'json-ld-1.0') < 'json-ld-1.1'
|
1623
1629
|
else
|
1624
1630
|
raise JsonLdError::InvalidContainerMapping,
|
1625
1631
|
"unknown mapping for '@container' to #{container.inspect} on term #{term.inspect}"
|
data/lib/json/ld/frame.rb
CHANGED
@@ -224,7 +224,6 @@ module JSON::LD
|
|
224
224
|
output = Hash.new
|
225
225
|
input.each do |key, value|
|
226
226
|
if key == '@preserve'
|
227
|
-
#require 'byebug'; byebug
|
228
227
|
# replace all key-value pairs where the key is @preserve with the value from the key-pair
|
229
228
|
output = cleanup_preserve(value, bnodes_to_clear)
|
230
229
|
elsif context.expand_iri(key) == '@id' && bnodes_to_clear.include?(value)
|
data/lib/json/ld/writer.rb
CHANGED
@@ -77,6 +77,11 @@ module JSON::LD
|
|
77
77
|
datatype: TrueClass,
|
78
78
|
on: ["--compact-arrays"],
|
79
79
|
description: "Replaces arrays with just one element with that element during compaction.") {true},
|
80
|
+
RDF::CLI::Option.new(
|
81
|
+
symbol: :compactToRelative,
|
82
|
+
datatype: TrueClass,
|
83
|
+
on: ["--compact-to-relative"],
|
84
|
+
description: "Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded. Default is `true` use --no-compact-to-relative to disable.") {true},
|
80
85
|
RDF::CLI::Option.new(
|
81
86
|
symbol: :context,
|
82
87
|
datatype: RDF::URI,
|
data/spec/compact_spec.rb
CHANGED
@@ -299,6 +299,69 @@ describe JSON::LD::API do
|
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
302
|
+
context "IRI Compaction" do
|
303
|
+
{
|
304
|
+
"Expands and compacts to document base in 1.0" => {
|
305
|
+
input: %({
|
306
|
+
"@id": "a",
|
307
|
+
"http://example.com/b": {"@id": "c"}
|
308
|
+
}),
|
309
|
+
context: %({"b": "http://example.com/b"}),
|
310
|
+
output: %({
|
311
|
+
"@context": {"b": "http://example.com/b"},
|
312
|
+
"@id": "a",
|
313
|
+
"b": {"@id": "c"}
|
314
|
+
}),
|
315
|
+
base: "http://example.org/"
|
316
|
+
},
|
317
|
+
"Expands and compacts to document base in 1.1 with compactToRelative true" => {
|
318
|
+
input: %({
|
319
|
+
"@id": "a",
|
320
|
+
"http://example.com/b": {"@id": "c"}
|
321
|
+
}),
|
322
|
+
context: %({"b": "http://example.com/b"}),
|
323
|
+
output: %({
|
324
|
+
"@context": {"b": "http://example.com/b"},
|
325
|
+
"@id": "a",
|
326
|
+
"b": {"@id": "c"}
|
327
|
+
}),
|
328
|
+
base: "http://example.org/",
|
329
|
+
compactToRelative: true,
|
330
|
+
processingMode: 'json-ld-1.1'
|
331
|
+
},
|
332
|
+
"Expands but does not compact to document base in 1.1 with compactToRelative false" => {
|
333
|
+
input: %({
|
334
|
+
"@id": "http://example.org/a",
|
335
|
+
"http://example.com/b": {"@id": "http://example.org/c"}
|
336
|
+
}),
|
337
|
+
context: %({"b": "http://example.com/b"}),
|
338
|
+
output: %({
|
339
|
+
"@context": {"b": "http://example.com/b"},
|
340
|
+
"@id": "http://example.org/a",
|
341
|
+
"b": {"@id": "http://example.org/c"}
|
342
|
+
}),
|
343
|
+
compactToRelative: false,
|
344
|
+
processingMode: 'json-ld-1.1'
|
345
|
+
},
|
346
|
+
"Expands and compacts to document base in 1.1 by default" => {
|
347
|
+
input: %({
|
348
|
+
"@id": "a",
|
349
|
+
"http://example.com/b": {"@id": "c"}
|
350
|
+
}),
|
351
|
+
context: %({"b": "http://example.com/b"}),
|
352
|
+
output: %({
|
353
|
+
"@context": {"b": "http://example.com/b"},
|
354
|
+
"@id": "a",
|
355
|
+
"b": {"@id": "c"}
|
356
|
+
}),
|
357
|
+
base: "http://example.org/",
|
358
|
+
processingMode: 'json-ld-1.1'
|
359
|
+
},
|
360
|
+
}.each_pair do |title, params|
|
361
|
+
it(title) {run_compact(params)}
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
302
365
|
context "@container: @reverse" do
|
303
366
|
{
|
304
367
|
"@container: @reverse" => {
|
@@ -1084,6 +1147,7 @@ describe JSON::LD::API do
|
|
1084
1147
|
"foo": {"@context": {"bar": "http://example.org/bar"}}
|
1085
1148
|
}),
|
1086
1149
|
processingMode: nil,
|
1150
|
+
validate: true,
|
1087
1151
|
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
1088
1152
|
},
|
1089
1153
|
}.each_pair do |title, params|
|
@@ -1244,6 +1308,7 @@ describe JSON::LD::API do
|
|
1244
1308
|
"Foo": {"@context": {"bar": "http://example.org/bar"}}
|
1245
1309
|
}),
|
1246
1310
|
processingMode: nil,
|
1311
|
+
validate: true,
|
1247
1312
|
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
1248
1313
|
},
|
1249
1314
|
}.each_pair do |title, params|
|
@@ -1272,18 +1337,107 @@ describe JSON::LD::API do
|
|
1272
1337
|
it(title) {run_compact(params)}
|
1273
1338
|
end
|
1274
1339
|
end
|
1340
|
+
|
1341
|
+
context "compact IRI selection" do
|
1342
|
+
{
|
1343
|
+
"compacts using expanded term in 1.0" => {
|
1344
|
+
input: %({"http://example.org/foo": "term"}),
|
1345
|
+
context: %({"ex": {"@id": "http://example.org/"}}),
|
1346
|
+
output: %({
|
1347
|
+
"@context": {"ex": {"@id": "http://example.org/"}},
|
1348
|
+
"ex:foo": "term"
|
1349
|
+
}),
|
1350
|
+
processingMode: "json-ld-1.0"
|
1351
|
+
},
|
1352
|
+
"does not compact using expanded term in 1.1" => {
|
1353
|
+
input: %({"http://example.org/foo": "term"}),
|
1354
|
+
context: %({"ex": {"@id": "http://example.org/"}}),
|
1355
|
+
output: %({
|
1356
|
+
"@context": {"ex": {"@id": "http://example.org/"}},
|
1357
|
+
"http://example.org/foo": "term"
|
1358
|
+
}),
|
1359
|
+
processingMode: "json-ld-1.1"
|
1360
|
+
},
|
1361
|
+
"does not compact using simple term not ending in gen-delim" => {
|
1362
|
+
input: %({"http://example.org/foo": "term"}),
|
1363
|
+
context: %({"ex": "http://example.org/f"}),
|
1364
|
+
output: %({
|
1365
|
+
"@context": {"ex": "http://example.org/f"},
|
1366
|
+
"http://example.org/foo": "term"
|
1367
|
+
})
|
1368
|
+
},
|
1369
|
+
"compacts using simple term ending in gen-delim ('/')" => {
|
1370
|
+
input: %({"http://example.org/foo": "term"}),
|
1371
|
+
context: %({"ex": "http://example.org/"}),
|
1372
|
+
output: %({
|
1373
|
+
"@context": {"ex": "http://example.org/"},
|
1374
|
+
"ex:foo": "term"
|
1375
|
+
})
|
1376
|
+
},
|
1377
|
+
"compacts using simple term ending in gen-delim (':')" => {
|
1378
|
+
input: %({"http://example.org/foo:bar": "term"}),
|
1379
|
+
context: %({"ex": "http://example.org/foo:"}),
|
1380
|
+
output: %({
|
1381
|
+
"@context": {"ex": "http://example.org/foo:"},
|
1382
|
+
"ex:bar": "term"
|
1383
|
+
})
|
1384
|
+
},
|
1385
|
+
"compacts using simple term ending in gen-delim ('?')" => {
|
1386
|
+
input: %({"http://example.org/foo?bar": "term"}),
|
1387
|
+
context: %({"ex": "http://example.org/foo?"}),
|
1388
|
+
output: %({
|
1389
|
+
"@context": {"ex": "http://example.org/foo?"},
|
1390
|
+
"ex:bar": "term"
|
1391
|
+
})
|
1392
|
+
},
|
1393
|
+
"compacts using simple term ending in gen-delim ('#')" => {
|
1394
|
+
input: %({"http://example.org/foo#bar": "term"}),
|
1395
|
+
context: %({"ex": "http://example.org/foo#"}),
|
1396
|
+
output: %({
|
1397
|
+
"@context": {"ex": "http://example.org/foo#"},
|
1398
|
+
"ex:bar": "term"
|
1399
|
+
})
|
1400
|
+
},
|
1401
|
+
"compacts using simple term ending in gen-delim ('[')" => {
|
1402
|
+
input: %({"http://example.org/foo[bar": "term"}),
|
1403
|
+
context: %({"ex": "http://example.org/foo["}),
|
1404
|
+
output: %({
|
1405
|
+
"@context": {"ex": "http://example.org/foo["},
|
1406
|
+
"ex:bar": "term"
|
1407
|
+
})
|
1408
|
+
},
|
1409
|
+
"compacts using simple term ending in gen-delim (']')" => {
|
1410
|
+
input: %({"http://example.org/foo]bar": "term"}),
|
1411
|
+
context: %({"ex": "http://example.org/foo]"}),
|
1412
|
+
output: %({
|
1413
|
+
"@context": {"ex": "http://example.org/foo]"},
|
1414
|
+
"ex:bar": "term"
|
1415
|
+
})
|
1416
|
+
},
|
1417
|
+
"compacts using simple term ending in gen-delim ('@')" => {
|
1418
|
+
input: %({"http://example.org/foo@bar": "term"}),
|
1419
|
+
context: %({"ex": "http://example.org/foo@"}),
|
1420
|
+
output: %({
|
1421
|
+
"@context": {"ex": "http://example.org/foo@"},
|
1422
|
+
"ex:bar": "term"
|
1423
|
+
})
|
1424
|
+
},
|
1425
|
+
}.each do |title, params|
|
1426
|
+
it(title) {run_compact(params)}
|
1427
|
+
end
|
1428
|
+
end
|
1275
1429
|
end
|
1276
1430
|
|
1277
1431
|
def run_compact(params)
|
1278
|
-
input, output, context
|
1432
|
+
input, output, context = params[:input], params[:output], params[:context]
|
1279
1433
|
input = ::JSON.parse(input) if input.is_a?(String)
|
1280
1434
|
output = ::JSON.parse(output) if output.is_a?(String)
|
1281
1435
|
context = ::JSON.parse(context) if context.is_a?(String)
|
1282
1436
|
pending params.fetch(:pending, "test implementation") unless input
|
1283
1437
|
if params[:exception]
|
1284
|
-
expect {JSON::LD::API.compact(input, context, logger: logger
|
1438
|
+
expect {JSON::LD::API.compact(input, context, params.merge(logger: logger))}.to raise_error(params[:exception])
|
1285
1439
|
else
|
1286
|
-
jld = JSON::LD::API.compact(input, context, logger: logger
|
1440
|
+
jld = JSON::LD::API.compact(input, context, params.merge(logger: logger))
|
1287
1441
|
expect(jld).to produce(output, logger)
|
1288
1442
|
end
|
1289
1443
|
end
|
data/spec/context_spec.rb
CHANGED
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
describe JSON::LD::Context do
|
26
26
|
let(:logger) {RDF::Spec.logger}
|
27
|
-
let(:context) {JSON::LD::Context.new(logger: logger, validate: true, processingMode: "json-ld-1.1")}
|
27
|
+
let(:context) {JSON::LD::Context.new(logger: logger, validate: true, processingMode: "json-ld-1.1", compactToRelative: true)}
|
28
28
|
let(:remote_doc) do
|
29
29
|
JSON::LD::API::RemoteDocument.new("http://example.com/context", %q({
|
30
30
|
"@context": {
|
@@ -76,11 +76,11 @@ describe JSON::LD::Context do
|
|
76
76
|
"avatar" => "http://xmlns.com/foaf/0.1/avatar"
|
77
77
|
}, logger)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "notes non-existing @context" do
|
81
81
|
expect {subject.parse(StringIO.new("{}"))}.to raise_error(JSON::LD::JsonLdError::InvalidRemoteContext)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it "parses a referenced context at a relative URI" do
|
85
85
|
rd1 = JSON::LD::API::RemoteDocument.new("http://example.com/c1", %({"@context": "context"}))
|
86
86
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/c1", anything).and_yield(rd1)
|
@@ -302,7 +302,7 @@ describe JSON::LD::Context do
|
|
302
302
|
expect(nil_ec.coercions).to eq init_ec.coercions
|
303
303
|
expect(nil_ec.containers).to eq init_ec.containers
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
it "removes a term definition" do
|
307
307
|
expect(subject.parse({"name" => nil}).send(:mapping, "name")).to be_nil
|
308
308
|
end
|
@@ -322,11 +322,14 @@ describe JSON::LD::Context do
|
|
322
322
|
"@type as @list" => {"foo" => {"@type" => "@list"}},
|
323
323
|
"@type as @set" => {"foo" => {"@type" => "@set"}},
|
324
324
|
"@container as object" => {"foo" => {"@container" => {}}},
|
325
|
-
"@container as array" => {"foo" => {"@container" => []}},
|
325
|
+
"@container as empty array" => {"foo" => {"@container" => []}},
|
326
326
|
"@container as string" => {"foo" => {"@container" => "true"}},
|
327
327
|
"@context which is invalid" => {"foo" => {"@context" => {"bar" => []}}},
|
328
328
|
"@language as @id" => {"@language" => {"@id" => "http://example.com/"}},
|
329
329
|
"@vocab as @id" => {"@vocab" => {"@id" => "http://example.com/"}},
|
330
|
+
"@prefix string" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => "str"}},
|
331
|
+
"@prefix array" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => []}},
|
332
|
+
"@prefix object" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => {}}},
|
330
333
|
}.each do |title, context|
|
331
334
|
it title do
|
332
335
|
expect {
|
@@ -335,7 +338,25 @@ describe JSON::LD::Context do
|
|
335
338
|
}.to raise_error(JSON::LD::JsonLdError)
|
336
339
|
end
|
337
340
|
end
|
338
|
-
|
341
|
+
|
342
|
+
context "1.0" do
|
343
|
+
let(:context) {JSON::LD::Context.new(logger: logger, validate: true)}
|
344
|
+
{
|
345
|
+
"@context" => {"foo" => {"@id" => 'http://example.org/', "@context" => {}}},
|
346
|
+
"@container @id" => {"foo" => {"@container" => "@id"}},
|
347
|
+
"@container @type" => {"foo" => {"@container" => "@type"}},
|
348
|
+
"@nest" => {"foo" => {"@id" => 'http://example.org/', "@nest" => "@nest"}},
|
349
|
+
"@prefix" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => true}},
|
350
|
+
}.each do |title, context|
|
351
|
+
it title do
|
352
|
+
expect {
|
353
|
+
ec = subject.parse(context)
|
354
|
+
expect(ec.serialize).to produce({}, logger)
|
355
|
+
}.to raise_error(JSON::LD::JsonLdError)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
339
360
|
(JSON::LD::KEYWORDS - %w(@base @language @vocab)).each do |kw|
|
340
361
|
it "does not redefine #{kw} as a string" do
|
341
362
|
expect {
|
@@ -807,7 +828,7 @@ describe JSON::LD::Context do
|
|
807
828
|
end
|
808
829
|
end
|
809
830
|
end
|
810
|
-
|
831
|
+
|
811
832
|
context "@vocab" do
|
812
833
|
{
|
813
834
|
"absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
|
@@ -858,7 +879,7 @@ describe JSON::LD::Context do
|
|
858
879
|
"unmapped" => ["foo", "foo"],
|
859
880
|
"bnode" => ["_:a", RDF::Node("a")],
|
860
881
|
"relative" => ["foo/bar", "http://base/foo/bar"],
|
861
|
-
"odd CURIE" => ["
|
882
|
+
"odd CURIE" => ["ex:perts", "http://example.org/perts"]
|
862
883
|
}.each do |title, (result, input)|
|
863
884
|
it title do
|
864
885
|
expect(subject.compact_iri(input)).to produce(result, logger)
|
@@ -904,7 +925,7 @@ describe JSON::LD::Context do
|
|
904
925
|
subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
|
905
926
|
subject.set_mapping("ex", nil)
|
906
927
|
expect(subject.compact_iri("http://example.org/name", position: :predicate)).
|
907
|
-
|
928
|
+
not_to produce("name", logger)
|
908
929
|
end
|
909
930
|
end
|
910
931
|
|
@@ -963,7 +984,7 @@ describe JSON::LD::Context do
|
|
963
984
|
[{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => true}],
|
964
985
|
[{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
|
965
986
|
[{"@value" => "de", "@language" => "de"}, {"@value" => "jp", "@language" => "jp"}],
|
966
|
-
[{"@value" => true}], [{"@value" => false}],
|
987
|
+
[{"@value" => true}], [{"@value" => false}],
|
967
988
|
[{"@value" => 1}], [{"@value" => 1.1}],
|
968
989
|
],
|
969
990
|
"listlang" => [[{"@value" => "en", "@language" => "en"}]],
|
@@ -984,9 +1005,7 @@ describe JSON::LD::Context do
|
|
984
1005
|
end
|
985
1006
|
end
|
986
1007
|
|
987
|
-
context "
|
988
|
-
before(:each) { subject.instance_variable_get(:@options)[:simple_compact_iris] = true}
|
989
|
-
|
1008
|
+
context "CURIE compaction" do
|
990
1009
|
{
|
991
1010
|
"nil" => [nil, nil],
|
992
1011
|
"absolute IRI" => ["http://example.com/", "http://example.com/"],
|
@@ -1223,7 +1242,7 @@ describe JSON::LD::Context do
|
|
1223
1242
|
end
|
1224
1243
|
end
|
1225
1244
|
end
|
1226
|
-
|
1245
|
+
|
1227
1246
|
context "coercion" do
|
1228
1247
|
before(:each) {subject.default_language = "en"}
|
1229
1248
|
{
|
data/spec/expand_spec.rb
CHANGED
@@ -83,7 +83,16 @@ describe JSON::LD::API do
|
|
83
83
|
"@value with false" => {
|
84
84
|
input: {"http://example.com/ex" => {"@value" => false}},
|
85
85
|
output: [{"http://example.com/ex" => [{"@value" => false}]}]
|
86
|
-
}
|
86
|
+
},
|
87
|
+
"compact IRI" => {
|
88
|
+
input: {
|
89
|
+
"@context" => {"ex" => "http://example.com/"},
|
90
|
+
"ex:p" => {"@id" => "ex:Sub1"}
|
91
|
+
},
|
92
|
+
output: [{
|
93
|
+
"http://example.com/p" => [{"@id" => "http://example.com/Sub1"}]
|
94
|
+
}]
|
95
|
+
},
|
87
96
|
}.each_pair do |title, params|
|
88
97
|
it(title) {run_expand params}
|
89
98
|
end
|
@@ -1201,6 +1210,7 @@ describe JSON::LD::API do
|
|
1201
1210
|
}
|
1202
1211
|
}),
|
1203
1212
|
processingMode: nil,
|
1213
|
+
validate: true,
|
1204
1214
|
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
1205
1215
|
},
|
1206
1216
|
}.each do |title, params|
|
@@ -1323,6 +1333,7 @@ describe JSON::LD::API do
|
|
1323
1333
|
}
|
1324
1334
|
}),
|
1325
1335
|
processingMode: nil,
|
1336
|
+
validate: true,
|
1326
1337
|
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
1327
1338
|
},
|
1328
1339
|
}.each do |title, params|
|
@@ -1452,6 +1463,7 @@ describe JSON::LD::API do
|
|
1452
1463
|
"a": {"@type": "Foo", "bar": "baz"}
|
1453
1464
|
}),
|
1454
1465
|
processingMode: nil,
|
1466
|
+
validate: true,
|
1455
1467
|
exception: JSON::LD::JsonLdError::InvalidTermDefinition
|
1456
1468
|
},
|
1457
1469
|
}.each do |title, params|
|
@@ -1622,7 +1634,7 @@ describe JSON::LD::API do
|
|
1622
1634
|
output = ::JSON.parse(output) if output.is_a?(String)
|
1623
1635
|
pending params.fetch(:pending, "test implementation") unless input
|
1624
1636
|
if params[:exception]
|
1625
|
-
expect {JSON::LD::API.expand(input, processingMode: processingMode)}.to raise_error(params[:exception])
|
1637
|
+
expect {JSON::LD::API.expand(input, {processingMode: processingMode}.merge(params))}.to raise_error(params[:exception])
|
1626
1638
|
else
|
1627
1639
|
jld = JSON::LD::API.expand(input, base: params[:base], logger: logger, processingMode: processingMode)
|
1628
1640
|
expect(jld).to produce(output, logger)
|
data/spec/suite_helper.rb
CHANGED
@@ -108,7 +108,7 @@ module Fixtures
|
|
108
108
|
def options
|
109
109
|
@options ||= begin
|
110
110
|
opts = {documentLoader: Fixtures::SuiteTest.method(:documentLoader)}
|
111
|
-
(property('option') || {}).each do |k, v|
|
111
|
+
{'specVersion' => "1.1"}.merge(property('option') || {}).each do |k, v|
|
112
112
|
opts[k.to_sym] = v
|
113
113
|
end
|
114
114
|
opts
|
@@ -162,6 +162,11 @@ module Fixtures
|
|
162
162
|
end
|
163
163
|
options = {validate: true}.merge(options)
|
164
164
|
|
165
|
+
unless options[:specVersion] == "1.1"
|
166
|
+
skip "not a 1.1 test"
|
167
|
+
return
|
168
|
+
end
|
169
|
+
|
165
170
|
if positiveTest?
|
166
171
|
logger.info "expected: #{expect rescue nil}" if expect_loc
|
167
172
|
begin
|
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: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: jsonlint
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -343,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
343
343
|
version: '0'
|
344
344
|
requirements: []
|
345
345
|
rubyforge_project: json-ld
|
346
|
-
rubygems_version: 2.6.
|
346
|
+
rubygems_version: 2.6.12
|
347
347
|
signing_key:
|
348
348
|
specification_version: 4
|
349
349
|
summary: JSON-LD reader/writer for Ruby.
|