Skip to content

Commit 9d64e12

Browse files
committed
Example for issue 30, and some improvements for the CLI.
1 parent 703b810 commit 9d64e12

File tree

6 files changed

+116
-3
lines changed

6 files changed

+116
-3
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ group :development do
88
gem 'ebnf', github: "gkellogg/ebnf", branch: "develop"
99
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"
1010
gem 'rdf-isomorphic', github: "ruby-rdf/rdf-isomorphic", branch: "develop"
11-
gem 'rdf-turtle', github: "ruby-rdf/rdf-turtle", branch: "develop"
1211
gem 'rdf-trig', github: "ruby-rdf/rdf-trig", branch: "develop"
1312
gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
1413
gem 'rdf-xsd', github: "ruby-rdf/rdf-xsd", branch: "develop"

example-files/issue_30.jsonld

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"@id": "http://vocab.getty.edu/ulan/500115403",
4+
"http://xmlns.com/foaf/0.1/focus": [
5+
{
6+
"@id": "http://vocab.getty.edu/ulan/500115403-agent"
7+
}
8+
],
9+
"http://www.w3.org/2004/02/skos/core#prefLabel": [
10+
{
11+
"@value": "Couture, Thomas"
12+
}
13+
],
14+
"http://www.w3.org/2004/02/skos/core#inScheme": [
15+
{
16+
"@id": "http://vocab.getty.edu/ulan/"
17+
}
18+
],
19+
"http://schema.org/url": [
20+
{
21+
"@id": "http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=500115403"
22+
}
23+
]
24+
}
25+
]

example-files/issue_30.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! /usr/bin/env ruby
2+
3+
require 'linkeddata'
4+
5+
unframed_json = JSON.parse '[
6+
{
7+
"@id": "http://vocab.getty.edu/ulan/500115403",
8+
"http://xmlns.com/foaf/0.1/focus": [
9+
{
10+
"@id": "http://vocab.getty.edu/ulan/500115403-agent"
11+
}
12+
],
13+
"http://www.w3.org/2004/02/skos/core#prefLabel": [
14+
{
15+
"@value": "Couture, Thomas"
16+
}
17+
],
18+
"http://www.w3.org/2004/02/skos/core#inScheme": [
19+
{
20+
"@id": "http://vocab.getty.edu/ulan/"
21+
}
22+
],
23+
"http://schema.org/url": [
24+
{
25+
"@id": "http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=500115403"
26+
}
27+
]
28+
}
29+
]'
30+
31+
frame = JSON.parse '{
32+
"@explicit": true,
33+
"@context": {
34+
"skos": "http://www.w3.org/2004/02/skos/core#",
35+
"foaf": "http://xmlns.com/foaf/0.1/",
36+
"schema": "http://schema.org/",
37+
"label": "skos:prefLabel",
38+
"id": "@id",
39+
"source": {
40+
"@id": "skos:inScheme",
41+
"@type": "@id"
42+
},
43+
"agent": {
44+
"@id": "foaf:focus",
45+
"@type": "@id"
46+
},
47+
"website": {
48+
"@id": "schema:url",
49+
"@type": "@id"
50+
}
51+
},
52+
"@requireAll": false,
53+
"@explicit": false,
54+
"label": {},
55+
"id": {},
56+
"source": {},
57+
"agent": {},
58+
"website": {}
59+
}'
60+
61+
puts JSON::LD::API.frame(unframed_json, frame, logger: STDERR).to_json(JSON::LD::JSON_STATE)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"@explicit": true,
3+
"@context": {
4+
"skos": "http://www.w3.org/2004/02/skos/core#",
5+
"foaf": "http://xmlns.com/foaf/0.1/",
6+
"schema": "http://schema.org/",
7+
"label": "skos:prefLabel",
8+
"id": "@id",
9+
"source": {
10+
"@id": "skos:inScheme",
11+
"@type": "@id"
12+
},
13+
"agent": {
14+
"@id": "foaf:focus",
15+
"@type": "@id"
16+
},
17+
"website": {
18+
"@id": "schema:url",
19+
"@type": "@id"
20+
}
21+
},
22+
"label": {},
23+
"id": {},
24+
"source": {},
25+
"agent": {},
26+
"website": {}
27+
}

json-ld.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Gem::Specification.new do |gem|
2929
gem.requirements = []
3030
gem.add_runtime_dependency 'rdf', '~> 2.1'
3131
gem.add_runtime_dependency 'multi_json', '~> 1.12'
32+
gem.add_development_dependency 'linkeddata', '~> 2.0'
3233
gem.add_development_dependency 'jsonlint', '~> 0.2' unless RUBY_ENGINE == "jruby"
3334
gem.add_development_dependency 'oj', '~> 2.17' unless RUBY_ENGINE == "jruby"
3435
gem.add_development_dependency 'yajl-ruby', '~> 1.2' unless RUBY_ENGINE == "jruby"

lib/json/ld/format.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def self.cli_commands
152152
end
153153
},
154154
frame: {
155-
description: "Flatten JSON-LD or parsed RDF",
155+
description: "Frame JSON-LD or parsed RDF",
156156
parse: false,
157-
help: "flatten --frame <frame-file> files ...",
157+
help: "frame --frame <frame-file> files ...",
158158
lambda: ->(files, options) do
159159
raise ArgumentError, "Framing requires a frame" unless options[:frame]
160160
out = options[:output] || $stdout

0 commit comments

Comments
 (0)