Skip to content

Commit 0786a2e

Browse files
committed
Finish 3.2.4
2 parents 37d6180 + 73ee226 commit 0786a2e

16 files changed

+477
-205
lines changed

.github/workflows/ci.yml

+5-12
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
ruby:
23-
- 2.6
24-
- 2.7
25-
- "3.0"
26-
- 3.1
27-
- ruby-head
28-
- jruby
22+
ruby: [2.6, 2.7, '3.0', 3.1, 3.2, ruby-head, jruby]
2923
steps:
3024
- name: Clone repository
31-
uses: actions/checkout@v2
25+
uses: actions/checkout@v3
3226
- name: Set up Ruby
3327
uses: ruby/setup-ruby@v1
3428
with:
@@ -48,15 +42,14 @@ jobs:
4842
runs-on: windows-latest
4943
env:
5044
CI: true
51-
ALLOW_FAILURES: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'jruby' }}
45+
ALLOW_FAILURES: ${{ matrix.ruby == '3.2' || matrix.ruby == 'jruby' }}
5246
strategy:
5347
fail-fast: false
5448
matrix:
55-
ruby:
56-
- 3.1
49+
ruby: [3.1, 3.2]
5750
steps:
5851
- name: Clone repository
59-
uses: actions/checkout@v2
52+
uses: actions/checkout@v3
6053
- name: Set up Ruby
6154
uses: ruby/setup-ruby@v1
6255
with:

.github/workflows/generate-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Update gh-pages with docs
1111
steps:
1212
- name: Clone repository
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v3
1414
- name: Set up Ruby
1515
uses: ruby/setup-ruby@v1
1616
with:

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.3
1+
3.2.4

json-ld.gemspec

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ Gem::Specification.new do |gem|
3232

3333
gem.required_ruby_version = '>= 2.6'
3434
gem.requirements = []
35-
gem.add_runtime_dependency 'rdf', '~> 3.2', '>= 3.2.9'
35+
gem.add_runtime_dependency 'rdf', '~> 3.2', '>= 3.2.10'
3636
gem.add_runtime_dependency 'multi_json', '~> 1.15'
3737
gem.add_runtime_dependency 'link_header', '~> 0.0', '>= 0.0.8'
3838
gem.add_runtime_dependency 'json-canonicalization', '~> 0.3'
39-
gem.add_runtime_dependency 'htmlentities', '~> 4.3'
40-
gem.add_runtime_dependency 'rack', '~> 2.2'
39+
gem.add_runtime_dependency 'htmlentities', '~> 4.3'
40+
gem.add_runtime_dependency "rack", '>= 2.2', '< 4'
4141
gem.add_development_dependency 'sinatra-linkeddata','~> 3.2'
42-
gem.add_development_dependency 'jsonlint', '~> 0.3' unless is_java
43-
gem.add_development_dependency 'oj', '~> 3.13' unless is_java
42+
gem.add_development_dependency 'jsonlint', '~> 0.4' unless is_java
43+
gem.add_development_dependency 'oj', '~> 3.14' unless is_java
4444
gem.add_development_dependency 'yajl-ruby', '~> 1.4' unless is_java
45-
gem.add_development_dependency 'rack-test', '~> 1.1'
45+
gem.add_development_dependency 'rack-test', '>= 1.1', '< 3'
4646
gem.add_development_dependency 'rdf-isomorphic', '~> 3.2'
4747
gem.add_development_dependency 'rdf-spec', '~> 3.2'
4848
gem.add_development_dependency 'rdf-trig', '~> 3.2'
4949
gem.add_development_dependency 'rdf-turtle', '~> 3.2'
5050
gem.add_development_dependency 'rdf-vocab', '~> 3.2'
5151
gem.add_development_dependency 'rdf-xsd', '~> 3.2'
52-
gem.add_development_dependency 'rspec', '~> 3.11'
52+
gem.add_development_dependency 'rspec', '~> 3.12'
5353
gem.add_development_dependency 'rspec-its', '~> 1.3'
5454
gem.add_development_dependency 'yard' , '~> 0.9'
5555

lib/json/ld/api.rb

+23-16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class API
6666
# @param [String, #read, Hash, Array, JSON::LD::Context] context
6767
# An external context to use additionally to the context embedded in input when expanding the input.
6868
# @param [Hash{Symbol => Object}] options
69+
# @option options [Symbol] :adapter used with MultiJson
6970
# @option options [RDF::URI, String, #to_s] :base
7071
# 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.
7172
# @option options [Boolean] :compactArrays (true)
@@ -74,10 +75,10 @@ class API
7475
# Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded.
7576
# @option options [Proc] :documentLoader
7677
# 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`.
7978
# @option options [String, #read, Hash, Array, JSON::LD::Context] :expandContext
8079
# 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.
8182
# @option options [Boolean] :extractAllScripts
8283
# 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.
8384
# @option options [Boolean, String, RDF::URI] :flatten
@@ -86,19 +87,19 @@ class API
8687
# 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.
8788
# @option options [Symbol] :library
8889
# 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.
8994
# @option options [String] :processingMode
9095
# 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)
9397
# support parsing JSON-LD-star statement resources.
9498
# @option options [Boolean] :rename_bnodes (true)
9599
# Rename bnodes as part of expansion, or keep them the same.
96100
# @option options [Boolean] :unique_bnodes (false)
97101
# 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
99102
# @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.
102103
# @yield [api]
103104
# @yieldparam [API]
104105
# @raise [JsonLdError]
@@ -235,7 +236,7 @@ def self.compact(input, context, expanded: false, serializer: nil, **options)
235236
end
236237

237238
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'}"}
239240
result = compact(value)
240241

241242
# xxx) Add the given context to the output
@@ -289,7 +290,7 @@ def self.flatten(input, context, expanded: false, serializer: nil, **options)
289290

290291
# Initialize input using
291292
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'}"}
293294

294295
# 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.
295296
@value = rename_bnodes(@value) if @options[:rename_bnodes]
@@ -410,8 +411,8 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
410411

411412
# Initialize input using frame as context
412413
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'}"}
415416

416417
if %w(@first @last).include?(options[:embed]) && context.processingMode('json-ld-1.1')
417418
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 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
458459

459460
# Replace values with `@preserve` with the content of its entry.
460461
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'}"}
462463

463464
# Compact result
464465
compacted = compact(result)
@@ -477,7 +478,7 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
477478
# Only add context if one was provided
478479
result = context.serialize(provided_context: frame).merge(result) if frame['@context']
479480

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'}"}
481482
result
482483
end
483484

@@ -518,7 +519,7 @@ def self.toRdf(input, expanded: false, **options, &block)
518519
API.new(flattened_input, nil, **options) do
519520
# 1) Perform the Expansion Algorithm on the JSON-LD input.
520521
# 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'}"}
522523

523524
# Recurse through input
524525
flattened_input.each do |node|
@@ -527,7 +528,7 @@ def self.toRdf(input, expanded: false, **options, &block)
527528

528529
# Drop invalid statements (other than IRIs)
529530
unless statement.valid_extended?
530-
log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
531+
# log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
531532
next
532533
end
533534

@@ -562,6 +563,7 @@ def self.fromRdf(input, useRdfType: false, useNativeTypes: false, serializer: ni
562563

563564
API.new(nil, nil, **options) do
564565
result = from_statements(input,
566+
extendedRepresentation: options[:extendedRepresentation],
565567
useRdfType: useRdfType,
566568
useNativeTypes: useNativeTypes)
567569
end
@@ -574,6 +576,9 @@ def self.fromRdf(input, useRdfType: false, useNativeTypes: false, serializer: ni
574576
# Uses built-in or provided documentLoader to retrieve a parsed document.
575577
#
576578
# @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.
577582
# @param [String, RDF::URI] base
578583
# Location to use as documentUrl instead of `url`.
579584
# @option options [Proc] :documentLoader
@@ -594,6 +599,7 @@ def self.fromRdf(input, useRdfType: false, useNativeTypes: false, serializer: ni
594599
# If a block is given, the result of evaluating the block is returned, otherwise, the retrieved remote document and context information unless block given
595600
# @raise [JsonLdError]
596601
def self.loadRemoteDocument(url,
602+
allowed_content_types: nil,
597603
base: nil,
598604
documentLoader: nil,
599605
extractAllScripts: false,
@@ -674,7 +680,8 @@ def self.loadRemoteDocument(url,
674680

675681
if remote_doc.contentType && validate
676682
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))
678685
end
679686
block_given? ? yield(remote_doc) : remote_doc
680687
end

lib/json/ld/compact.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ def compact(element,
2121
base: nil,
2222
property: nil,
2323
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}"}
2525

2626
# If the term definition for active property itself contains a context, use that for compacting values.
2727
input_context = self.context
2828

2929
case element
3030
when Array
31-
#log_debug("") {"Array #{element.inspect}"}
31+
# log_debug("") {"Array #{element.inspect}"}
3232
result = element.map do |item|
3333
compact(item, base: base, property: property, log_depth: log_depth.to_i + 1)
3434
end.compact
@@ -38,10 +38,10 @@ def compact(element,
3838
# member; otherwise the compacted value is element
3939
if result.length == 1 &&
4040
!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}
4242
result.first
4343
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}
4545
result
4646
end
4747
when Hash
@@ -52,7 +52,7 @@ def compact(element,
5252

5353
# Revert any previously type-scoped (non-preserved) context
5454
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}"}
5656
self.context = context.previous_context
5757
end
5858

@@ -61,13 +61,13 @@ def compact(element,
6161
if td && !td.context.nil?
6262
self.context = context.parse(td.context,
6363
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}"}
6565
end
6666

6767
if (element.key?('@id') || element.key?('@value')) && !element.key?('@annotation')
6868
result = context.compact_value(property, element, base: @options[:base])
6969
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}"}
7171
return result
7272
end
7373
end
@@ -90,12 +90,12 @@ def compact(element,
9090
each do |term|
9191
term_context = input_context.term_definitions[term].context if input_context.term_definitions[term]
9292
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}"}
9494
end
9595

9696
element.keys.opt_sort(ordered: @options[:ordered]).each do |expanded_property|
9797
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}"}
9999

100100
if expanded_property == '@id'
101101
compacted_value = as_array(expanded_value).map do |expanded_id|
@@ -134,7 +134,7 @@ def compact(element,
134134
compacted_value = compact(expanded_value, base: base,
135135
property: '@reverse',
136136
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}"}
138138
# handle double-reversed properties
139139
compacted_value.each do |prop, value|
140140
if context.reverse?(prop)
@@ -146,7 +146,7 @@ def compact(element,
146146

147147
unless compacted_value.empty?
148148
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}"}
150150
result[al] = compacted_value
151151
end
152152
next
@@ -157,7 +157,7 @@ def compact(element,
157157
compacted_value = compact(expanded_value, base: base,
158158
property: property,
159159
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}"}
161161

162162
unless compacted_value.is_a?(Array) && compacted_value.empty?
163163
result['@preserve'] = compacted_value
@@ -166,14 +166,14 @@ def compact(element,
166166
end
167167

168168
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"}
170170
next
171171
end
172172

173173
# Otherwise, if expanded property is @direction, @index, @value, or @language:
174174
if EXPANDED_PROPERTY_DIRECTION_INDEX_LANGUAGE_VALUE.include?(expanded_property)
175175
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}"}
177177
result[al] = expanded_value
178178
next
179179
end
@@ -223,7 +223,7 @@ def compact(element,
223223
compacted_item = compact(value, base: base,
224224
property: item_active_property,
225225
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}"}
227227

228228
# handle @list
229229
if list?(expanded_item)
@@ -345,7 +345,7 @@ def compact(element,
345345
result
346346
else
347347
# 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}
349349
element
350350
end
351351

0 commit comments

Comments
 (0)