Skip to content

Commit

Permalink
Finish 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Aug 18, 2018
2 parents d43a850 + 9a3994f commit 5f042eb
Show file tree
Hide file tree
Showing 46 changed files with 2,328 additions and 752 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.yardoc/
/doc/
/coverage/
/*.gem
/coverage/
/spec.html
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install:
- "gem update --system"
- "gem install bundler"
env:
- CI=true
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- jruby-9
- rbx-3
cache: bundler
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ gemspec
gem 'rdf', git: "https://github.com/ruby-rdf/rdf", branch: "develop"

group :development do
gem 'ebnf', git: "https://github.com/gkellogg/ebnf", branch: "develop"
gem 'ebnf', git: "https://github.com/dryruby/ebnf", branch: "develop"
gem 'sxp', git: "https://github.com/dryruby/sxp.rb", branch: "develop"
#gem 'linkeddata', git: "https://github.com/ruby-rdf/linkeddata", branch: "develop"
gem 'linkeddata', git: "https://github.com/ruby-rdf/linkeddata", branch: "develop"
gem 'rdf-spec', git: "https://github.com/ruby-rdf/rdf-spec", branch: "develop"
gem 'rdf-isomorphic', git: "https://github.com/ruby-rdf/rdf-isomorphic", branch: "develop"
gem 'rdf-trig', git: "https://github.com/ruby-rdf/rdf-trig", branch: "develop"
Expand Down
110 changes: 55 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
* RDF Lists are written as separate nodes using `rdf:first` and `rdf:rest` properties.

## Examples

require 'rubygems'
require 'json/ld'

```ruby
require 'rubygems'
require 'json/ld'
```
### Expand a Document

input = JSON.parse %({
```ruby
input = JSON.parse %({
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": "http://xmlns.com/foaf/0.1/homepage",
Expand All @@ -51,9 +51,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
"http://xmlns.com/foaf/0.1/homepage": [{"@value"=>"http://manu.sporny.org/"}],
"http://xmlns.com/foaf/0.1/avatar": [{"@value": "http://twitter.com/account/profile_image/manusporny"}]
}]

```
### Compact a Document

```ruby
input = JSON.parse %([{
"http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
"http://xmlns.com/foaf/0.1/homepage": [{"@id": "http://manu.sporny.org/"}],
Expand All @@ -79,9 +79,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
"homepage": "http://manu.sporny.org/",
"name": "Manu Sporny"
}

```
### Frame a Document

```ruby
input = JSON.parse %({
"@context": {
"Book": "http://example.org/vocab#Book",
Expand Down Expand Up @@ -162,9 +162,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
}
]
}

```
### Turn JSON-LD into RDF (Turtle)

```ruby
input = JSON.parse %({
"@context": {
"": "http://manu.sporny.org/",
Expand All @@ -185,9 +185,9 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
<http://example.org/people#joebob> a foaf:Person;
foaf:name "Joe Bob";
foaf:nick ("joe" "bob" "jaybe") .

```
### Turn RDF into JSON-LD

```ruby
require 'rdf/turtle'
input = RDF::Graph.new << RDF::Turtle::Reader.new(%(
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
Expand Down Expand Up @@ -223,12 +223,12 @@ This gem implements an optimized streaming writer used for generating JSON-LD fr
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
}
]

```
## Use a custom Document Loader
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.

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:

```ruby
def load_document_local(url, options={}, &block)
if RDF::URI(url, canonicalize: true) == RDF::URI('http://schema.org/')
remote_document = JSON::LD::API::RemoteDocument.new(url, File.read("etc/schema.org.jsonld"))
Expand All @@ -237,28 +237,28 @@ All entries into the {JSON::LD::API} accept a `:documentLoader` option, which ca
JSON::LD::API.documentLoader(url, options, &block)
end
end

```
Then, when performing something like expansion:

```ruby
JSON::LD::API.expand(input, documentLoader: load_document_local)

```

## Preloading contexts
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.

```ruby
ctx = JSON::LD::Context.new().parse('http://schema.org/')
JSON::LD::Context.add_preloaded('http://schema.org/', ctx)

```
On lookup, URIs with an `https` prefix are normalized to `http`.

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

## RDF Reader and Writer
{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:

```ruby
graph = RDF::Graph.load("etc/doap.jsonld", format: :jsonld)
graph.dump(:jsonld, standard_prefixes: true)

```
`RDF::GRAPH#dump` can also take a `:context` option to use a separately defined context

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

### Scoped Contexts
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.

```ruby
{
"@context": {
"ex": "http://example.com/",
Expand All @@ -283,10 +283,10 @@ A term definition can include `@context`, which is applied to values of that obj
},
"foo": "Bar"
}

```
### @id and @type maps
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.

```ruby
{
"@context": {
"@vocab": "http://example/",
Expand All @@ -297,10 +297,10 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
"_:bar": {"label": "Object with @id _:bar"}
}
}

```
### @graph containers and maps
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.

```ruby
{
"@context": {
"@vocab": "http://example.org/",
Expand All @@ -310,28 +310,28 @@ A term can have `@container` set to include `@graph` optionally including `@id`
"value": "x"
}
}

```
which expands to the following:

```ruby
[{
"http://example.org/input": [{
"@graph": [{
"http://example.org/value": [{"@value": "x"}]
}]
}]
}]

```
Compaction reverses this process, optionally ensuring that a single value is contained within an array of `@container` also includes `@set`:

```ruby
{
"@context": {
"@vocab": "http://example.org/",
"input": {"@container": ["@graph", "@set"]}
}
}

```
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.

```ruby
{
"@context": {
"@vocab": "http://example.org/",
Expand All @@ -341,9 +341,9 @@ A graph map uses the map form already existing for `@index`, `@language`, `@type
"g1": {"value": "x"}
}
}

```
treats "g1" as an index, and expands to the following:

```ruby
[{
"http://example.org/input": [{
"@index": "g1",
Expand All @@ -352,11 +352,11 @@ treats "g1" as an index, and expands to the following:
}]
}]
}])

```
This can also include `@set` to ensure that, when compacting, a single value of an index will be in array form.

The _id_ version is similar:

```ruby
{
"@context": {
"@vocab": "http://example.org/",
Expand All @@ -366,9 +366,9 @@ The _id_ version is similar:
"http://example.com/g1": {"value": "x"}
}
}

```
which expands to:

```ruby
[{
"http://example.org/input": [{
"@id": "http://example.com/g1",
Expand All @@ -377,10 +377,10 @@ which expands to:
}]
}]
}])

```
### Transparent Nesting
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:

```json
{
"@context": {
"skos": "http://www.w3.org/2004/02/skos/core#",
Expand All @@ -396,9 +396,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
"other_label": "This is the other label"
}
}

```
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:

```json
{
"@context": {
"skos": "http://www.w3.org/2004/02/skos/core#",
Expand All @@ -412,9 +412,9 @@ Many JSON APIs separate properties from their entities using an intermediate obj
"main_label": "This is the main label for my resource",
"other_label": "This is the other label"
}

```
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.

```json
{
"@context": {
"skos": "http://www.w3.org/2004/02/skos/core#",
Expand All @@ -430,7 +430,7 @@ Many JSON APIs separate properties from their entities using an intermediate obj
"other_label": "This is the other label"
}
}

```
In this way, nesting survives round-tripping through expansion, and framed output can include nested properties.

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

## Dependencies
* [Ruby](http://ruby-lang.org/) (>= 2.2.2)
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.2)
* [JSON](https://rubygems.org/gems/json) (>= 1.5)
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
* [JSON](https://rubygems.org/gems/json) (>= 2.1)

## Installation
The recommended installation method is via [RubyGems](http://rubygems.org/).
To install the latest official release of the `JSON-LD` gem, do:

% [sudo] gem install json-ld

```bash
% [sudo] gem install json-ld
```
## Download
To get a local working copy of the development repository, do:

% git clone git://github.com/ruby-rdf/json-ld.git

```bash
% git clone git://github.com/ruby-rdf/json-ld.git
```
## Mailing List
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.1
3.0.0
18 changes: 18 additions & 0 deletions example-files/graph-container-framing-expanded.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"ex:claim": [
{
"@graph": [
{
"@id": "ex:1",
"https://example.com#test": [
{
"@value": "foo"
}
]
}
]
}
]
}
]
13 changes: 13 additions & 0 deletions example-files/graph-container-framing-frame.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@context": {
"@version": 1.1,
"@vocab": "https://example.com#",
"ex": "http://example.org/",
"claim": {
"@id": "ex:claim",
"@container": "@graph"
},
"id": "@id"
},
"claim": {}
}
22 changes: 22 additions & 0 deletions example-files/graph-container-framing-framed.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"@context": {
"@version": 1.1,
"@vocab": "https://example.com#",
"ex": "http://example.org/",
"claim": {
"@id": "ex:claim",
"@container": "@graph"
},
"id": "@id"
},
"@graph": [
{
"claim": {
"@graph": {
"id": "ex:1",
"test": "foo"
}
}
}
]
}

0 comments on commit 5f042eb

Please sign in to comment.