json-ld 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +107 -4
- data/VERSION +1 -1
- data/lib/json/ld.rb +38 -33
- data/lib/json/ld/api.rb +27 -14
- data/lib/json/ld/compact.rb +65 -10
- data/lib/json/ld/context.rb +158 -22
- data/lib/json/ld/expand.rb +339 -279
- data/lib/json/ld/frame.rb +30 -5
- data/lib/json/ld/from_rdf.rb +4 -3
- data/spec/compact_spec.rb +1107 -328
- data/spec/context_spec.rb +153 -27
- data/spec/expand_spec.rb +907 -152
- data/spec/format_spec.rb +1 -1
- data/spec/frame_spec.rb +90 -24
- data/spec/spec_helper.rb +0 -6
- data/spec/streaming_writer_spec.rb +2 -2
- data/spec/suite_helper.rb +2 -3
- data/spec/writer_spec.rb +2 -2
- metadata +7 -49
data/spec/format_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe JSON::LD::Format do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe ".cli_commands" do
|
70
|
+
describe ".cli_commands", skip: ("TextMate OptionParser issues" if ENV['TM_SELECTED_FILE']) do
|
71
71
|
require 'rdf/cli'
|
72
72
|
let(:ttl) {File.expand_path("../test-files/test-1-rdf.ttl", __FILE__)}
|
73
73
|
let(:json) {File.expand_path("../test-files/test-1-input.json", __FILE__)}
|
data/spec/frame_spec.rb
CHANGED
@@ -654,14 +654,11 @@ describe JSON::LD::API do
|
|
654
654
|
"result": {"@id": "mf:result", "@type": "xsd:boolean"}
|
655
655
|
},
|
656
656
|
"@graph": [{
|
657
|
-
"@id": "_:b0",
|
658
657
|
"@type": "mf:Manifest",
|
659
658
|
"comment": "Positive processor tests",
|
660
659
|
"entries": [{
|
661
|
-
"@id": "_:b1",
|
662
660
|
"@type": "mf:ManifestEntry",
|
663
661
|
"action": {
|
664
|
-
"@id": "_:b2",
|
665
662
|
"@type": "mq:QueryTest",
|
666
663
|
"data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
|
667
664
|
"query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
|
@@ -819,7 +816,7 @@ describe JSON::LD::API do
|
|
819
816
|
output = ::JSON.parse(output) if output.is_a?(String)
|
820
817
|
jld = JSON::LD::API.frame(input, frame, logger: logger)
|
821
818
|
expect(jld).to produce(output, logger)
|
822
|
-
rescue JSON::LD::JsonLdError
|
819
|
+
rescue JSON::LD::JsonLdError => e
|
823
820
|
fail("#{e.class}: #{e.message}\n" +
|
824
821
|
"#{logger}\n" +
|
825
822
|
"Backtrace:\n#{e.backtrace.join("\n")}")
|
@@ -1135,9 +1132,7 @@ describe JSON::LD::API do
|
|
1135
1132
|
"@graph": [{
|
1136
1133
|
"@id": "urn:id-1",
|
1137
1134
|
"@type": "Class",
|
1138
|
-
"preserve": {
|
1139
|
-
"@id": "_:b0"
|
1140
|
-
}
|
1135
|
+
"preserve": {}
|
1141
1136
|
}]
|
1142
1137
|
})
|
1143
1138
|
},
|
@@ -1260,9 +1255,7 @@ describe JSON::LD::API do
|
|
1260
1255
|
"term": "foo"
|
1261
1256
|
},
|
1262
1257
|
"preserve": {
|
1263
|
-
"@id": "_:b0",
|
1264
1258
|
"deep": {
|
1265
|
-
"@id": "_:b1",
|
1266
1259
|
"@graph": [{
|
1267
1260
|
"@id": "urn:id-3",
|
1268
1261
|
"term": "bar"
|
@@ -1338,23 +1331,96 @@ describe JSON::LD::API do
|
|
1338
1331
|
end
|
1339
1332
|
end
|
1340
1333
|
|
1334
|
+
describe "pruneBlankNodeIdentifiers" do
|
1335
|
+
it "preserves single-use bnode identifiers if option set to false" do
|
1336
|
+
do_frame(
|
1337
|
+
input: %({
|
1338
|
+
"@context": {
|
1339
|
+
"dc0": "http://purl.org/dc/terms/",
|
1340
|
+
"dc:creator": {
|
1341
|
+
"@type": "@id"
|
1342
|
+
},
|
1343
|
+
"foaf": "http://xmlns.com/foaf/0.1/",
|
1344
|
+
"ps": "http://purl.org/payswarm#"
|
1345
|
+
},
|
1346
|
+
"@id": "http://example.com/asset",
|
1347
|
+
"@type": "ps:Asset",
|
1348
|
+
"dc:creator": {
|
1349
|
+
"foaf:name": "John Doe"
|
1350
|
+
}
|
1351
|
+
}),
|
1352
|
+
frame: %({
|
1353
|
+
"@context": {
|
1354
|
+
"dc": "http://purl.org/dc/terms/",
|
1355
|
+
"dc:creator": {
|
1356
|
+
"@type": "@id"
|
1357
|
+
},
|
1358
|
+
"foaf": "http://xmlns.com/foaf/0.1/",
|
1359
|
+
"ps": "http://purl.org/payswarm#"
|
1360
|
+
},
|
1361
|
+
"@id": "http://example.com/asset",
|
1362
|
+
"@type": "ps:Asset",
|
1363
|
+
"dc:creator": {}
|
1364
|
+
}),
|
1365
|
+
output: %({
|
1366
|
+
"@context": {
|
1367
|
+
"dc": "http://purl.org/dc/terms/",
|
1368
|
+
"dc:creator": {
|
1369
|
+
"@type": "@id"
|
1370
|
+
},
|
1371
|
+
"foaf": "http://xmlns.com/foaf/0.1/",
|
1372
|
+
"ps": "http://purl.org/payswarm#"
|
1373
|
+
},
|
1374
|
+
"@graph": [
|
1375
|
+
{
|
1376
|
+
"@id": "http://example.com/asset",
|
1377
|
+
"@type": "ps:Asset",
|
1378
|
+
"dc:creator": {
|
1379
|
+
"@id": "_:b0",
|
1380
|
+
"foaf:name": "John Doe"
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
]
|
1384
|
+
}),
|
1385
|
+
prune: false
|
1386
|
+
)
|
1387
|
+
end
|
1388
|
+
end
|
1389
|
+
|
1341
1390
|
context "problem cases" do
|
1342
1391
|
it "pr #20" do
|
1343
|
-
expanded = [
|
1392
|
+
expanded = %([
|
1344
1393
|
{
|
1345
|
-
"@id"
|
1346
|
-
"@type"
|
1347
|
-
"http://xmlns.com/foaf/0.1/name"
|
1394
|
+
"@id": "_:gregg",
|
1395
|
+
"@type": "http://xmlns.com/foaf/0.1/Person",
|
1396
|
+
"http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
|
1348
1397
|
}, {
|
1349
|
-
"@id"
|
1350
|
-
"@type"
|
1351
|
-
"http://xmlns.com/foaf/0.1/knows"
|
1352
|
-
"http://xmlns.com/foaf/0.1/name"
|
1398
|
+
"@id": "http://manu.sporny.org/#me",
|
1399
|
+
"@type": "http://xmlns.com/foaf/0.1/Person",
|
1400
|
+
"http://xmlns.com/foaf/0.1/knows": {"@id": "_:gregg"},
|
1401
|
+
"http://xmlns.com/foaf/0.1/name": "Manu Sporny"
|
1353
1402
|
}
|
1354
|
-
]
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1403
|
+
])
|
1404
|
+
expected = %({
|
1405
|
+
"@graph": [
|
1406
|
+
{
|
1407
|
+
"@id": "_:b0",
|
1408
|
+
"@type": "http://xmlns.com/foaf/0.1/Person",
|
1409
|
+
"http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
|
1410
|
+
},
|
1411
|
+
{
|
1412
|
+
"@id": "http://manu.sporny.org/#me",
|
1413
|
+
"@type": "http://xmlns.com/foaf/0.1/Person",
|
1414
|
+
"http://xmlns.com/foaf/0.1/knows": {
|
1415
|
+
"@id": "_:b0",
|
1416
|
+
"@type": "http://xmlns.com/foaf/0.1/Person",
|
1417
|
+
"http://xmlns.com/foaf/0.1/name": "Gregg Kellogg"
|
1418
|
+
},
|
1419
|
+
"http://xmlns.com/foaf/0.1/name": "Manu Sporny"
|
1420
|
+
}
|
1421
|
+
]
|
1422
|
+
})
|
1423
|
+
do_frame(input: expanded, frame: {}, output: expected)
|
1358
1424
|
end
|
1359
1425
|
|
1360
1426
|
it "issue #28" do
|
@@ -1417,13 +1483,13 @@ describe JSON::LD::API do
|
|
1417
1483
|
|
1418
1484
|
def do_frame(params)
|
1419
1485
|
begin
|
1420
|
-
input, frame, output = params[:input], params[:frame], params[:output]
|
1486
|
+
input, frame, output, prune = params[:input], params[:frame], params[:output], params.fetch(:prune, true)
|
1421
1487
|
input = ::JSON.parse(input) if input.is_a?(String)
|
1422
1488
|
frame = ::JSON.parse(frame) if frame.is_a?(String)
|
1423
1489
|
output = ::JSON.parse(output) if output.is_a?(String)
|
1424
|
-
jld = JSON::LD::API.frame(input, frame, logger: logger)
|
1490
|
+
jld = JSON::LD::API.frame(input, frame, logger: logger, pruneBlankNodeIdentifiers: prune)
|
1425
1491
|
expect(jld).to produce(output, logger)
|
1426
|
-
rescue JSON::LD::JsonLdError
|
1492
|
+
rescue JSON::LD::JsonLdError => e
|
1427
1493
|
fail("#{e.class}: #{e.message}\n" +
|
1428
1494
|
"#{logger}\n" +
|
1429
1495
|
"Backtrace:\n#{e.backtrace.join("\n")}")
|
data/spec/spec_helper.rb
CHANGED
@@ -12,8 +12,6 @@ require 'rdf/vocab'
|
|
12
12
|
require 'rdf/spec'
|
13
13
|
require 'rdf/spec/matchers'
|
14
14
|
require 'yaml'
|
15
|
-
require 'restclient/components'
|
16
|
-
require 'rack/cache'
|
17
15
|
begin
|
18
16
|
require 'simplecov'
|
19
17
|
require 'coveralls'
|
@@ -41,10 +39,6 @@ JSON_STATE = JSON::State.new(
|
|
41
39
|
URI_CACHE = File.expand_path(File.join(File.dirname(__FILE__), "uri-cache"))
|
42
40
|
Dir.mkdir(URI_CACHE) unless File.directory?(URI_CACHE)
|
43
41
|
# Cache client requests
|
44
|
-
RestClient.enable Rack::Cache,
|
45
|
-
verbose: false,
|
46
|
-
metastore: "file:" + ::File.expand_path("../uri-cache/meta", __FILE__),
|
47
|
-
entitystore: "file:" + ::File.expand_path("../uri-cache/body", __FILE__)
|
48
42
|
|
49
43
|
::RSpec.configure do |c|
|
50
44
|
c.filter_run focus: true
|
@@ -99,7 +99,7 @@ describe JSON::LD::StreamingWriter do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
|
-
context "Writes fromRdf tests to isomorphic graph"
|
102
|
+
context "Writes fromRdf tests to isomorphic graph" do
|
103
103
|
require 'suite_helper'
|
104
104
|
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
|
105
105
|
[nil, {}].each do |ctx|
|
@@ -124,7 +124,7 @@ describe JSON::LD::StreamingWriter do
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
end
|
127
|
+
end unless ENV['CI']
|
128
128
|
|
129
129
|
def parse(input, options = {})
|
130
130
|
format = options.fetch(:format, :trig)
|
data/spec/suite_helper.rb
CHANGED
@@ -42,7 +42,7 @@ module Fixtures
|
|
42
42
|
def options
|
43
43
|
@options ||= begin
|
44
44
|
opts = {documentLoader: Fixtures::SuiteTest.method(:documentLoader)}
|
45
|
-
|
45
|
+
(property('option') || {}).each do |k, v|
|
46
46
|
opts[k.to_sym] = v
|
47
47
|
end
|
48
48
|
opts
|
@@ -94,6 +94,7 @@ module Fixtures
|
|
94
94
|
else
|
95
95
|
self.options.dup
|
96
96
|
end
|
97
|
+
options = {validate: true}.merge(options)
|
97
98
|
|
98
99
|
if positiveTest?
|
99
100
|
logger.info "expected: #{expect rescue nil}" if expect_loc
|
@@ -142,8 +143,6 @@ module Fixtures
|
|
142
143
|
end
|
143
144
|
rescue JSON::LD::JsonLdError => e
|
144
145
|
fail("Processing error: #{e.message}")
|
145
|
-
rescue JSON::LD::InvalidFrame => e
|
146
|
-
fail("Invalid Frame: #{e.message}")
|
147
146
|
end
|
148
147
|
else
|
149
148
|
logger.info "expected: #{property('expect')}" if property('expect')
|
data/spec/writer_spec.rb
CHANGED
@@ -190,7 +190,7 @@ describe JSON::LD::Writer do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
-
context "Writes fromRdf tests to isomorphic graph"
|
193
|
+
context "Writes fromRdf tests to isomorphic graph" do
|
194
194
|
require 'suite_helper'
|
195
195
|
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
|
196
196
|
describe m.name do
|
@@ -212,7 +212,7 @@ describe JSON::LD::Writer do
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
215
|
-
end
|
215
|
+
end unless ENV['CI']
|
216
216
|
|
217
217
|
def parse(input, options = {})
|
218
218
|
format = options.fetch(:format, :trig)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-ld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,48 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.2'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rack-cache
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.2'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.2'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rest-client
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.8'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '1.8'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rest-client-components
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '1.4'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '1.4'
|
139
97
|
- !ruby/object:Gem::Dependency
|
140
98
|
name: rdf-isomorphic
|
141
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +114,14 @@ dependencies:
|
|
156
114
|
requirements:
|
157
115
|
- - "~>"
|
158
116
|
- !ruby/object:Gem::Version
|
159
|
-
version: '2.
|
117
|
+
version: '2.2'
|
160
118
|
type: :development
|
161
119
|
prerelease: false
|
162
120
|
version_requirements: !ruby/object:Gem::Requirement
|
163
121
|
requirements:
|
164
122
|
- - "~>"
|
165
123
|
- !ruby/object:Gem::Version
|
166
|
-
version: '2.
|
124
|
+
version: '2.2'
|
167
125
|
- !ruby/object:Gem::Dependency
|
168
126
|
name: rdf-trig
|
169
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -385,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
385
343
|
version: '0'
|
386
344
|
requirements: []
|
387
345
|
rubyforge_project: json-ld
|
388
|
-
rubygems_version: 2.6.
|
346
|
+
rubygems_version: 2.6.11
|
389
347
|
signing_key:
|
390
348
|
specification_version: 4
|
391
349
|
summary: JSON-LD reader/writer for Ruby.
|