json-ld 3.2.2 → 3.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63c237710b5f32fe8037a11969feaf712a79f68a4d1d568a89ece1a5d1d26ff2
4
- data.tar.gz: cac81da94266cac30a7e31e5018477ef55e52b6b1701b048214947f266439236
3
+ metadata.gz: 7df92f96bef30d3af100b145f427533e3fa5bc2a91369e1edc86fd41dc2946bb
4
+ data.tar.gz: fcd7f3972ea390ace60be529f3106bd04823c8cddbb5efd050d0c9d134586028
5
5
  SHA512:
6
- metadata.gz: 440da082cc1cbabcd69e8cb3d34858c4fe8fd96b116c0d67651d5ce7338d6e787f9d00451ff1f730d08982f0d8697d097f51d09d033ff7f8e290252006f96c78
7
- data.tar.gz: 0b877d9d96857964a4913aef1790aa04dc98f83676ec0154c016ad05e7a9dc0a22b1b3bd31ae785cfb4447ac6914291ac56d42f5dc6781fc58c6687ccd4d15cd
6
+ metadata.gz: 3c1df99a21da6ae271caeedc44e0f66fffe77dbae771297153b45286d70a96044dcc97ea62a3aaffe74ac11a847ae52bf641410ba74e43cfed51c5f773c69c9a
7
+ data.tar.gz: ed0e35ecdaf9118b0ee81a34bb72f92e9344678a8c3e4311f4bed4a35d58bb217b2f4810e1f8cc5c59c97312399e716a237b5c1e841fd538c730d4e8e9e151c7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.2.4
data/lib/json/ld/api.rb CHANGED
@@ -66,6 +66,7 @@ module JSON::LD
66
66
  # @param [String, #read, Hash, Array, JSON::LD::Context] context
67
67
  # An external context to use additionally to the context embedded in input when expanding the input.
68
68
  # @param [Hash{Symbol => Object}] options
69
+ # @option options [Symbol] :adapter used with MultiJson
69
70
  # @option options [RDF::URI, String, #to_s] :base
70
71
  # 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.
71
72
  # @option options [Boolean] :compactArrays (true)
@@ -74,10 +75,10 @@ module JSON::LD
74
75
  # Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded.
75
76
  # @option options [Proc] :documentLoader
76
77
  # 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.
77
- # @option options [Boolean] :lowercaseLanguage
78
- # By default, language tags are left as is. To normalize to lowercase, set this option to `true`.
79
78
  # @option options [String, #read, Hash, Array, JSON::LD::Context] :expandContext
80
79
  # A context that is used to initialize the active context when expanding a document.
80
+ # @option options [Boolean] :extendedRepresentation (false)
81
+ # Use the extended internal representation.
81
82
  # @option options [Boolean] :extractAllScripts
82
83
  # If set, when given an HTML input without a fragment identifier, extracts all `script` elements with type `application/ld+json` into an array during expansion.
83
84
  # @option options [Boolean, String, RDF::URI] :flatten
@@ -86,19 +87,19 @@ module JSON::LD
86
87
  # 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.
87
88
  # @option options [Symbol] :library
88
89
  # One of :nokogiri or :rexml. If nil/unspecified uses :nokogiri if available, :rexml otherwise.
90
+ # @option options [Boolean] :lowercaseLanguage
91
+ # By default, language tags are left as is. To normalize to lowercase, set this option to `true`.
92
+ # @option options [Boolean] :ordered (true)
93
+ # Order traversal of dictionary members by key when performing algorithms.
89
94
  # @option options [String] :processingMode
90
95
  # Processing mode, json-ld-1.0 or json-ld-1.1.
91
- # 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`.
92
- # @option options [Boolean] rdfstar (false)
96
+ # @option options [Boolean] :rdfstar (false)
93
97
  # support parsing JSON-LD-star statement resources.
94
98
  # @option options [Boolean] :rename_bnodes (true)
95
99
  # Rename bnodes as part of expansion, or keep them the same.
96
100
  # @option options [Boolean] :unique_bnodes (false)
97
101
  # Use unique bnode identifiers, defaults to using the identifier which the node was originally initialized with (if any).
98
- # @option options [Symbol] :adapter used with MultiJson
99
102
  # @option options [Boolean] :validate Validate input, if a string or readable object.
100
- # @option options [Boolean] :ordered (true)
101
- # Order traversal of dictionary members by key when performing algorithms.
102
103
  # @yield [api]
103
104
  # @yieldparam [API]
104
105
  # @raise [JsonLdError]
@@ -235,7 +236,7 @@ module JSON::LD
235
236
  end
236
237
 
237
238
  API.new(expanded_input, context, no_default_base: true, **options) do
238
- log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
239
+ # log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
239
240
  result = compact(value)
240
241
 
241
242
  # xxx) Add the given context to the output
@@ -289,7 +290,7 @@ module JSON::LD
289
290
 
290
291
  # Initialize input using
291
292
  API.new(expanded_input, context, no_default_base: true, **options) do
292
- log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
293
+ # log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
293
294
 
294
295
  # Rename blank nodes recusively. Note that this does not create new blank node identifiers where none exist, which is performed in the node map generation algorithm.
295
296
  @value = rename_bnodes(@value) if @options[:rename_bnodes]
@@ -410,8 +411,8 @@ module JSON::LD
410
411
 
411
412
  # Initialize input using frame as context
412
413
  API.new(expanded_input, frame['@context'], no_default_base: true, **options) do
413
- log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
414
- log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
414
+ # log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
415
+ # log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
415
416
 
416
417
  if %w(@first @last).include?(options[:embed]) && context.processingMode('json-ld-1.1')
417
418
  raise JSON::LD::JsonLdError::InvalidEmbedValue, "#{options[:embed]} is not a valid value of @embed in 1.1 mode" if @options[:validate]
@@ -458,7 +459,7 @@ module JSON::LD
458
459
 
459
460
  # Replace values with `@preserve` with the content of its entry.
460
461
  result = cleanup_preserve(result)
461
- log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
462
+ # log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
462
463
 
463
464
  # Compact result
464
465
  compacted = compact(result)
@@ -477,7 +478,7 @@ module JSON::LD
477
478
  # Only add context if one was provided
478
479
  result = context.serialize(provided_context: frame).merge(result) if frame['@context']
479
480
 
480
- log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
481
+ # log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
481
482
  result
482
483
  end
483
484
 
@@ -518,7 +519,7 @@ module JSON::LD
518
519
  API.new(flattened_input, nil, **options) do
519
520
  # 1) Perform the Expansion Algorithm on the JSON-LD input.
520
521
  # This removes any existing context to allow the given context to be cleanly applied.
521
- log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}
522
+ # log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}
522
523
 
523
524
  # Recurse through input
524
525
  flattened_input.each do |node|
@@ -527,7 +528,7 @@ module JSON::LD
527
528
 
528
529
  # Drop invalid statements (other than IRIs)
529
530
  unless statement.valid_extended?
530
- log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
531
+ # log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
531
532
  next
532
533
  end
533
534
 
@@ -562,6 +563,7 @@ module JSON::LD
562
563
 
563
564
  API.new(nil, nil, **options) do
564
565
  result = from_statements(input,
566
+ extendedRepresentation: options[:extendedRepresentation],
565
567
  useRdfType: useRdfType,
566
568
  useNativeTypes: useNativeTypes)
567
569
  end
@@ -574,6 +576,9 @@ module JSON::LD
574
576
  # Uses built-in or provided documentLoader to retrieve a parsed document.
575
577
  #
576
578
  # @param [RDF::URI, String] url
579
+ # @param [Regexp] allowed_content_types
580
+ # A regular expression matching other content types allowed
581
+ # beyond types for JSON and HTML.
577
582
  # @param [String, RDF::URI] base
578
583
  # Location to use as documentUrl instead of `url`.
579
584
  # @option options [Proc] :documentLoader
@@ -594,6 +599,7 @@ module JSON::LD
594
599
  # If a block is given, the result of evaluating the block is returned, otherwise, the retrieved remote document and context information unless block given
595
600
  # @raise [JsonLdError]
596
601
  def self.loadRemoteDocument(url,
602
+ allowed_content_types: nil,
597
603
  base: nil,
598
604
  documentLoader: nil,
599
605
  extractAllScripts: false,
@@ -674,7 +680,8 @@ module JSON::LD
674
680
 
675
681
  if remote_doc.contentType && validate
676
682
  raise IOError, "url: #{url}, contentType: #{remote_doc.contentType}" unless
677
- remote_doc.contentType.match?(/application\/(.+\+)?json|text\/html|application\/xhtml\+xml/)
683
+ remote_doc.contentType.match?(/application\/(.+\+)?json|text\/html|application\/xhtml\+xml/) ||
684
+ (allowed_content_types && remote_doc.contentType.match?(allowed_content_types))
678
685
  end
679
686
  block_given? ? yield(remote_doc) : remote_doc
680
687
  end
@@ -827,8 +834,10 @@ module JSON::LD
827
834
  # other arguments that may be passed for some specific implementation.
828
835
  # @param [Hash<Symbol, Object>] options
829
836
  # options passed from the invoking context.
837
+ # @option options [Object] :serializer_opts (JSON_STATE)
830
838
  def self.serializer(object, *args, **options)
831
- MultiJson.dump(object, JSON_STATE)
839
+ serializer_opts = options.fetch(:serializer_opts, JSON_STATE)
840
+ MultiJson.dump(object, serializer_opts)
832
841
  end
833
842
 
834
843
  ##
@@ -21,14 +21,14 @@ module JSON::LD
21
21
  base: nil,
22
22
  property: nil,
23
23
  log_depth: nil)
24
- log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}
24
+ # log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}
25
25
 
26
26
  # If the term definition for active property itself contains a context, use that for compacting values.
27
27
  input_context = self.context
28
28
 
29
29
  case element
30
30
  when Array
31
- #log_debug("") {"Array #{element.inspect}"}
31
+ # log_debug("") {"Array #{element.inspect}"}
32
32
  result = element.map do |item|
33
33
  compact(item, base: base, property: property, log_depth: log_depth.to_i + 1)
34
34
  end.compact
@@ -38,10 +38,10 @@ module JSON::LD
38
38
  # member; otherwise the compacted value is element
39
39
  if result.length == 1 &&
40
40
  !context.as_array?(property) && @options[:compactArrays]
41
- log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
41
+ # log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
42
42
  result.first
43
43
  else
44
- log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
44
+ # log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
45
45
  result
46
46
  end
47
47
  when Hash
@@ -52,7 +52,7 @@ module JSON::LD
52
52
 
53
53
  # Revert any previously type-scoped (non-preserved) context
54
54
  if context.previous_context && !element.key?('@value') && element.keys != %w(@id)
55
- log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
55
+ # log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
56
56
  self.context = context.previous_context
57
57
  end
58
58
 
@@ -61,13 +61,13 @@ module JSON::LD
61
61
  if td && !td.context.nil?
62
62
  self.context = context.parse(td.context,
63
63
  override_protected: true)
64
- log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
64
+ # log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
65
65
  end
66
66
 
67
67
  if (element.key?('@id') || element.key?('@value')) && !element.key?('@annotation')
68
68
  result = context.compact_value(property, element, base: @options[:base])
69
69
  if !result.is_a?(Hash) || context.coerce(property) == '@json'
70
- log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
70
+ # log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
71
71
  return result
72
72
  end
73
73
  end
@@ -90,12 +90,12 @@ module JSON::LD
90
90
  each do |term|
91
91
  term_context = input_context.term_definitions[term].context if input_context.term_definitions[term]
92
92
  self.context = context.parse(term_context, propagate: false) unless term_context.nil?
93
- log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
93
+ # log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
94
94
  end
95
95
 
96
96
  element.keys.opt_sort(ordered: @options[:ordered]).each do |expanded_property|
97
97
  expanded_value = element[expanded_property]
98
- log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
98
+ # log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
99
99
 
100
100
  if expanded_property == '@id'
101
101
  compacted_value = as_array(expanded_value).map do |expanded_id|
@@ -134,7 +134,7 @@ module JSON::LD
134
134
  compacted_value = compact(expanded_value, base: base,
135
135
  property: '@reverse',
136
136
  log_depth: log_depth.to_i + 1)
137
- log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
137
+ # log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
138
138
  # handle double-reversed properties
139
139
  compacted_value.each do |prop, value|
140
140
  if context.reverse?(prop)
@@ -146,7 +146,7 @@ module JSON::LD
146
146
 
147
147
  unless compacted_value.empty?
148
148
  al = context.compact_iri('@reverse', vocab: true)
149
- log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
149
+ # log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
150
150
  result[al] = compacted_value
151
151
  end
152
152
  next
@@ -157,7 +157,7 @@ module JSON::LD
157
157
  compacted_value = compact(expanded_value, base: base,
158
158
  property: property,
159
159
  log_depth: log_depth.to_i + 1)
160
- log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
160
+ # log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
161
161
 
162
162
  unless compacted_value.is_a?(Array) && compacted_value.empty?
163
163
  result['@preserve'] = compacted_value
@@ -166,14 +166,14 @@ module JSON::LD
166
166
  end
167
167
 
168
168
  if expanded_property == '@index' && context.container(property).include?('@index')
169
- log_debug("@index", depth: log_depth.to_i) {"drop @index"}
169
+ # log_debug("@index", depth: log_depth.to_i) {"drop @index"}
170
170
  next
171
171
  end
172
172
 
173
173
  # Otherwise, if expanded property is @direction, @index, @value, or @language:
174
174
  if EXPANDED_PROPERTY_DIRECTION_INDEX_LANGUAGE_VALUE.include?(expanded_property)
175
175
  al = context.compact_iri(expanded_property, vocab: true)
176
- log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
176
+ # log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
177
177
  result[al] = expanded_value
178
178
  next
179
179
  end
@@ -223,7 +223,7 @@ module JSON::LD
223
223
  compacted_item = compact(value, base: base,
224
224
  property: item_active_property,
225
225
  log_depth: log_depth.to_i + 1)
226
- log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
226
+ # log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
227
227
 
228
228
  # handle @list
229
229
  if list?(expanded_item)
@@ -345,7 +345,7 @@ module JSON::LD
345
345
  result
346
346
  else
347
347
  # For other types, the compacted value is the element value
348
- log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
348
+ # log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
349
349
  element
350
350
  end
351
351