Skip to content

Commit 5f042eb

Browse files
committed
Finish 3.0.0
2 parents d43a850 + 9a3994f commit 5f042eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2328
-752
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.yardoc/
22
/doc/
3+
/coverage/
34
/*.gem
45
/coverage/
56
/spec.html

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
language: ruby
22
bundler_args: --without debug
33
script: "bundle exec rspec spec"
4+
before_install:
5+
- "gem update --system"
6+
- "gem install bundler"
47
env:
58
- CI=true
69
rvm:
710
- 2.2
811
- 2.3
912
- 2.4
13+
- 2.5
1014
- jruby-9
1115
- rbx-3
1216
cache: bundler

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ gemspec
44
gem 'rdf', git: "https://github.com/ruby-rdf/rdf", branch: "develop"
55

66
group :development do
7-
gem 'ebnf', git: "https://github.com/gkellogg/ebnf", branch: "develop"
7+
gem 'ebnf', git: "https://github.com/dryruby/ebnf", branch: "develop"
88
gem 'sxp', git: "https://github.com/dryruby/sxp.rb", branch: "develop"
9-
#gem 'linkeddata', git: "https://github.com/ruby-rdf/linkeddata", branch: "develop"
9+
gem 'linkeddata', git: "https://github.com/ruby-rdf/linkeddata", branch: "develop"
1010
gem 'rdf-spec', git: "https://github.com/ruby-rdf/rdf-spec", branch: "develop"
1111
gem 'rdf-isomorphic', git: "https://github.com/ruby-rdf/rdf-isomorphic", branch: "develop"
1212
gem 'rdf-trig', git: "https://github.com/ruby-rdf/rdf-trig", branch: "develop"

README.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
2828
* RDF Lists are written as separate nodes using `rdf:first` and `rdf:rest` properties.
2929

3030
## Examples
31-
32-
require 'rubygems'
33-
require 'json/ld'
34-
31+
```ruby
32+
require 'rubygems'
33+
require 'json/ld'
34+
```
3535
### Expand a Document
36-
37-
input = JSON.parse %({
36+
```ruby
37+
input = JSON.parse %({
3838
"@context": {
3939
"name": "http://xmlns.com/foaf/0.1/name",
4040
"homepage": "http://xmlns.com/foaf/0.1/homepage",
@@ -51,9 +51,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
5151
"http://xmlns.com/foaf/0.1/homepage": [{"@value"=>"http://manu.sporny.org/"}],
5252
"http://xmlns.com/foaf/0.1/avatar": [{"@value": "http://twitter.com/account/profile_image/manusporny"}]
5353
}]
54-
54+
```
5555
### Compact a Document
56-
56+
```ruby
5757
input = JSON.parse %([{
5858
"http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
5959
"http://xmlns.com/foaf/0.1/homepage": [{"@id": "http://manu.sporny.org/"}],
@@ -79,9 +79,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
7979
"homepage": "http://manu.sporny.org/",
8080
"name": "Manu Sporny"
8181
}
82-
82+
```
8383
### Frame a Document
84-
84+
```ruby
8585
input = JSON.parse %({
8686
"@context": {
8787
"Book": "http://example.org/vocab#Book",
@@ -162,9 +162,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
162162
}
163163
]
164164
}
165-
165+
```
166166
### Turn JSON-LD into RDF (Turtle)
167-
167+
```ruby
168168
input = JSON.parse %({
169169
"@context": {
170170
"": "http://manu.sporny.org/",
@@ -185,9 +185,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
185185
<http://example.org/people#joebob> a foaf:Person;
186186
foaf:name "Joe Bob";
187187
foaf:nick ("joe" "bob" "jaybe") .
188-
188+
```
189189
### Turn RDF into JSON-LD
190-
190+
```ruby
191191
require 'rdf/turtle'
192192
input = RDF::Graph.new << RDF::Turtle::Reader.new(%(
193193
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@@ -223,12 +223,12 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
223223
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
224224
}
225225
]
226-
226+
```
227227
## Use a custom Document Loader
228228
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.
229229

230230
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:
231-
231+
```ruby
232232
def load_document_local(url, options={}, &block)
233233
if RDF::URI(url, canonicalize: true) == RDF::URI('http://schema.org/')
234234
remote_document = JSON::LD::API::RemoteDocument.new(url, File.read("etc/schema.org.jsonld"))
@@ -237,28 +237,28 @@ All entries into the {JSON::LD::API} accept a `:documentLoader` option, which ca
237237
JSON::LD::API.documentLoader(url, options, &block)
238238
end
239239
end
240-
240+
```
241241
Then, when performing something like expansion:
242-
242+
```ruby
243243
JSON::LD::API.expand(input, documentLoader: load_document_local)
244-
244+
```
245245

246246
## Preloading contexts
247247
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.
248-
248+
```ruby
249249
ctx = JSON::LD::Context.new().parse('http://schema.org/')
250250
JSON::LD::Context.add_preloaded('http://schema.org/', ctx)
251-
251+
```
252252
On lookup, URIs with an `https` prefix are normalized to `http`.
253253

254254
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}.
255255

256256
## RDF Reader and Writer
257257
{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
258-
258+
```ruby
259259
graph = RDF::Graph.load("etc/doap.jsonld", format: :jsonld)
260260
graph.dump(:jsonld, standard_prefixes: true)
261-
261+
```
262262
`RDF::GRAPH#dump` can also take a `:context` option to use a separately defined context
263263

264264
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
268268

269269
### Scoped Contexts
270270
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
272272
{
273273
"@context": {
274274
"ex": "http://example.com/",
@@ -283,10 +283,10 @@ A term definition can include `@context`, which is applied to values of that obj
283283
},
284284
"foo": "Bar"
285285
}
286-
286+
```
287287
### @id and @type maps
288288
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
290290
{
291291
"@context": {
292292
"@vocab": "http://example/",
@@ -297,10 +297,10 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
297297
"_:bar": {"label": "Object with @id _:bar"}
298298
}
299299
}
300-
300+
```
301301
### @graph containers and maps
302302
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
304304
{
305305
"@context": {
306306
"@vocab": "http://example.org/",
@@ -310,28 +310,28 @@ A term can have `@container` set to include `@graph` optionally including `@id`
310310
"value": "x"
311311
}
312312
}
313-
313+
```
314314
which expands to the following:
315-
315+
```ruby
316316
[{
317317
"http://example.org/input": [{
318318
"@graph": [{
319319
"http://example.org/value": [{"@value": "x"}]
320320
}]
321321
}]
322322
}]
323-
323+
```
324324
Compaction reverses this process, optionally ensuring that a single value is contained within an array of `@container` also includes `@set`:
325-
325+
```ruby
326326
{
327327
"@context": {
328328
"@vocab": "http://example.org/",
329329
"input": {"@container": ["@graph", "@set"]}
330330
}
331331
}
332-
332+
```
333333
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
335335
{
336336
"@context": {
337337
"@vocab": "http://example.org/",
@@ -341,9 +341,9 @@ A graph map uses the map form already existing for `@index`, `@language`, `@type
341341
"g1": {"value": "x"}
342342
}
343343
}
344-
344+
```
345345
treats "g1" as an index, and expands to the following:
346-
346+
```ruby
347347
[{
348348
"http://example.org/input": [{
349349
"@index": "g1",
@@ -352,11 +352,11 @@ treats "g1" as an index, and expands to the following:
352352
}]
353353
}]
354354
}])
355-
355+
```
356356
This can also include `@set` to ensure that, when compacting, a single value of an index will be in array form.
357357

358358
The _id_ version is similar:
359-
359+
```ruby
360360
{
361361
"@context": {
362362
"@vocab": "http://example.org/",
@@ -366,9 +366,9 @@ The _id_ version is similar:
366366
"http://example.com/g1": {"value": "x"}
367367
}
368368
}
369-
369+
```
370370
which expands to:
371-
371+
```ruby
372372
[{
373373
"http://example.org/input": [{
374374
"@id": "http://example.com/g1",
@@ -377,10 +377,10 @@ which expands to:
377377
}]
378378
}]
379379
}])
380-
380+
```
381381
### Transparent Nesting
382382
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
384384
{
385385
"@context": {
386386
"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
396396
"other_label": "This is the other label"
397397
}
398398
}
399-
399+
```
400400
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
402402
{
403403
"@context": {
404404
"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
412412
"main_label": "This is the main label for my resource",
413413
"other_label": "This is the other label"
414414
}
415-
415+
```
416416
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
418418
{
419419
"@context": {
420420
"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
430430
"other_label": "This is the other label"
431431
}
432432
}
433-
433+
```
434434
In this way, nesting survives round-tripping through expansion, and framed output can include nested properties.
435435

436436
### Framing Updates
@@ -469,20 +469,20 @@ Note, the API method signatures differed in versions before 1.0, in that they al
469469

470470
## Dependencies
471471
* [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)
474474

475475
## Installation
476476
The recommended installation method is via [RubyGems](http://rubygems.org/).
477477
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+
```
481481
## Download
482482
To get a local working copy of the development repository, do:
483-
484-
% git clone git://github.com/ruby-rdf/json-ld.git
485-
483+
```bash
484+
% git clone git://github.com/ruby-rdf/json-ld.git
485+
```
486486
## Mailing List
487487
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
488488

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.1
1+
3.0.0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"ex:claim": [
4+
{
5+
"@graph": [
6+
{
7+
"@id": "ex:1",
8+
"https://example.com#test": [
9+
{
10+
"@value": "foo"
11+
}
12+
]
13+
}
14+
]
15+
}
16+
]
17+
}
18+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@vocab": "https://example.com#",
5+
"ex": "http://example.org/",
6+
"claim": {
7+
"@id": "ex:claim",
8+
"@container": "@graph"
9+
},
10+
"id": "@id"
11+
},
12+
"claim": {}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@vocab": "https://example.com#",
5+
"ex": "http://example.org/",
6+
"claim": {
7+
"@id": "ex:claim",
8+
"@container": "@graph"
9+
},
10+
"id": "@id"
11+
},
12+
"@graph": [
13+
{
14+
"claim": {
15+
"@graph": {
16+
"id": "ex:1",
17+
"test": "foo"
18+
}
19+
}
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)