json-ld 3.0.0 → 3.0.1
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 +28 -16
- data/lib/json/ld/compact.rb +10 -9
- data/lib/json/ld/context.rb +3 -3
- data/lib/json/ld/expand.rb +1 -1
- data/lib/json/ld/extensions.rb +6 -6
- data/lib/json/ld/flatten.rb +3 -1
- data/lib/json/ld/frame.rb +10 -8
- data/lib/json/ld/from_rdf.rb +5 -3
- data/lib/json/ld/reader.rb +1 -1
- data/lib/json/ld/writer.rb +25 -15
- data/spec/api_spec.rb +3 -3
- data/spec/compact_spec.rb +7 -2
- data/spec/expand_spec.rb +30 -4
- data/spec/flatten_spec.rb +1 -1
- data/spec/frame_spec.rb +73 -86
- data/spec/from_rdf_spec.rb +88 -77
- data/spec/matchers.rb +20 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/streaming_writer_spec.rb +1 -1
- data/spec/suite_compact_spec.rb +7 -1
- data/spec/suite_expand_spec.rb +7 -1
- data/spec/suite_flatten_spec.rb +7 -2
- data/spec/suite_frame_spec.rb +8 -2
- data/spec/suite_from_rdf_spec.rb +7 -1
- data/spec/suite_helper.rb +42 -12
- data/spec/suite_remote_doc_spec.rb +7 -1
- data/spec/support/extensions.rb +31 -1
- data/spec/writer_spec.rb +8 -8
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f16239f3f6fc54a6a0e1e6a68d097ba97bb268893f3160df3fe86b4ac6170e
|
4
|
+
data.tar.gz: f21243bfcf58a41dd1a091ac9a92664be80e4e8a813ed9630285f1f96ead4f4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9890153889067a1d87707aac9b52cc6b914dcf0372253d51ba3e496b97f87f5b0bfaa07091513c1f3e3e8b23852151f7b221ef21e5d83e94f59cff3079120fd9
|
7
|
+
data.tar.gz: 0e6240f1d3e02b145a7a786a14770c181700e777d99bf7af924d50af221074ccf2e0fb20659cfc5c061ef9c5550acb397c433b029f115f1eba89dd25aa60378e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.1
|
data/lib/json/ld/api.rb
CHANGED
@@ -71,6 +71,8 @@ module JSON::LD
|
|
71
71
|
# A context that is used to initialize the active context when expanding a document.
|
72
72
|
# @option options [Boolean, String, RDF::URI] :flatten
|
73
73
|
# If set to a value that is not `false`, the JSON-LD processor must modify the output of the Compaction Algorithm or the Expansion Algorithm by coalescing all properties associated with each subject via the Flattening Algorithm. The value of `flatten must` be either an _IRI_ value representing the name of the graph to flatten, or `true`. If the value is `true`, then the first graph encountered in the input document is selected and flattened.
|
74
|
+
# @option options [String] :language
|
75
|
+
# When set, this has the effect of inserting a context definition with `@language` set to the associated value, creating a default language for interpreting string values.
|
74
76
|
# @option options [String] :processingMode
|
75
77
|
# Processing mode, json-ld-1.0 or json-ld-1.1.
|
76
78
|
# If `processingMode` is not specified, a mode of `json-ld-1.0` or `json-ld-1.1` is set, the context used for `expansion` or `compaction`.
|
@@ -80,12 +82,15 @@ module JSON::LD
|
|
80
82
|
# Use unique bnode identifiers, defaults to using the identifier which the node was originally initialized with (if any).
|
81
83
|
# @option options [Symbol] :adapter used with MultiJson
|
82
84
|
# @option options [Boolean] :validate Validate input, if a string or readable object.
|
85
|
+
# @option options [Boolean] :ordered (true)
|
86
|
+
# Order traversal of dictionary members by key when performing algorithms.
|
83
87
|
# @yield [api]
|
84
88
|
# @yieldparam [API]
|
85
89
|
# @raise [JsonLdError]
|
86
90
|
def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **options, &block)
|
87
91
|
@options = {
|
88
92
|
compactArrays: true,
|
93
|
+
ordered: false,
|
89
94
|
documentLoader: self.class.method(:documentLoader)
|
90
95
|
}.merge(options)
|
91
96
|
@namer = unique_bnodes ? BlankNodeUniqer.new : (rename_bnodes ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
|
@@ -161,11 +166,11 @@ module JSON::LD
|
|
161
166
|
# @return [Object, Array<Hash>]
|
162
167
|
# If a block is given, the result of evaluating the block is returned, otherwise, the expanded JSON-LD document
|
163
168
|
# @see http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
|
164
|
-
def self.expand(input,
|
169
|
+
def self.expand(input, framing: false, **options, &block)
|
165
170
|
result, doc_base = nil
|
166
171
|
API.new(input, options[:expandContext], options) do
|
167
172
|
result = self.expand(self.value, nil, self.context,
|
168
|
-
ordered: ordered,
|
173
|
+
ordered: @options[:ordered],
|
169
174
|
framing: framing)
|
170
175
|
doc_base = @options[:base]
|
171
176
|
end
|
@@ -216,14 +221,14 @@ module JSON::LD
|
|
216
221
|
|
217
222
|
# 1) Perform the Expansion Algorithm on the JSON-LD input.
|
218
223
|
# This removes any existing context to allow the given context to be cleanly applied.
|
219
|
-
expanded_input = expanded ? input : API.expand(input, options) do |res, base_iri|
|
224
|
+
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false)) do |res, base_iri|
|
220
225
|
options[:base] ||= base_iri if options[:compactToRelative]
|
221
226
|
res
|
222
227
|
end
|
223
228
|
|
224
229
|
API.new(expanded_input, context, no_default_base: true, **options) do
|
225
230
|
log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
|
226
|
-
result = compact(value)
|
231
|
+
result = compact(value, ordered: @options[:ordered])
|
227
232
|
|
228
233
|
# xxx) Add the given context to the output
|
229
234
|
ctx = self.context.serialize
|
@@ -274,23 +279,23 @@ module JSON::LD
|
|
274
279
|
create_node_map(value, graph_maps)
|
275
280
|
|
276
281
|
default_graph = graph_maps['@default']
|
277
|
-
graph_maps.keys.
|
282
|
+
graph_maps.keys.opt_sort(ordered: @options[:ordered]).each do |graph_name|
|
278
283
|
next if graph_name == '@default'
|
279
284
|
|
280
285
|
graph = graph_maps[graph_name]
|
281
286
|
entry = default_graph[graph_name] ||= {'@id' => graph_name}
|
282
287
|
nodes = entry['@graph'] ||= []
|
283
|
-
graph.keys.
|
288
|
+
graph.keys.opt_sort(ordered: @options[:ordered]).each do |id|
|
284
289
|
nodes << graph[id] unless node_reference?(graph[id])
|
285
290
|
end
|
286
291
|
end
|
287
|
-
default_graph.keys.
|
292
|
+
default_graph.keys.opt_sort(ordered: @options[:ordered]).each do |id|
|
288
293
|
flattened << default_graph[id] unless node_reference?(default_graph[id])
|
289
294
|
end
|
290
295
|
|
291
296
|
if context && !flattened.empty?
|
292
297
|
# Otherwise, return the result of compacting flattened according the Compaction algorithm passing context ensuring that the compaction result uses the @graph keyword (or its alias) at the top-level, even if the context is empty or if there is only one element to put in the @graph array. This ensures that the returned document has a deterministic structure.
|
293
|
-
compacted = as_array(compact(flattened))
|
298
|
+
compacted = as_array(compact(flattened, ordered: @options[:ordered]))
|
294
299
|
kwgraph = self.context.compact_iri('@graph', quiet: true)
|
295
300
|
flattened = self.context.serialize.merge(kwgraph => compacted)
|
296
301
|
end
|
@@ -337,7 +342,6 @@ module JSON::LD
|
|
337
342
|
explicit: false,
|
338
343
|
requireAll: true,
|
339
344
|
omitDefault: false,
|
340
|
-
omitGraph: false,
|
341
345
|
documentLoader: method(:documentLoader)
|
342
346
|
}.merge(options)
|
343
347
|
|
@@ -361,19 +365,24 @@ module JSON::LD
|
|
361
365
|
end
|
362
366
|
|
363
367
|
# Expand input to simplify processing
|
364
|
-
expanded_input = expanded ? input : API.expand(input, options) do |res, base_iri|
|
368
|
+
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false)) do |res, base_iri|
|
365
369
|
options[:base] ||= base_iri if options[:compactToRelative]
|
366
370
|
res
|
367
371
|
end
|
368
372
|
|
369
373
|
# Expand frame to simplify processing
|
370
|
-
expanded_frame = API.expand(frame, framing: true,
|
374
|
+
expanded_frame = API.expand(frame, options.merge(framing: true, ordered: false))
|
371
375
|
|
372
376
|
# Initialize input using frame as context
|
373
377
|
API.new(expanded_input, frame['@context'], no_default_base: true, **options) do
|
374
378
|
log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
|
375
379
|
log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
|
376
380
|
|
381
|
+
# Set omitGraph option, if not present, based on processingMode
|
382
|
+
unless options.has_key?(:omitGraph)
|
383
|
+
options[:omitGraph] = @options[:processingMode] != 'json-ld-1.0'
|
384
|
+
end
|
385
|
+
|
377
386
|
# Get framing nodes from expanded input, replacing Blank Node identifiers as necessary
|
378
387
|
create_node_map(value, framing_state[:graphMap], active_graph: '@default')
|
379
388
|
|
@@ -391,7 +400,7 @@ module JSON::LD
|
|
391
400
|
framing_state[:subjects] = framing_state[:graphMap][framing_state[:graph]]
|
392
401
|
|
393
402
|
result = []
|
394
|
-
frame(framing_state, framing_state[:subjects].keys.
|
403
|
+
frame(framing_state, framing_state[:subjects].keys.opt_sort(ordered: @options[:ordered]), (expanded_frame.first || {}), parent: result, **options)
|
395
404
|
|
396
405
|
# Count blank node identifiers used in the document, if pruning
|
397
406
|
unless @options[:processingMode] == 'json-ld-1.0'
|
@@ -402,7 +411,7 @@ module JSON::LD
|
|
402
411
|
# Initalize context from frame
|
403
412
|
@context = @context.parse(frame['@context'])
|
404
413
|
# Compact result
|
405
|
-
compacted = compact(result)
|
414
|
+
compacted = compact(result, ordered: @options[:ordered])
|
406
415
|
compacted = [compacted] unless options[:omitGraph] || compacted.is_a?(Array)
|
407
416
|
|
408
417
|
# Add the given context to the output
|
@@ -443,7 +452,7 @@ module JSON::LD
|
|
443
452
|
end
|
444
453
|
|
445
454
|
# Expand input to simplify processing
|
446
|
-
expanded_input = expanded ? input : API.expand(input, ordered: false
|
455
|
+
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false))
|
447
456
|
|
448
457
|
API.new(expanded_input, nil, options) do
|
449
458
|
# 1) Perform the Expansion Algorithm on the JSON-LD input.
|
@@ -487,8 +496,11 @@ module JSON::LD
|
|
487
496
|
def self.fromRdf(input, useRdfType: false, useNativeTypes: false, **options, &block)
|
488
497
|
result = nil
|
489
498
|
|
490
|
-
API.new(nil, nil, options) do
|
491
|
-
result =
|
499
|
+
API.new(nil, nil, options) do
|
500
|
+
result = from_statements(input,
|
501
|
+
useRdfType: useRdfType,
|
502
|
+
useNativeTypes: useNativeTypes,
|
503
|
+
ordered: @options[:ordered])
|
492
504
|
end
|
493
505
|
|
494
506
|
block_given? ? yield(result) : result
|
data/lib/json/ld/compact.rb
CHANGED
@@ -9,8 +9,10 @@ module JSON::LD
|
|
9
9
|
#
|
10
10
|
# @param [Array, Hash] element
|
11
11
|
# @param [String] property (nil)
|
12
|
+
# @param [Boolean] ordered (true)
|
13
|
+
# Ensure output objects have keys ordered properly
|
12
14
|
# @return [Array, Hash]
|
13
|
-
def compact(element, property: nil)
|
15
|
+
def compact(element, property: nil, ordered: false)
|
14
16
|
#if property.nil?
|
15
17
|
# log_debug("compact") {"element: #{element.inspect}, ec: #{context.inspect}"}
|
16
18
|
#else
|
@@ -25,7 +27,7 @@ module JSON::LD
|
|
25
27
|
case element
|
26
28
|
when Array
|
27
29
|
#log_debug("") {"Array #{element.inspect}"}
|
28
|
-
result = element.map {|item| compact(item, property: property)}.compact
|
30
|
+
result = element.map {|item| compact(item, property: property, ordered: ordered)}.compact
|
29
31
|
|
30
32
|
# If element has a single member and the active property has no
|
31
33
|
# @container mapping to @list or @set, the compacted value is that
|
@@ -54,7 +56,7 @@ module JSON::LD
|
|
54
56
|
|
55
57
|
# If expanded property is @list and we're contained within a list container, recursively compact this item to an array
|
56
58
|
if list?(element) && context.container(property) == %w(@list)
|
57
|
-
return compact(element['@list'], property: property)
|
59
|
+
return compact(element['@list'], property: property, ordered: ordered)
|
58
60
|
end
|
59
61
|
|
60
62
|
|
@@ -71,7 +73,7 @@ module JSON::LD
|
|
71
73
|
self.context = context.parse(term_context) if term_context
|
72
74
|
end
|
73
75
|
|
74
|
-
element.keys.
|
76
|
+
element.keys.opt_sort(ordered: ordered).each do |expanded_property|
|
75
77
|
expanded_value = element[expanded_property]
|
76
78
|
#log_debug("") {"#{expanded_property}: #{expanded_value.inspect}"}
|
77
79
|
|
@@ -89,7 +91,7 @@ module JSON::LD
|
|
89
91
|
end
|
90
92
|
|
91
93
|
if expanded_property == '@reverse'
|
92
|
-
compacted_value = compact(expanded_value, property: '@reverse')
|
94
|
+
compacted_value = compact(expanded_value, property: '@reverse', ordered: ordered)
|
93
95
|
#log_debug("@reverse") {"compacted_value: #{compacted_value.inspect}"}
|
94
96
|
# handle double-reversed properties
|
95
97
|
compacted_value.each do |prop, value|
|
@@ -110,7 +112,7 @@ module JSON::LD
|
|
110
112
|
|
111
113
|
if expanded_property == '@preserve'
|
112
114
|
# Compact using `property`
|
113
|
-
compacted_value = compact(expanded_value, property: property)
|
115
|
+
compacted_value = compact(expanded_value, property: property, ordered: ordered)
|
114
116
|
#log_debug("@preserve") {"compacted_value: #{compacted_value.inspect}"}
|
115
117
|
|
116
118
|
unless compacted_value.is_a?(Array) && compacted_value.empty?
|
@@ -176,7 +178,7 @@ module JSON::LD
|
|
176
178
|
else expanded_item
|
177
179
|
end
|
178
180
|
|
179
|
-
compacted_item = compact(value, property: item_active_property)
|
181
|
+
compacted_item = compact(value, property: item_active_property, ordered: ordered)
|
180
182
|
#log_debug("") {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
|
181
183
|
|
182
184
|
# handle @list
|
@@ -267,8 +269,7 @@ module JSON::LD
|
|
267
269
|
end
|
268
270
|
end
|
269
271
|
|
270
|
-
|
271
|
-
result.keys.sort.each_with_object({}) {|kk, memo| memo[kk] = result[kk]}
|
272
|
+
result
|
272
273
|
else
|
273
274
|
# For other types, the compacted value is the element value
|
274
275
|
#log_debug("compact") {element.class.to_s}
|
data/lib/json/ld/context.rb
CHANGED
@@ -750,7 +750,7 @@ module JSON::LD
|
|
750
750
|
ctx['@vocab'] = vocab.to_s if vocab
|
751
751
|
|
752
752
|
# Term Definitions
|
753
|
-
term_definitions.keys.
|
753
|
+
term_definitions.keys.each do |term|
|
754
754
|
defn = term_definitions[term].to_context_definition(self)
|
755
755
|
ctx[term] = defn if defn
|
756
756
|
end
|
@@ -1201,7 +1201,7 @@ module JSON::LD
|
|
1201
1201
|
candidates << ciri unless value && term_definitions.has_key?(ciri)
|
1202
1202
|
end
|
1203
1203
|
|
1204
|
-
return candidates.
|
1204
|
+
return candidates.sort.first if !candidates.empty?
|
1205
1205
|
|
1206
1206
|
# If we still don't have any terms and we're using standard_prefixes,
|
1207
1207
|
# try those, and add to mapping
|
@@ -1214,7 +1214,7 @@ module JSON::LD
|
|
1214
1214
|
iri.sub(v.to_uri.to_s, "#{prefix}:").sub(/:$/, '')
|
1215
1215
|
end
|
1216
1216
|
|
1217
|
-
return candidates.
|
1217
|
+
return candidates.sort.first if !candidates.empty?
|
1218
1218
|
end
|
1219
1219
|
|
1220
1220
|
if !vocab
|
data/lib/json/ld/expand.rb
CHANGED
@@ -19,7 +19,7 @@ module JSON::LD
|
|
19
19
|
# @param [Boolean] framing (false)
|
20
20
|
# Special rules for expanding a frame
|
21
21
|
# @return [Array<Hash{String => Object}>]
|
22
|
-
def expand(input, active_property, context, ordered:
|
22
|
+
def expand(input, active_property, context, ordered: false, framing: false)
|
23
23
|
#log_debug("expand") {"input: #{input.inspect}, active_property: #{active_property.inspect}, context: #{context.inspect}"}
|
24
24
|
framing = false if active_property == '@default'
|
25
25
|
result = case input
|
data/lib/json/ld/extensions.rb
CHANGED
@@ -43,11 +43,11 @@ module RDF
|
|
43
43
|
end
|
44
44
|
|
45
45
|
class Array
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
# Optionally order items
|
47
|
+
#
|
48
|
+
# @param [Boolean] ordered
|
49
|
+
# @return [Array]
|
50
|
+
def opt_sort(ordered: false)
|
51
|
+
ordered ? self.sort : self
|
52
52
|
end
|
53
53
|
end
|
data/lib/json/ld/flatten.rb
CHANGED
@@ -18,6 +18,8 @@ module JSON::LD
|
|
18
18
|
# Property within current node
|
19
19
|
# @param [Array] list (nil)
|
20
20
|
# Used when property value is a list
|
21
|
+
# @param [Boolean] ordered (true)
|
22
|
+
# Ensure output objects have keys ordered properly
|
21
23
|
def create_node_map(element, graph_map,
|
22
24
|
active_graph: '@default',
|
23
25
|
active_subject: nil,
|
@@ -110,7 +112,7 @@ module JSON::LD
|
|
110
112
|
active_graph: id)
|
111
113
|
end
|
112
114
|
|
113
|
-
element.keys.
|
115
|
+
element.keys.each do |property|
|
114
116
|
value = element[property]
|
115
117
|
|
116
118
|
property = namer.get_name(property) if blank_node?(property)
|
data/lib/json/ld/frame.rb
CHANGED
@@ -14,13 +14,15 @@ module JSON::LD
|
|
14
14
|
# @param [Array<String>] subjects
|
15
15
|
# The subjects to filter
|
16
16
|
# @param [Hash{String => Object}] frame
|
17
|
-
# @param [
|
18
|
-
# @option options [Hash{String => Object}] :parent (nil)
|
19
|
-
# Parent subject or top-level array
|
20
|
-
# @option options [String] :property (nil)
|
17
|
+
# @param [String] property (nil)
|
21
18
|
# The parent property.
|
19
|
+
# @param [Hash{String => Object}] parent (nil)
|
20
|
+
# Parent subject or top-level array
|
21
|
+
# @param [Boolean] ordered (true)
|
22
|
+
# Ensure output objects have keys ordered properly
|
23
|
+
# @param [Hash{Symbol => Object}] options ({})
|
22
24
|
# @raise [JSON::LD::InvalidFrame]
|
23
|
-
def frame(state, subjects, frame, parent: nil, property: nil, **options)
|
25
|
+
def frame(state, subjects, frame, parent: nil, property: nil, ordered: false, **options)
|
24
26
|
#log_depth do
|
25
27
|
#log_debug("frame") {"subjects: #{subjects.inspect}"}
|
26
28
|
#log_debug("frame") {"frame: #{frame.to_json(JSON_STATE)}"}
|
@@ -45,7 +47,7 @@ module JSON::LD
|
|
45
47
|
matches = filter_subjects(state, subjects, frame, flags)
|
46
48
|
|
47
49
|
# For each id and node from the set of matched subjects ordered by id
|
48
|
-
matches.keys.
|
50
|
+
matches.keys.opt_sort(ordered: ordered).each do |id|
|
49
51
|
subject = matches[id]
|
50
52
|
|
51
53
|
# Note: In order to treat each top-level match as a compartmentalized result, clear the unique embedded subjects map when the property is nil, which only occurs at the top-level.
|
@@ -110,7 +112,7 @@ module JSON::LD
|
|
110
112
|
end
|
111
113
|
|
112
114
|
# iterate over subject properties in order
|
113
|
-
subject.keys.
|
115
|
+
subject.keys.opt_sort(ordered: ordered).each do |prop|
|
114
116
|
objects = subject[prop]
|
115
117
|
|
116
118
|
# copy keywords to output
|
@@ -153,7 +155,7 @@ module JSON::LD
|
|
153
155
|
end
|
154
156
|
|
155
157
|
# handle defaults in order
|
156
|
-
frame.keys.
|
158
|
+
frame.keys.opt_sort(ordered: ordered).each do |prop|
|
157
159
|
next if prop.start_with?('@')
|
158
160
|
|
159
161
|
# if omit default is off, then include default values for properties that appear in the next frame but are not in the matching subject
|
data/lib/json/ld/from_rdf.rb
CHANGED
@@ -14,8 +14,10 @@ module JSON::LD
|
|
14
14
|
# @param [Boolean] useRdfType (false)
|
15
15
|
# If set to `true`, the JSON-LD processor will treat `rdf:type` like a normal property instead of using `@type`.
|
16
16
|
# @param [Boolean] useNativeTypes (false) use native representations
|
17
|
+
# @param [Boolean] ordered (true)
|
18
|
+
# Ensure output objects have keys ordered properly
|
17
19
|
# @return [Array<Hash>] the JSON-LD document in normalized form
|
18
|
-
def from_statements(dataset, useRdfType: false, useNativeTypes: false)
|
20
|
+
def from_statements(dataset, useRdfType: false, useNativeTypes: false, ordered: false)
|
19
21
|
default_graph = {}
|
20
22
|
graph_map = {'@default' => default_graph}
|
21
23
|
referenced_once = {}
|
@@ -118,11 +120,11 @@ module JSON::LD
|
|
118
120
|
end
|
119
121
|
|
120
122
|
result = []
|
121
|
-
default_graph.keys.
|
123
|
+
default_graph.keys.opt_sort(ordered: ordered).each do |subject|
|
122
124
|
node = default_graph[subject]
|
123
125
|
if graph_map.has_key?(subject)
|
124
126
|
node['@graph'] = []
|
125
|
-
graph_map[subject].keys.
|
127
|
+
graph_map[subject].keys.opt_sort(ordered: ordered).each do |s|
|
126
128
|
n = graph_map[subject][s]
|
127
129
|
n.delete(:usages)
|
128
130
|
node['@graph'] << n unless node_reference?(n)
|
data/lib/json/ld/reader.rb
CHANGED
@@ -21,7 +21,7 @@ module JSON::LD
|
|
21
21
|
on: ["--expand-context CONTEXT"],
|
22
22
|
description: "Context to use when expanding.") {|arg| RDF::URI(arg)},
|
23
23
|
RDF::CLI::Option.new(
|
24
|
-
symbol: :
|
24
|
+
symbol: :processingMode,
|
25
25
|
datatype: %w(json-ld-1.0 json-ld-1.1),
|
26
26
|
control: :radio,
|
27
27
|
on: ["--processingMode MODE", %w(json-ld-1.0 json-ld-1.1)],
|
data/lib/json/ld/writer.rb
CHANGED
@@ -75,15 +75,17 @@ module JSON::LD
|
|
75
75
|
RDF::CLI::Option.new(
|
76
76
|
symbol: :compactArrays,
|
77
77
|
datatype: TrueClass,
|
78
|
+
default: true,
|
78
79
|
control: :checkbox,
|
79
|
-
on: ["--compact-arrays"],
|
80
|
-
description: "Replaces arrays with just one element with that element during compaction.") {
|
80
|
+
on: ["--[no-]compact-arrays"],
|
81
|
+
description: "Replaces arrays with just one element with that element during compaction. Default is `true` use --no-compact-arrays to disable.") {|arg| arg},
|
81
82
|
RDF::CLI::Option.new(
|
82
83
|
symbol: :compactToRelative,
|
83
84
|
datatype: TrueClass,
|
85
|
+
default: true,
|
84
86
|
control: :checkbox,
|
85
|
-
on: ["--compact-to-relative"],
|
86
|
-
description: "Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded. Default is `true` use --no-compact-to-relative to disable.") {
|
87
|
+
on: ["--[no-]compact-to-relative"],
|
88
|
+
description: "Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded. Default is `true` use --no-compact-to-relative to disable.") {|arg| arg},
|
87
89
|
RDF::CLI::Option.new(
|
88
90
|
symbol: :context,
|
89
91
|
datatype: RDF::URI,
|
@@ -93,6 +95,7 @@ module JSON::LD
|
|
93
95
|
RDF::CLI::Option.new(
|
94
96
|
symbol: :embed,
|
95
97
|
datatype: %w(@always @last @never),
|
98
|
+
default: '@last',
|
96
99
|
control: :select,
|
97
100
|
on: ["--embed EMBED"],
|
98
101
|
description: "How to embed matched objects (@last).") {|arg| RDF::URI(arg)},
|
@@ -100,16 +103,22 @@ module JSON::LD
|
|
100
103
|
symbol: :explicit,
|
101
104
|
datatype: TrueClass,
|
102
105
|
control: :checkbox,
|
103
|
-
on: ["--explicit"],
|
104
|
-
description: "Only include explicitly declared properties in output (false)") {|arg|
|
106
|
+
on: ["--[no-]explicit"],
|
107
|
+
description: "Only include explicitly declared properties in output (false)") {|arg| arg},
|
105
108
|
RDF::CLI::Option.new(
|
106
109
|
symbol: :omitDefault,
|
107
110
|
datatype: TrueClass,
|
108
111
|
control: :checkbox,
|
109
|
-
on: ["--omitDefault"],
|
110
|
-
description: "Omit missing properties from output (false)") {|arg|
|
112
|
+
on: ["--[no-]omitDefault"],
|
113
|
+
description: "Omit missing properties from output (false)") {|arg| arg},
|
111
114
|
RDF::CLI::Option.new(
|
112
|
-
symbol: :
|
115
|
+
symbol: :ordered,
|
116
|
+
datatype: TrueClass,
|
117
|
+
control: :checkbox,
|
118
|
+
on: ["--[no-]ordered"],
|
119
|
+
description: "Order object member processing lexographically.") {|arg| arg},
|
120
|
+
RDF::CLI::Option.new(
|
121
|
+
symbol: :processingMode,
|
113
122
|
datatype: %w(json-ld-1.0 json-ld-1.1),
|
114
123
|
control: :radio,
|
115
124
|
on: ["--processingMode MODE", %w(json-ld-1.0 json-ld-1.1)],
|
@@ -117,21 +126,22 @@ module JSON::LD
|
|
117
126
|
RDF::CLI::Option.new(
|
118
127
|
symbol: :requireAll,
|
119
128
|
datatype: TrueClass,
|
129
|
+
default: true,
|
120
130
|
control: :checkbox,
|
121
|
-
on: ["--requireAll"],
|
122
|
-
description: "Require all properties to match (true)") {|arg|
|
131
|
+
on: ["--[no-]requireAll"],
|
132
|
+
description: "Require all properties to match (true). Default is `true` use --no-compact-to-relative to disable.") {|arg| arg},
|
123
133
|
RDF::CLI::Option.new(
|
124
134
|
symbol: :stream,
|
125
135
|
datatype: TrueClass,
|
126
136
|
control: :checkbox,
|
127
|
-
on: ["--stream"],
|
128
|
-
description: "Do not attempt to optimize graph presentation, suitable for streaming large graphs.") {
|
137
|
+
on: ["--[no-]stream"],
|
138
|
+
description: "Do not attempt to optimize graph presentation, suitable for streaming large graphs.") {|arg| arg},
|
129
139
|
RDF::CLI::Option.new(
|
130
140
|
symbol: :useRdfType,
|
131
141
|
datatype: TrueClass,
|
132
142
|
control: :checkbox,
|
133
|
-
on: ["--use-rdf-type"],
|
134
|
-
description: "Treat `rdf:type` like a normal property instead of using `@type`.") {
|
143
|
+
on: ["--[no-]use-rdf-type"],
|
144
|
+
description: "Treat `rdf:type` like a normal property instead of using `@type`.") {|arg| arg},
|
135
145
|
]
|
136
146
|
end
|
137
147
|
|