json-ld 3.1.0 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -46
- data/VERSION +1 -1
- data/bin/jsonld +27 -30
- data/lib/json/ld.rb +12 -8
- data/lib/json/ld/api.rb +51 -43
- data/lib/json/ld/compact.rb +82 -68
- data/lib/json/ld/conneg.rb +1 -1
- data/lib/json/ld/context.rb +650 -542
- data/lib/json/ld/expand.rb +154 -87
- data/lib/json/ld/flatten.rb +1 -1
- data/lib/json/ld/format.rb +10 -6
- data/lib/json/ld/frame.rb +1 -2
- data/lib/json/ld/from_rdf.rb +7 -8
- data/lib/json/ld/html/nokogiri.rb +2 -1
- data/lib/json/ld/html/rexml.rb +2 -1
- data/lib/json/ld/reader.rb +20 -11
- data/lib/json/ld/streaming_reader.rb +578 -0
- data/lib/json/ld/to_rdf.rb +9 -3
- data/lib/json/ld/writer.rb +12 -5
- data/spec/compact_spec.rb +1 -0
- data/spec/context_spec.rb +63 -116
- data/spec/expand_spec.rb +29 -9
- data/spec/frame_spec.rb +44 -0
- data/spec/matchers.rb +1 -1
- data/spec/reader_spec.rb +33 -34
- data/spec/streaming_reader_spec.rb +237 -0
- data/spec/suite_expand_spec.rb +4 -2
- data/spec/suite_frame_spec.rb +0 -1
- data/spec/suite_helper.rb +23 -8
- data/spec/suite_to_rdf_spec.rb +1 -1
- data/spec/to_rdf_spec.rb +3 -3
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65b570568511427e573b9ffecdc5eedfee1b708c62e88ffc24dce4ffa8d62c2f
|
4
|
+
data.tar.gz: a3255398de49dd88c3d4b3beb918857c8939de6eed4cf92c2aa1f61764455b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f84d29c4d742ffe07dbdc585f8d51e612b7426dc3a58d21061d959587ebdfff0801bc02d3c7edf11426d03d6b9d500a54bdd172afc34b460bd5957fc0f9e4c5
|
7
|
+
data.tar.gz: ee8b915d0fb258e909e751c668ea31750b255d5d7e0276123439a149eece298284324fb63a8d13df9b23109f0662dcbcd0db41f56e23e22f745da17f50f7b75b
|
data/README.md
CHANGED
@@ -19,21 +19,31 @@ JSON::LD can now be used to create a _context_ from an RDFS/OWL definition, and
|
|
19
19
|
|
20
20
|
Install with `gem install json-ld`
|
21
21
|
|
22
|
-
### MultiJson parser
|
23
|
-
The [MultiJson](https://rubygems.org/gems/multi_json) gem is used for parsing JSON; this defaults to the native JSON parser, but will use a more performant parser if one is available. A specific parser can be specified by adding the `:adapter` option to any API call. See [MultiJson](https://rubygems.org/gems/multi_json) for more information.
|
24
|
-
|
25
22
|
### JSON-LD Streaming Profile
|
26
|
-
This gem implements an optimized streaming
|
23
|
+
This gem implements an optimized streaming reader used for generating RDF from large dataset dumps formatted as JSON-LD. Such documents must correspond to the [JSON-LD Streaming Profile](https://w3c.github.io/json-ld-streaming/):
|
24
|
+
|
25
|
+
* Keys in JSON objects must be ordered with any of `@context`, and/or `@type` coming before any other keys, in that order. This includes aliases of those keys. It is strongly encouraged that `@id` be present, and come immediately after.
|
26
|
+
* JSON-LD documents can be signaled or requested in [streaming document form](https://w3c.github.io/json-ld-streaming/#dfn-streaming-document-form). The profile URI identifying the [streaming document form](https://w3c.github.io/json-ld-streaming/#dfn-streaming-document-form) is `http://www.w3.org/ns/json-ld#streaming`.
|
27
|
+
|
28
|
+
This gem also implements an optimized streaming writer used for generating JSON-LD from large repositories. Such documents result in the JSON-LD Streaming Profile:
|
27
29
|
|
28
30
|
* Each statement written as a separate node in expanded/flattened form.
|
29
|
-
* RDF
|
31
|
+
* `RDF List`s are written as separate nodes using `rdf:first` and `rdf:rest` properties.
|
32
|
+
|
33
|
+
The order of triples retrieved from the `RDF::Enumerable` dataset determines the way that JSON-LD node objects are written; for best results, statements should be ordered by _graph name_, _subect_, _predicate_ and _object_.
|
34
|
+
|
35
|
+
### MultiJson parser
|
36
|
+
The [MultiJson](https://rubygems.org/gems/multi_json) gem is used for parsing JSON; this defaults to the native JSON parser, but will use a more performant parser if one is available. A specific parser can be specified by adding the `:adapter` option to any API call. See [MultiJson](https://rubygems.org/gems/multi_json) for more information.
|
30
37
|
|
31
38
|
## Examples
|
39
|
+
|
32
40
|
```ruby
|
33
41
|
require 'rubygems'
|
34
42
|
require 'json/ld'
|
35
43
|
```
|
44
|
+
|
36
45
|
### Expand a Document
|
46
|
+
|
37
47
|
```ruby
|
38
48
|
input = JSON.parse %({
|
39
49
|
"@context": {
|
@@ -53,8 +63,9 @@ require 'json/ld'
|
|
53
63
|
"http://xmlns.com/foaf/0.1/avatar": [{"@value": "https://twitter.com/account/profile_image/manusporny"}]
|
54
64
|
}]
|
55
65
|
```
|
66
|
+
|
56
67
|
### Compact a Document
|
57
|
-
|
68
|
+
|
58
69
|
input = JSON.parse %([{
|
59
70
|
"http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
|
60
71
|
"http://xmlns.com/foaf/0.1/homepage": [{"@id": "https://manu.sporny.org/"}],
|
@@ -80,9 +91,9 @@ require 'json/ld'
|
|
80
91
|
"homepage": "https://manu.sporny.org/",
|
81
92
|
"name": "Manu Sporny"
|
82
93
|
}
|
83
|
-
|
94
|
+
|
84
95
|
### Frame a Document
|
85
|
-
|
96
|
+
|
86
97
|
input = JSON.parse %({
|
87
98
|
"@context": {
|
88
99
|
"Book": "http://example.org/vocab#Book",
|
@@ -163,9 +174,9 @@ require 'json/ld'
|
|
163
174
|
}
|
164
175
|
]
|
165
176
|
}
|
166
|
-
|
177
|
+
|
167
178
|
### Turn JSON-LD into RDF (Turtle)
|
168
|
-
|
179
|
+
|
169
180
|
input = JSON.parse %({
|
170
181
|
"@context": {
|
171
182
|
"": "https://manu.sporny.org/",
|
@@ -186,9 +197,9 @@ require 'json/ld'
|
|
186
197
|
<http://example.org/people#joebob> a foaf:Person;
|
187
198
|
foaf:name "Joe Bob";
|
188
199
|
foaf:nick ("joe" "bob" "jaybe") .
|
189
|
-
|
200
|
+
|
190
201
|
### Turn RDF into JSON-LD
|
191
|
-
|
202
|
+
|
192
203
|
require 'rdf/turtle'
|
193
204
|
input = RDF::Graph.new << RDF::Turtle::Reader.new(%(
|
194
205
|
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
@@ -224,13 +235,14 @@ require 'json/ld'
|
|
224
235
|
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
|
225
236
|
}
|
226
237
|
]
|
227
|
-
|
238
|
+
|
228
239
|
## Use a custom Document Loader
|
229
240
|
In some cases, the built-in document loader {JSON::LD::API.documentLoader} is inadequate; for example, when using `http://schema.org` as a remote context, it will be re-loaded every time (however, see [json-ld-preloaded](https://rubygems.org/gems/json-ld-preloaded)).
|
230
241
|
|
231
242
|
All entries into the {JSON::LD::API} accept a `:documentLoader` option, which can be used to provide an alternative method to use when loading remote documents. For example:
|
243
|
+
|
232
244
|
```ruby
|
233
|
-
|
245
|
+
load_document_local = Proc.new do |url, **options, &block|
|
234
246
|
if RDF::URI(url, canonicalize: true) == RDF::URI('http://schema.org/')
|
235
247
|
remote_document = JSON::LD::API::RemoteDocument.new(url, File.read("etc/schema.org.jsonld"))
|
236
248
|
return block_given? ? yield(remote_document) : remote_document
|
@@ -238,28 +250,34 @@ def load_document_local(url, options={}, &block)
|
|
238
250
|
JSON::LD::API.documentLoader(url, options, &block)
|
239
251
|
end
|
240
252
|
end
|
253
|
+
|
241
254
|
```
|
242
255
|
Then, when performing something like expansion:
|
256
|
+
|
243
257
|
```ruby
|
244
258
|
JSON::LD::API.expand(input, documentLoader: load_document_local)
|
245
259
|
```
|
246
260
|
|
247
261
|
## Preloading contexts
|
248
262
|
In many cases, for small documents, processing time can be dominated by loading and parsing remote contexts. In particular, a small schema.org example may need to download a large context and turn it into an internal representation, before the actual document can be expanded for processing. Using {JSON::LD::Context.add_preloaded}, an implementation can perform this loading up-front, and make it available to the processor.
|
263
|
+
|
249
264
|
```ruby
|
250
265
|
ctx = JSON::LD::Context.new().parse('http://schema.org/')
|
251
266
|
JSON::LD::Context.add_preloaded('http://schema.org/', ctx)
|
252
267
|
```
|
268
|
+
|
253
269
|
On lookup, URIs with an `https` prefix are normalized to `http`.
|
254
270
|
|
255
271
|
A context may be serialized to Ruby to speed this process using `Context#to_rb`. When loaded, this generated file will add entries to the {JSON::LD::Context::PRELOADED}.
|
256
272
|
|
257
273
|
## RDF Reader and Writer
|
258
274
|
{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
|
275
|
+
|
259
276
|
```ruby
|
260
277
|
graph = RDF::Graph.load("etc/doap.jsonld", format: :jsonld)
|
261
278
|
graph.dump(:jsonld, standard_prefixes: true)
|
262
279
|
```
|
280
|
+
|
263
281
|
`RDF::GRAPH#dump` can also take a `:context` option to use a separately defined context
|
264
282
|
|
265
283
|
As JSON-LD may come from many different sources, included as an embedded script tag within an HTML document, the RDF Reader will strip input before the leading `{` or `[` and after the trailing `}` or `]`.
|
@@ -269,7 +287,7 @@ This implementation is being used as a test-bed for features planned for an upco
|
|
269
287
|
|
270
288
|
### Scoped Contexts
|
271
289
|
A term definition can include `@context`, which is applied to values of that object. This is also used when compacting. Taken together, this allows framing to effectively include context definitions more deeply within the framed structure.
|
272
|
-
|
290
|
+
|
273
291
|
{
|
274
292
|
"@context": {
|
275
293
|
"ex": "http://example.com/",
|
@@ -284,10 +302,10 @@ A term definition can include `@context`, which is applied to values of that obj
|
|
284
302
|
},
|
285
303
|
"foo": "Bar"
|
286
304
|
}
|
287
|
-
|
305
|
+
|
288
306
|
### @id and @type maps
|
289
307
|
The value of `@container` in a term definition can include `@id` or `@type`, in addition to `@set`, `@list`, `@language`, and `@index`. This allows value indexing based on either the `@id` or `@type` of associated objects.
|
290
|
-
|
308
|
+
|
291
309
|
{
|
292
310
|
"@context": {
|
293
311
|
"@vocab": "http://example/",
|
@@ -298,10 +316,10 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
|
|
298
316
|
"_:bar": {"label": "Object with @id _:bar"}
|
299
317
|
}
|
300
318
|
}
|
301
|
-
|
319
|
+
|
302
320
|
### @graph containers and maps
|
303
321
|
A term can have `@container` set to include `@graph` optionally including `@id` or `@index` and `@set`. In the first form, with `@container` set to `@graph`, the value of a property is treated as a _simple graph object_, meaning that values treated as if they were contained in an object with `@graph`, creating _named graph_ with an anonymous name.
|
304
|
-
|
322
|
+
|
305
323
|
{
|
306
324
|
"@context": {
|
307
325
|
"@vocab": "http://example.org/",
|
@@ -311,9 +329,9 @@ A term can have `@container` set to include `@graph` optionally including `@id`
|
|
311
329
|
"value": "x"
|
312
330
|
}
|
313
331
|
}
|
314
|
-
|
332
|
+
|
315
333
|
which expands to the following:
|
316
|
-
|
334
|
+
|
317
335
|
[{
|
318
336
|
"http://example.org/input": [{
|
319
337
|
"@graph": [{
|
@@ -321,18 +339,18 @@ which expands to the following:
|
|
321
339
|
}]
|
322
340
|
}]
|
323
341
|
}]
|
324
|
-
|
342
|
+
|
325
343
|
Compaction reverses this process, optionally ensuring that a single value is contained within an array of `@container` also includes `@set`:
|
326
|
-
|
344
|
+
|
327
345
|
{
|
328
346
|
"@context": {
|
329
347
|
"@vocab": "http://example.org/",
|
330
348
|
"input": {"@container": ["@graph", "@set"]}
|
331
349
|
}
|
332
350
|
}
|
333
|
-
|
351
|
+
|
334
352
|
A graph map uses the map form already existing for `@index`, `@language`, `@type`, and `@id` where the index is either an index value or an id.
|
335
|
-
|
353
|
+
|
336
354
|
{
|
337
355
|
"@context": {
|
338
356
|
"@vocab": "http://example.org/",
|
@@ -342,9 +360,9 @@ A graph map uses the map form already existing for `@index`, `@language`, `@type
|
|
342
360
|
"g1": {"value": "x"}
|
343
361
|
}
|
344
362
|
}
|
345
|
-
|
363
|
+
|
346
364
|
treats "g1" as an index, and expands to the following:
|
347
|
-
|
365
|
+
|
348
366
|
[{
|
349
367
|
"http://example.org/input": [{
|
350
368
|
"@index": "g1",
|
@@ -353,11 +371,11 @@ treats "g1" as an index, and expands to the following:
|
|
353
371
|
}]
|
354
372
|
}]
|
355
373
|
}])
|
356
|
-
|
374
|
+
|
357
375
|
This can also include `@set` to ensure that, when compacting, a single value of an index will be in array form.
|
358
376
|
|
359
377
|
The _id_ version is similar:
|
360
|
-
|
378
|
+
|
361
379
|
{
|
362
380
|
"@context": {
|
363
381
|
"@vocab": "http://example.org/",
|
@@ -367,9 +385,9 @@ The _id_ version is similar:
|
|
367
385
|
"http://example.com/g1": {"value": "x"}
|
368
386
|
}
|
369
387
|
}
|
370
|
-
|
388
|
+
|
371
389
|
which expands to:
|
372
|
-
|
390
|
+
|
373
391
|
[{
|
374
392
|
"http://example.org/input": [{
|
375
393
|
"@id": "http://example.com/g1",
|
@@ -378,10 +396,10 @@ which expands to:
|
|
378
396
|
}]
|
379
397
|
}]
|
380
398
|
}])
|
381
|
-
|
399
|
+
|
382
400
|
### Transparent Nesting
|
383
401
|
Many JSON APIs separate properties from their entities using an intermediate object. For example, a set of possible labels may be grouped under a common property:
|
384
|
-
|
402
|
+
|
385
403
|
{
|
386
404
|
"@context": {
|
387
405
|
"skos": "http://www.w3.org/2004/02/skos/core#",
|
@@ -397,9 +415,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
|
|
397
415
|
"other_label": "This is the other label"
|
398
416
|
}
|
399
417
|
}
|
400
|
-
|
418
|
+
|
401
419
|
In this case, the `labels` property is semantically meaningless. Defining it as equivalent to `@nest` causes it to be ignored when expanding, making it equivalent to the following:
|
402
|
-
|
420
|
+
|
403
421
|
{
|
404
422
|
"@context": {
|
405
423
|
"skos": "http://www.w3.org/2004/02/skos/core#",
|
@@ -413,9 +431,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
|
|
413
431
|
"main_label": "This is the main label for my resource",
|
414
432
|
"other_label": "This is the other label"
|
415
433
|
}
|
416
|
-
|
434
|
+
|
417
435
|
Similarly, properties may be marked with "@nest": "nest-term", to cause them to be nested. Note that the `@nest` keyword can also be aliased in the context.
|
418
|
-
|
436
|
+
|
419
437
|
{
|
420
438
|
"@context": {
|
421
439
|
"skos": "http://www.w3.org/2004/02/skos/core#",
|
@@ -431,7 +449,7 @@ Many JSON APIs separate properties from their entities using an intermediate obj
|
|
431
449
|
"other_label": "This is the other label"
|
432
450
|
}
|
433
451
|
}
|
434
|
-
|
452
|
+
|
435
453
|
In this way, nesting survives round-tripping through expansion, and framed output can include nested properties.
|
436
454
|
|
437
455
|
## Sinatra/Rack support
|
@@ -509,14 +527,14 @@ Note, the API method signatures differed in versions before 1.0, in that they al
|
|
509
527
|
## Installation
|
510
528
|
The recommended installation method is via [RubyGems](https://rubygems.org/).
|
511
529
|
To install the latest official release of the `JSON-LD` gem, do:
|
512
|
-
|
513
|
-
|
514
|
-
|
530
|
+
|
531
|
+
% [sudo] gem install json-ld
|
532
|
+
|
515
533
|
## Download
|
516
534
|
To get a local working copy of the development repository, do:
|
517
|
-
|
518
|
-
|
519
|
-
|
535
|
+
|
536
|
+
% git clone git://github.com/ruby-rdf/json-ld.git
|
537
|
+
|
520
538
|
## Mailing List
|
521
539
|
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
522
540
|
|
@@ -534,7 +552,9 @@ To get a local working copy of the development repository, do:
|
|
534
552
|
list in the the `README`. Alphabetical order applies.
|
535
553
|
* Do note that in order for us to merge any non-trivial changes (as a rule
|
536
554
|
of thumb, additions larger than about 15 lines of code), we need an
|
537
|
-
explicit [public domain dedication][PDD] on record from you
|
555
|
+
explicit [public domain dedication][PDD] on record from you,
|
556
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
557
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
538
558
|
|
539
559
|
License
|
540
560
|
-------
|
@@ -546,7 +566,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
546
566
|
[RDF]: https://www.w3.org/RDF/
|
547
567
|
[YARD]: https://yardoc.org/
|
548
568
|
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
549
|
-
[PDD]: https://
|
569
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
550
570
|
[RDF.rb]: https://rubygems.org/gems/rdf
|
551
571
|
[Rack::LinkedData]: https://rubygems.org/gems/rack-linkeddata
|
552
572
|
[Backports]: https://rubygems.org/gems/backports
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.5
|
data/bin/jsonld
CHANGED
@@ -10,7 +10,7 @@ require 'getoptlong'
|
|
10
10
|
require 'open-uri'
|
11
11
|
require 'logger'
|
12
12
|
|
13
|
-
def run(input, options)
|
13
|
+
def run(input, options, parser_options)
|
14
14
|
reader_class = RDF::Reader.for(options[:input_format].to_sym)
|
15
15
|
raise "Reader not found for #{options[:input_format]}" unless reader_class
|
16
16
|
|
@@ -19,38 +19,38 @@ def run(input, options)
|
|
19
19
|
|
20
20
|
# If input format is not JSON-LD, transform input to JSON-LD first
|
21
21
|
reader = if options[:input_format] != :jsonld
|
22
|
-
reader_class.new(input,
|
22
|
+
reader_class.new(input, parser_options)
|
23
23
|
end
|
24
24
|
|
25
25
|
start = Time.new
|
26
26
|
if options[:expand]
|
27
|
-
|
27
|
+
parser_options = parser_options.merge(expandContext: parser_options.delete(:context)) if parser_options.has_key?(:context)
|
28
28
|
input = JSON::LD::API.fromRdf(reader) if reader
|
29
|
-
output = JSON::LD::API.expand(input,
|
29
|
+
output = JSON::LD::API.expand(input, parser_options)
|
30
30
|
secs = Time.new - start
|
31
31
|
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
|
32
32
|
STDERR.puts "Expanded in #{secs} seconds." unless options[:quiet]
|
33
33
|
elsif options[:compact]
|
34
34
|
input = JSON::LD::API.fromRdf(reader) if reader
|
35
|
-
output = JSON::LD::API.compact(input,
|
35
|
+
output = JSON::LD::API.compact(input, parser_options[:context], parser_options)
|
36
36
|
secs = Time.new - start
|
37
37
|
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
|
38
38
|
STDERR.puts "Compacted in #{secs} seconds." unless options[:quiet]
|
39
39
|
elsif options[:flatten]
|
40
40
|
input = JSON::LD::API.fromRdf(reader) if reader
|
41
|
-
output = JSON::LD::API.flatten(input,
|
41
|
+
output = JSON::LD::API.flatten(input, parser_options[:context], parser_options)
|
42
42
|
secs = Time.new - start
|
43
43
|
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
|
44
44
|
STDERR.puts "Flattened in #{secs} seconds." unless options[:quiet]
|
45
45
|
elsif options[:frame]
|
46
46
|
input = JSON::LD::API.fromRdf(reader) if reader
|
47
|
-
output = JSON::LD::API.frame(input,
|
47
|
+
output = JSON::LD::API.frame(input, parser_options[:frame], parser_options)
|
48
48
|
secs = Time.new - start
|
49
49
|
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
|
50
50
|
STDERR.puts "Framed in #{secs} seconds." unless options[:quiet]
|
51
51
|
else
|
52
|
-
|
53
|
-
parser_options
|
52
|
+
parser_options = parser_options.merge(expandContext: parser_options.delete(:context)) if parser_options.has_key?(:context)
|
53
|
+
parser_options[:standard_prefixes] = true
|
54
54
|
reader ||= JSON::LD::Reader.new(input, parser_options)
|
55
55
|
num = 0
|
56
56
|
RDF::Writer.for(options[:output_format]).new(options[:output], parser_options) do |w|
|
@@ -86,7 +86,6 @@ parser_options = {
|
|
86
86
|
}
|
87
87
|
|
88
88
|
options = {
|
89
|
-
parser_options: parser_options,
|
90
89
|
output: STDOUT,
|
91
90
|
output_format: :jsonld,
|
92
91
|
input_format: :jsonld,
|
@@ -141,49 +140,47 @@ opts = GetoptLong.new(*OPT_ARGS.map {|o| o[0..-2]})
|
|
141
140
|
opts.each do |opt, arg|
|
142
141
|
case opt
|
143
142
|
when '--debug' then logger.level = Logger::DEBUG
|
144
|
-
when '--compact' then
|
145
|
-
when "--compactArrays" then
|
146
|
-
when '--context' then
|
143
|
+
when '--compact' then parser_options[:compact] = true
|
144
|
+
when "--compactArrays" then parser_options[:compactArrays] = (arg || 'true') == 'true'
|
145
|
+
when '--context' then parser_options[:context] = RDF::URI(arg).absolute? ? arg : File.open(arg)
|
147
146
|
when '--evaluate' then input = arg
|
148
147
|
when '--expand' then options[:expand] = true
|
149
|
-
when "--expanded" then
|
150
|
-
when "--explicit" then
|
148
|
+
when "--expanded" then parser_options[:expanded] = (arg || 'true') == 'true'
|
149
|
+
when "--explicit" then parser_options[:compactArrays] = (arg || 'true') == 'true'
|
151
150
|
when '--format' then options[:output_format] = arg.to_sym
|
152
151
|
when '--flatten' then options[:flatten] = arg
|
153
|
-
when '--frame' then options[:frame] = arg
|
152
|
+
when '--frame' then options[:frame] = parser_otpions[:frame] = RDF::URI(arg).absolute? ? arg : File.open(arg)
|
154
153
|
when '--input-format' then options[:input_format] = arg.to_sym
|
155
|
-
when "--omitDefault" then
|
154
|
+
when "--omitDefault" then parser_options[:omitDefault] = (arg || 'true') == 'true'
|
156
155
|
when '--output' then options[:output] = File.open(arg, "w")
|
157
156
|
when '--parse-only' then options[:parse_only] = true
|
158
|
-
when '--processingMode' then
|
157
|
+
when '--processingMode' then parser_options[:processingMode] = arg
|
159
158
|
when '--quiet'
|
160
159
|
options[:quiet] = true
|
161
160
|
logger.level = Logger::FATAL
|
162
|
-
when "--rename_bnodes" then
|
163
|
-
when "--requireAll" then
|
161
|
+
when "--rename_bnodes" then parser_options[:rename_bnodes] = (arg || 'true') == 'true'
|
162
|
+
when "--requireAll" then parser_options[:requireAll] = (arg || 'true') == 'true'
|
164
163
|
when '--stream' then parser_options[:stream] = true
|
165
|
-
when "--unique_bnodes" then
|
164
|
+
when "--unique_bnodes" then parser_options[:unique_bnodes] = (arg || 'true') == 'true'
|
166
165
|
when '--uri' then parser_options[:base] = arg
|
167
166
|
when '--validate' then parser_options[:validate] = true
|
168
167
|
when '--help' then usage
|
169
168
|
when '--embed'
|
170
169
|
case arg
|
171
|
-
when '@always', '@never', '@link', '@
|
172
|
-
|
170
|
+
when '@always', '@never', '@link', '@once'
|
171
|
+
parser_options[:embed] = arg
|
173
172
|
when 'true'
|
174
|
-
|
173
|
+
parser_options[:embed] = '@never'
|
175
174
|
when 'false'
|
176
|
-
|
175
|
+
parser_options[:embed] = '@first'
|
177
176
|
else
|
178
|
-
STDERR.puts "--embed option takes one of @always, @never, @link,
|
177
|
+
STDERR.puts "--embed option takes one of @always, @never, @link, or @once"
|
179
178
|
exit(1)
|
180
179
|
end
|
181
180
|
end
|
182
181
|
end
|
183
182
|
|
184
183
|
# Hack
|
185
|
-
options[:parser_options][:context] = options[:context] if parser_options[:stream]
|
186
|
-
|
187
184
|
if !(options.keys & [:expand, :compact, :flatten, :frame]).empty? &&
|
188
185
|
(parser_options[:stream] || options[:output_format] != :jsonld)
|
189
186
|
STDERR.puts "Incompatible options"
|
@@ -192,11 +189,11 @@ end
|
|
192
189
|
|
193
190
|
if ARGV.empty?
|
194
191
|
s = input ? input : $stdin.read
|
195
|
-
run(StringIO.new(s), options)
|
192
|
+
run(StringIO.new(s), options, parser_options)
|
196
193
|
else
|
197
194
|
ARGV.each do |file|
|
198
195
|
# Call with opened files
|
199
|
-
RDF::Util::File.open_file(file, options) {|f| run(f, options)}
|
196
|
+
RDF::Util::File.open_file(file, options) {|f| run(f, options, parser_options)}
|
200
197
|
end
|
201
198
|
end
|
202
199
|
puts
|