Skip to content

Commit cdece75

Browse files
committed
Finish 3.1.5
2 parents 73bf2cf + 24105ae commit cdece75

27 files changed

+5454
-2559
lines changed

.yardopts

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
AUTHORS
1010
VERSION
1111
UNLICENSE
12-
etc/earl.html

CONTRIBUTING.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
2828
enough, be assured we will eventually add you in there.
2929
* Do note that in order for us to merge any non-trivial changes (as a rule
3030
of thumb, additions larger than about 15 lines of code), we need an
31-
explicit [public domain dedication][PDD] on record from you.
31+
explicit [public domain dedication][PDD] on record from you,
32+
which you will be asked to agree to on the first commit to a repo within the organization.
33+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
3234

3335
[YARD]: https://yardoc.org/
3436
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
35-
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
36-
[pr]: https://github.com/ruby-rdf/json-ld/compare/
37+
[PDD]: https://unlicense.org/#unlicensing-contributions
38+
[pr]: https://github.com/ruby-rdf/rdf/compare/

README.md

+60-46
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@ This gem implements an optimized streaming reader used for generating RDF from l
2525
* 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.
2626
* 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`.
2727

28-
### MultiJson parser
29-
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-
31-
### JSON-LD Streaming Profile
32-
This gem implements an optimized streaming writer used for generating JSON-LD from large repositories. Such documents result in the JSON-LD Streaming Profile:
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:
3329

3430
* Each statement written as a separate node in expanded/flattened form.
35-
* RDF Lists are written as separate nodes using `rdf:first` and `rdf:rest` properties.
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.
3637

3738
## Examples
39+
3840
```ruby
3941
require 'rubygems'
4042
require 'json/ld'
4143
```
44+
4245
### Expand a Document
46+
4347
```ruby
4448
input = JSON.parse %({
4549
"@context": {
@@ -59,8 +63,9 @@ require 'json/ld'
5963
"http://xmlns.com/foaf/0.1/avatar": [{"@value": "https://twitter.com/account/profile_image/manusporny"}]
6064
}]
6165
```
66+
6267
### Compact a Document
63-
```ruby
68+
6469
input = JSON.parse %([{
6570
"http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
6671
"http://xmlns.com/foaf/0.1/homepage": [{"@id": "https://manu.sporny.org/"}],
@@ -86,9 +91,9 @@ require 'json/ld'
8691
"homepage": "https://manu.sporny.org/",
8792
"name": "Manu Sporny"
8893
}
89-
```
94+
9095
### Frame a Document
91-
```ruby
96+
9297
input = JSON.parse %({
9398
"@context": {
9499
"Book": "http://example.org/vocab#Book",
@@ -169,9 +174,9 @@ require 'json/ld'
169174
}
170175
]
171176
}
172-
```
177+
173178
### Turn JSON-LD into RDF (Turtle)
174-
```ruby
179+
175180
input = JSON.parse %({
176181
"@context": {
177182
"": "https://manu.sporny.org/",
@@ -192,9 +197,9 @@ require 'json/ld'
192197
<http://example.org/people#joebob> a foaf:Person;
193198
foaf:name "Joe Bob";
194199
foaf:nick ("joe" "bob" "jaybe") .
195-
```
200+
196201
### Turn RDF into JSON-LD
197-
```ruby
202+
198203
require 'rdf/turtle'
199204
input = RDF::Graph.new << RDF::Turtle::Reader.new(%(
200205
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@@ -230,11 +235,12 @@ require 'json/ld'
230235
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
231236
}
232237
]
233-
```
238+
234239
## Use a custom Document Loader
235240
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)).
236241

237242
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+
238244
```ruby
239245
load_document_local = Proc.new do |url, **options, &block|
240246
if RDF::URI(url, canonicalize: true) == RDF::URI('http://schema.org/')
@@ -244,28 +250,34 @@ load_document_local = Proc.new do |url, **options, &block|
244250
JSON::LD::API.documentLoader(url, options, &block)
245251
end
246252
end
253+
247254
```
248255
Then, when performing something like expansion:
256+
249257
```ruby
250258
JSON::LD::API.expand(input, documentLoader: load_document_local)
251259
```
252260

253261
## Preloading contexts
254262
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+
255264
```ruby
256265
ctx = JSON::LD::Context.new().parse('http://schema.org/')
257266
JSON::LD::Context.add_preloaded('http://schema.org/', ctx)
258267
```
268+
259269
On lookup, URIs with an `https` prefix are normalized to `http`.
260270

261271
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}.
262272

263273
## RDF Reader and Writer
264274
{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
275+
265276
```ruby
266277
graph = RDF::Graph.load("etc/doap.jsonld", format: :jsonld)
267278
graph.dump(:jsonld, standard_prefixes: true)
268279
```
280+
269281
`RDF::GRAPH#dump` can also take a `:context` option to use a separately defined context
270282

271283
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 `]`.
@@ -275,7 +287,7 @@ This implementation is being used as a test-bed for features planned for an upco
275287

276288
### Scoped Contexts
277289
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.
278-
```ruby
290+
279291
{
280292
"@context": {
281293
"ex": "http://example.com/",
@@ -290,10 +302,10 @@ A term definition can include `@context`, which is applied to values of that obj
290302
},
291303
"foo": "Bar"
292304
}
293-
```
305+
294306
### @id and @type maps
295307
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.
296-
```ruby
308+
297309
{
298310
"@context": {
299311
"@vocab": "http://example/",
@@ -304,10 +316,10 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
304316
"_:bar": {"label": "Object with @id _:bar"}
305317
}
306318
}
307-
```
319+
308320
### @graph containers and maps
309321
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.
310-
```ruby
322+
311323
{
312324
"@context": {
313325
"@vocab": "http://example.org/",
@@ -317,28 +329,28 @@ A term can have `@container` set to include `@graph` optionally including `@id`
317329
"value": "x"
318330
}
319331
}
320-
```
332+
321333
which expands to the following:
322-
```ruby
334+
323335
[{
324336
"http://example.org/input": [{
325337
"@graph": [{
326338
"http://example.org/value": [{"@value": "x"}]
327339
}]
328340
}]
329341
}]
330-
```
342+
331343
Compaction reverses this process, optionally ensuring that a single value is contained within an array of `@container` also includes `@set`:
332-
```ruby
344+
333345
{
334346
"@context": {
335347
"@vocab": "http://example.org/",
336348
"input": {"@container": ["@graph", "@set"]}
337349
}
338350
}
339-
```
351+
340352
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.
341-
```ruby
353+
342354
{
343355
"@context": {
344356
"@vocab": "http://example.org/",
@@ -348,9 +360,9 @@ A graph map uses the map form already existing for `@index`, `@language`, `@type
348360
"g1": {"value": "x"}
349361
}
350362
}
351-
```
363+
352364
treats "g1" as an index, and expands to the following:
353-
```ruby
365+
354366
[{
355367
"http://example.org/input": [{
356368
"@index": "g1",
@@ -359,11 +371,11 @@ treats "g1" as an index, and expands to the following:
359371
}]
360372
}]
361373
}])
362-
```
374+
363375
This can also include `@set` to ensure that, when compacting, a single value of an index will be in array form.
364376

365377
The _id_ version is similar:
366-
```ruby
378+
367379
{
368380
"@context": {
369381
"@vocab": "http://example.org/",
@@ -373,9 +385,9 @@ The _id_ version is similar:
373385
"http://example.com/g1": {"value": "x"}
374386
}
375387
}
376-
```
388+
377389
which expands to:
378-
```ruby
390+
379391
[{
380392
"http://example.org/input": [{
381393
"@id": "http://example.com/g1",
@@ -384,10 +396,10 @@ which expands to:
384396
}]
385397
}]
386398
}])
387-
```
399+
388400
### Transparent Nesting
389401
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:
390-
```json
402+
391403
{
392404
"@context": {
393405
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -403,9 +415,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
403415
"other_label": "This is the other label"
404416
}
405417
}
406-
```
418+
407419
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:
408-
```json
420+
409421
{
410422
"@context": {
411423
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -419,9 +431,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
419431
"main_label": "This is the main label for my resource",
420432
"other_label": "This is the other label"
421433
}
422-
```
434+
423435
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.
424-
```json
436+
425437
{
426438
"@context": {
427439
"skos": "http://www.w3.org/2004/02/skos/core#",
@@ -437,7 +449,7 @@ Many JSON APIs separate properties from their entities using an intermediate obj
437449
"other_label": "This is the other label"
438450
}
439451
}
440-
```
452+
441453
In this way, nesting survives round-tripping through expansion, and framed output can include nested properties.
442454

443455
## Sinatra/Rack support
@@ -515,14 +527,14 @@ Note, the API method signatures differed in versions before 1.0, in that they al
515527
## Installation
516528
The recommended installation method is via [RubyGems](https://rubygems.org/).
517529
To install the latest official release of the `JSON-LD` gem, do:
518-
```bash
519-
% [sudo] gem install json-ld
520-
```
530+
531+
% [sudo] gem install json-ld
532+
521533
## Download
522534
To get a local working copy of the development repository, do:
523-
```bash
524-
% git clone git://github.com/ruby-rdf/json-ld.git
525-
```
535+
536+
% git clone git://github.com/ruby-rdf/json-ld.git
537+
526538
## Mailing List
527539
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
528540

@@ -540,7 +552,9 @@ To get a local working copy of the development repository, do:
540552
list in the the `README`. Alphabetical order applies.
541553
* Do note that in order for us to merge any non-trivial changes (as a rule
542554
of thumb, additions larger than about 15 lines of code), we need an
543-
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.
544558

545559
License
546560
-------
@@ -552,7 +566,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
552566
[RDF]: https://www.w3.org/RDF/
553567
[YARD]: https://yardoc.org/
554568
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
555-
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
569+
[PDD]: https://unlicense.org/#unlicensing-contributions
556570
[RDF.rb]: https://rubygems.org/gems/rdf
557571
[Rack::LinkedData]: https://rubygems.org/gems/rack-linkeddata
558572
[Backports]: https://rubygems.org/gems/backports

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.4
1+
3.1.5

0 commit comments

Comments
 (0)