json-ld 3.2.2 → 3.2.3
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 +3 -1
- data/lib/json/ld/format.rb +81 -115
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff11a49b52d7ca0faf6deaac7324f08530747b53ec857ebe007c027a1bf412b4
|
4
|
+
data.tar.gz: b0a808fc12be08ecaa47f399c0f20ff26120cc36820bf45d6c434ad1f31f53e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e17fbb3280f393ece72136d09182d1032982ca116d49577f03dc72ca35ebc8193495054a1944e525acdad8ae67ce6cb341f6859c5e97a7d2497ca047d7ee40
|
7
|
+
data.tar.gz: eef60e136ca7d86ac66cd0b74d5b01862b4f5c7039352c7d6e678b73ab783bf7bbf2f397f7fd928421bc52e332389cab1432e69175d6fa0d260dfcf7a315a66a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.
|
1
|
+
3.2.3
|
data/lib/json/ld/api.rb
CHANGED
@@ -827,8 +827,10 @@ module JSON::LD
|
|
827
827
|
# other arguments that may be passed for some specific implementation.
|
828
828
|
# @param [Hash<Symbol, Object>] options
|
829
829
|
# options passed from the invoking context.
|
830
|
+
# @option options [Object] :serializer_opts (JSON_STATE)
|
830
831
|
def self.serializer(object, *args, **options)
|
831
|
-
|
832
|
+
serializer_opts = options.fetch(:serializer_opts, JSON_STATE)
|
833
|
+
MultiJson.dump(object, serializer_opts)
|
832
834
|
end
|
833
835
|
|
834
836
|
##
|
data/lib/json/ld/format.rb
CHANGED
@@ -45,8 +45,80 @@ module JSON::LD
|
|
45
45
|
!sample.include?("http://www.w3.org/ns/csvw")
|
46
46
|
end
|
47
47
|
|
48
|
+
# Specify how to execute CLI commands for each supported format.
|
49
|
+
# Derived formats (e.g., YAML-LD) define their own entrypoints.
|
50
|
+
LD_FORMATS = {
|
51
|
+
jsonld: {
|
52
|
+
expand: ->(input, **options) {
|
53
|
+
JSON::LD::API.expand(input,
|
54
|
+
serializer: JSON::LD::API.method(:serializer),
|
55
|
+
**options)
|
56
|
+
},
|
57
|
+
compact: ->(input, **options) {
|
58
|
+
JSON::LD::API.compact(input,
|
59
|
+
options[:context],
|
60
|
+
serializer: JSON::LD::API.method(:serializer),
|
61
|
+
**options)
|
62
|
+
},
|
63
|
+
flatten: ->(input, **options) {
|
64
|
+
JSON::LD::API.flatten(input,
|
65
|
+
options[:context],
|
66
|
+
serializer: JSON::LD::API.method(:serializer),
|
67
|
+
**options)
|
68
|
+
},
|
69
|
+
frame: ->(input, **options) {
|
70
|
+
JSON::LD::API.frame(input,
|
71
|
+
options[:frame],
|
72
|
+
serializer: JSON::LD::API.method(:serializer),
|
73
|
+
**options)
|
74
|
+
},
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
# Execute the body of a CLI command, generic for each different API method based on definitions on {LD_FORMATS}.
|
79
|
+
#
|
80
|
+
# Expands the input, or transforms from an RDF format based on the `:format` option, and then executes the appropriate command based on `:output_format` and does appropriate output serialization.
|
81
|
+
# @private
|
82
|
+
def self.cli_exec(command, files, output: $stdin, **options)
|
83
|
+
output.set_encoding(Encoding::UTF_8) if output.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
|
84
|
+
options[:base] ||= options[:base_uri]
|
85
|
+
|
86
|
+
# Parse using input format, serialize using output format
|
87
|
+
in_fmt = LD_FORMATS[options.fetch(:format, :jsonld)]
|
88
|
+
out_fmt = LD_FORMATS[options.fetch(:output_format, :jsonld)]
|
89
|
+
|
90
|
+
if in_fmt
|
91
|
+
# Input is a JSON-LD based source (or derived)
|
92
|
+
if files.empty?
|
93
|
+
# If files are empty, either use options[:evaluate] or STDIN
|
94
|
+
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
|
95
|
+
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
|
96
|
+
expanded = in_fmt[:expand].call(input, serializer: nil, **options)
|
97
|
+
output.puts out_fmt[command].call(expanded, expanded: true, **options)
|
98
|
+
else
|
99
|
+
files.each do |file|
|
100
|
+
expanded = in_fmt[:expand].call(file, serializer: nil, **options)
|
101
|
+
output.puts out_fmt[command].call(expanded, expanded: true, **options)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
else
|
105
|
+
# Turn RDF into JSON-LD first
|
106
|
+
RDF::CLI.parse(files, **options) do |reader|
|
107
|
+
JSON::LD::API.fromRdf(reader, serializer: nil, **options) do |expanded|
|
108
|
+
output.puts out_fmt[command].call(expanded, expanded: true, **options)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
48
114
|
##
|
49
|
-
# Hash of CLI commands appropriate for this format
|
115
|
+
# Hash of CLI commands appropriate for this format:
|
116
|
+
#
|
117
|
+
# * `expand` => {JSON::LD::API.expand}
|
118
|
+
# * `compact` => {JSON::LD::API.compact}
|
119
|
+
# * `flatten` => {JSON::LD::API.flatten}
|
120
|
+
# * `frame` => {JSON::LD::API.frame}
|
121
|
+
#
|
50
122
|
# @return [Hash{Symbol => Hash}]
|
51
123
|
def self.cli_commands
|
52
124
|
{
|
@@ -54,73 +126,21 @@ module JSON::LD
|
|
54
126
|
description: "Expand JSON-LD or parsed RDF",
|
55
127
|
parse: false,
|
56
128
|
help: "expand [--context <context-file>] files ...",
|
57
|
-
filter: {output_format:
|
129
|
+
filter: {output_format: LD_FORMATS.keys}, # Only shows output format set
|
58
130
|
lambda: ->(files, **options) do
|
59
|
-
out = options[:output] || $stdout
|
60
|
-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
|
61
131
|
options = options.merge(expandContext: options.delete(:context)) if options.key?(:context)
|
62
|
-
|
63
|
-
if options[:format] == :jsonld
|
64
|
-
if files.empty?
|
65
|
-
# If files are empty, either use options[:evaluate] or STDIN
|
66
|
-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
|
67
|
-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
|
68
|
-
JSON::LD::API.expand(input, validate: false, **options) do |expanded|
|
69
|
-
out.puts expanded.to_json(JSON::LD::JSON_STATE)
|
70
|
-
end
|
71
|
-
else
|
72
|
-
files.each do |file|
|
73
|
-
JSON::LD::API.expand(file, validate: false, **options) do |expanded|
|
74
|
-
out.puts expanded.to_json(JSON::LD::JSON_STATE)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
else
|
79
|
-
# Turn RDF into JSON-LD first
|
80
|
-
RDF::CLI.parse(files, **options) do |reader|
|
81
|
-
JSON::LD::API.fromRdf(reader) do |expanded|
|
82
|
-
out.puts expanded.to_json(JSON::LD::JSON_STATE)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
132
|
+
cli_exec(:expand, files, **options)
|
86
133
|
end,
|
87
134
|
option_use: {context: :removed}
|
88
135
|
},
|
89
136
|
compact: {
|
90
137
|
description: "Compact JSON-LD or parsed RDF",
|
91
138
|
parse: false,
|
92
|
-
filter: {output_format:
|
139
|
+
filter: {output_format: LD_FORMATS.keys}, # Only shows output format set
|
93
140
|
help: "compact --context <context-file> files ...",
|
94
141
|
lambda: ->(files, **options) do
|
95
142
|
raise ArgumentError, "Compacting requires a context" unless options[:context]
|
96
|
-
|
97
|
-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
|
98
|
-
options[:base] ||= options[:base_uri]
|
99
|
-
if options[:format] == :jsonld
|
100
|
-
if files.empty?
|
101
|
-
# If files are empty, either use options[:evaluate] or STDIN
|
102
|
-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
|
103
|
-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
|
104
|
-
JSON::LD::API.compact(input, options[:context], **options) do |compacted|
|
105
|
-
out.puts compacted.to_json(JSON::LD::JSON_STATE)
|
106
|
-
end
|
107
|
-
else
|
108
|
-
files.each do |file|
|
109
|
-
JSON::LD::API.compact(file, options[:context], **options) do |compacted|
|
110
|
-
out.puts compacted.to_json(JSON::LD::JSON_STATE)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
else
|
115
|
-
# Turn RDF into JSON-LD first
|
116
|
-
RDF::CLI.parse(files, **options) do |reader|
|
117
|
-
JSON::LD::API.fromRdf(reader) do |expanded|
|
118
|
-
JSON::LD::API.compact(expanded, options[:context], **options) do |compacted|
|
119
|
-
out.puts compacted.to_json(JSON::LD::JSON_STATE)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
143
|
+
cli_exec(:compact, files, **options)
|
124
144
|
end,
|
125
145
|
options: [
|
126
146
|
RDF::CLI::Option.new(
|
@@ -136,36 +156,9 @@ module JSON::LD
|
|
136
156
|
description: "Flatten JSON-LD or parsed RDF",
|
137
157
|
parse: false,
|
138
158
|
help: "flatten [--context <context-file>] files ...",
|
139
|
-
filter: {output_format:
|
159
|
+
filter: {output_format: LD_FORMATS.keys}, # Only shows output format set
|
140
160
|
lambda: ->(files, **options) do
|
141
|
-
|
142
|
-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
|
143
|
-
options[:base] ||= options[:base_uri]
|
144
|
-
if options[:format] == :jsonld
|
145
|
-
if files.empty?
|
146
|
-
# If files are empty, either use options[:evaluate] or STDIN
|
147
|
-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
|
148
|
-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
|
149
|
-
JSON::LD::API.flatten(input, options[:context], **options) do |flattened|
|
150
|
-
out.puts flattened.to_json(JSON::LD::JSON_STATE)
|
151
|
-
end
|
152
|
-
else
|
153
|
-
files.each do |file|
|
154
|
-
JSON::LD::API.flatten(file, options[:context], **options) do |flattened|
|
155
|
-
out.puts flattened.to_json(JSON::LD::JSON_STATE)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
else
|
160
|
-
# Turn RDF into JSON-LD first
|
161
|
-
RDF::CLI.parse(files, **options) do |reader|
|
162
|
-
JSON::LD::API.fromRdf(reader) do |expanded|
|
163
|
-
JSON::LD::API.flatten(expanded, options[:context], **options) do |flattened|
|
164
|
-
out.puts flattened.to_json(JSON::LD::JSON_STATE)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
161
|
+
cli_exec(:compact, files, **options)
|
169
162
|
end,
|
170
163
|
options: [
|
171
164
|
RDF::CLI::Option.new(
|
@@ -188,37 +181,10 @@ module JSON::LD
|
|
188
181
|
description: "Frame JSON-LD or parsed RDF",
|
189
182
|
parse: false,
|
190
183
|
help: "frame --frame <frame-file> files ...",
|
191
|
-
filter: {output_format:
|
184
|
+
filter: {output_format: LD_FORMATS.keys}, # Only shows output format set
|
192
185
|
lambda: ->(files, **options) do
|
193
186
|
raise ArgumentError, "Framing requires a frame" unless options[:frame]
|
194
|
-
|
195
|
-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
|
196
|
-
options[:base] ||= options[:base_uri]
|
197
|
-
if options[:format] == :jsonld
|
198
|
-
if files.empty?
|
199
|
-
# If files are empty, either use options[:evaluate] or STDIN
|
200
|
-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
|
201
|
-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
|
202
|
-
JSON::LD::API.frame(input, options[:frame], **options) do |framed|
|
203
|
-
out.puts framed.to_json(JSON::LD::JSON_STATE)
|
204
|
-
end
|
205
|
-
else
|
206
|
-
files.each do |file|
|
207
|
-
JSON::LD::API.frame(file, options[:frame], **options) do |framed|
|
208
|
-
out.puts framed.to_json(JSON::LD::JSON_STATE)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
else
|
213
|
-
# Turn RDF into JSON-LD first
|
214
|
-
RDF::CLI.parse(files, **options) do |reader|
|
215
|
-
JSON::LD::API.fromRdf(reader) do |expanded|
|
216
|
-
JSON::LD::API.frame(expanded, options[:frame], **options) do |framed|
|
217
|
-
out.puts framed.to_json(JSON::LD::JSON_STATE)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
187
|
+
cli_exec(:compact, files, **options)
|
222
188
|
end,
|
223
189
|
option_use: {context: :removed},
|
224
190
|
options: [
|
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: 3.2.
|
4
|
+
version: 3.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.9
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.9
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: multi_json
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,14 +112,14 @@ dependencies:
|
|
106
112
|
requirements:
|
107
113
|
- - "~>"
|
108
114
|
- !ruby/object:Gem::Version
|
109
|
-
version: '3.
|
115
|
+
version: '3.2'
|
110
116
|
type: :development
|
111
117
|
prerelease: false
|
112
118
|
version_requirements: !ruby/object:Gem::Requirement
|
113
119
|
requirements:
|
114
120
|
- - "~>"
|
115
121
|
- !ruby/object:Gem::Version
|
116
|
-
version: '3.
|
122
|
+
version: '3.2'
|
117
123
|
- !ruby/object:Gem::Dependency
|
118
124
|
name: jsonlint
|
119
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -260,14 +266,14 @@ dependencies:
|
|
260
266
|
requirements:
|
261
267
|
- - "~>"
|
262
268
|
- !ruby/object:Gem::Version
|
263
|
-
version: '3.
|
269
|
+
version: '3.11'
|
264
270
|
type: :development
|
265
271
|
prerelease: false
|
266
272
|
version_requirements: !ruby/object:Gem::Requirement
|
267
273
|
requirements:
|
268
274
|
- - "~>"
|
269
275
|
- !ruby/object:Gem::Version
|
270
|
-
version: '3.
|
276
|
+
version: '3.11'
|
271
277
|
- !ruby/object:Gem::Dependency
|
272
278
|
name: rspec-its
|
273
279
|
requirement: !ruby/object:Gem::Requirement
|