You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
229
229
230
230
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:
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.
On lookup, URIs with an `https` prefix are normalized to `http`.
253
253
254
254
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}.
255
255
256
256
## RDF Reader and Writer
257
257
{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
`RDF::GRAPH#dump` can also take a `:context` option to use a separately defined context
263
263
264
264
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 `]`.
@@ -268,7 +268,7 @@ This implementation is being used as a test-bed for features planned for an upco
268
268
269
269
### Scoped Contexts
270
270
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.
271
-
271
+
```ruby
272
272
{
273
273
"@context": {
274
274
"ex": "http://example.com/",
@@ -283,10 +283,10 @@ A term definition can include `@context`, which is applied to values of that obj
283
283
},
284
284
"foo": "Bar"
285
285
}
286
-
286
+
```
287
287
### @id and @type maps
288
288
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.
289
-
289
+
```ruby
290
290
{
291
291
"@context": {
292
292
"@vocab": "http://example/",
@@ -297,10 +297,10 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
297
297
"_:bar": {"label": "Object with @id _:bar"}
298
298
}
299
299
}
300
-
300
+
```
301
301
### @graph containers and maps
302
302
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.
303
-
303
+
```ruby
304
304
{
305
305
"@context": {
306
306
"@vocab": "http://example.org/",
@@ -310,28 +310,28 @@ A term can have `@container` set to include `@graph` optionally including `@id`
310
310
"value": "x"
311
311
}
312
312
}
313
-
313
+
```
314
314
which expands to the following:
315
-
315
+
```ruby
316
316
[{
317
317
"http://example.org/input": [{
318
318
"@graph": [{
319
319
"http://example.org/value": [{"@value": "x"}]
320
320
}]
321
321
}]
322
322
}]
323
-
323
+
```
324
324
Compaction reverses this process, optionally ensuring that a single value is contained within an array of `@container` also includes `@set`:
325
-
325
+
```ruby
326
326
{
327
327
"@context": {
328
328
"@vocab": "http://example.org/",
329
329
"input": {"@container": ["@graph", "@set"]}
330
330
}
331
331
}
332
-
332
+
```
333
333
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.
334
-
334
+
```ruby
335
335
{
336
336
"@context": {
337
337
"@vocab": "http://example.org/",
@@ -341,9 +341,9 @@ A graph map uses the map form already existing for `@index`, `@language`, `@type
341
341
"g1": {"value": "x"}
342
342
}
343
343
}
344
-
344
+
```
345
345
treats "g1" as an index, and expands to the following:
346
-
346
+
```ruby
347
347
[{
348
348
"http://example.org/input": [{
349
349
"@index": "g1",
@@ -352,11 +352,11 @@ treats "g1" as an index, and expands to the following:
352
352
}]
353
353
}]
354
354
}])
355
-
355
+
```
356
356
This can also include `@set` to ensure that, when compacting, a single value of an index will be in array form.
357
357
358
358
The _id_ version is similar:
359
-
359
+
```ruby
360
360
{
361
361
"@context": {
362
362
"@vocab": "http://example.org/",
@@ -366,9 +366,9 @@ The _id_ version is similar:
366
366
"http://example.com/g1": {"value": "x"}
367
367
}
368
368
}
369
-
369
+
```
370
370
which expands to:
371
-
371
+
```ruby
372
372
[{
373
373
"http://example.org/input": [{
374
374
"@id": "http://example.com/g1",
@@ -377,10 +377,10 @@ which expands to:
377
377
}]
378
378
}]
379
379
}])
380
-
380
+
```
381
381
### Transparent Nesting
382
382
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:
383
-
383
+
```json
384
384
{
385
385
"@context": {
386
386
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -396,9 +396,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
396
396
"other_label": "This is the other label"
397
397
}
398
398
}
399
-
399
+
```
400
400
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:
401
-
401
+
```json
402
402
{
403
403
"@context": {
404
404
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -412,9 +412,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
412
412
"main_label": "This is the main label for my resource",
413
413
"other_label": "This is the other label"
414
414
}
415
-
415
+
```
416
416
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.
417
-
417
+
```json
418
418
{
419
419
"@context": {
420
420
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -430,7 +430,7 @@ Many JSON APIs separate properties from their entities using an intermediate obj
430
430
"other_label": "This is the other label"
431
431
}
432
432
}
433
-
433
+
```
434
434
In this way, nesting survives round-tripping through expansion, and framed output can include nested properties.
435
435
436
436
### Framing Updates
@@ -469,20 +469,20 @@ Note, the API method signatures differed in versions before 1.0, in that they al
469
469
470
470
## Dependencies
471
471
*[Ruby](http://ruby-lang.org/) (>= 2.2.2)
472
-
*[RDF.rb](http://rubygems.org/gems/rdf) (>= 2.2)
473
-
*[JSON](https://rubygems.org/gems/json) (>= 1.5)
472
+
*[RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
473
+
*[JSON](https://rubygems.org/gems/json) (>= 2.1)
474
474
475
475
## Installation
476
476
The recommended installation method is via [RubyGems](http://rubygems.org/).
477
477
To install the latest official release of the `JSON-LD` gem, do:
478
-
479
-
% [sudo] gem install json-ld
480
-
478
+
```bash
479
+
% [sudo] gem install json-ld
480
+
```
481
481
## Download
482
482
To get a local working copy of the development repository, do:
0 commit comments