json-ld 1.99.2 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/json/ld.rb +0 -3
- data/lib/json/ld/api.rb +38 -21
- data/lib/json/ld/compact.rb +24 -24
- data/lib/json/ld/context.rb +80 -79
- data/lib/json/ld/expand.rb +30 -30
- data/lib/json/ld/flatten.rb +2 -2
- data/lib/json/ld/format.rb +126 -1
- data/lib/json/ld/frame.rb +3 -3
- data/lib/json/ld/from_rdf.rb +3 -3
- data/lib/json/ld/reader.rb +15 -5
- data/lib/json/ld/streaming_writer.rb +6 -6
- data/lib/json/ld/to_rdf.rb +75 -85
- data/lib/json/ld/utils.rb +1 -30
- data/lib/json/ld/writer.rb +86 -51
- data/spec/api_spec.rb +8 -8
- data/spec/compact_spec.rb +19 -19
- data/spec/context_spec.rb +76 -96
- data/spec/expand_spec.rb +30 -30
- data/spec/flatten_spec.rb +3 -4
- data/spec/format_spec.rb +43 -0
- data/spec/frame_spec.rb +7 -9
- data/spec/from_rdf_spec.rb +25 -24
- data/spec/reader_spec.rb +4 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/streaming_writer_spec.rb +18 -11
- data/spec/suite_helper.rb +29 -28
- data/spec/suite_to_rdf_spec.rb +0 -2
- data/spec/to_rdf_spec.rb +17 -18
- data/spec/writer_spec.rb +15 -11
- metadata +75 -35
- data/spec/matchers.rb +0 -67
data/spec/reader_spec.rb
CHANGED
@@ -7,6 +7,9 @@ describe JSON::LD::Reader do
|
|
7
7
|
let!(:doap) {File.expand_path("../../etc/doap.jsonld", __FILE__)}
|
8
8
|
let!(:doap_nt) {File.expand_path("../../etc/doap.nt", __FILE__)}
|
9
9
|
let!(:doap_count) {File.open(doap_nt).each_line.to_a.length}
|
10
|
+
let(:logger) {RDF::Spec.logger}
|
11
|
+
|
12
|
+
after(:each) {|example| puts logger.to_s if example.exception}
|
10
13
|
|
11
14
|
it_behaves_like 'an RDF::Reader' do
|
12
15
|
let(:reader_input) {File.read(doap)}
|
@@ -32,7 +35,7 @@ describe JSON::LD::Reader do
|
|
32
35
|
context "when validating", pending: ("JRuby support for jsonlint" if RUBY_ENGINE == "jruby") do
|
33
36
|
it "detects invalid JSON" do
|
34
37
|
expect do |b|
|
35
|
-
described_class.new(StringIO.new(%({"a": "b", "a": "c"})), validate: true).each_statement(&b)
|
38
|
+
described_class.new(StringIO.new(%({"a": "b", "a": "c"})), validate: true, logger: false).each_statement(&b)
|
36
39
|
end.to raise_error(RDF::ReaderError)
|
37
40
|
end
|
38
41
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,10 @@ require 'rdf/spec/writer'
|
|
5
5
|
require 'json/ld/streaming_writer'
|
6
6
|
|
7
7
|
describe JSON::LD::StreamingWriter do
|
8
|
+
let(:logger) {RDF::Spec.logger}
|
9
|
+
|
10
|
+
after(:each) {|example| puts logger.to_s if example.exception}
|
11
|
+
|
8
12
|
it_behaves_like 'an RDF::Writer' do
|
9
13
|
let(:writer) {JSON::LD::Writer.new(StringIO.new(""), stream: true)}
|
10
14
|
end
|
@@ -13,11 +17,11 @@ describe JSON::LD::StreamingWriter do
|
|
13
17
|
it "should use full URIs without base" do
|
14
18
|
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
15
19
|
obj = serialize(input)
|
16
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse
|
20
|
+
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
17
21
|
expect(obj).to produce([{
|
18
22
|
'@id' => "http://a/b",
|
19
23
|
"http://a/c" => [{"@id" => "http://a/d"}]
|
20
|
-
}],
|
24
|
+
}], logger)
|
21
25
|
end
|
22
26
|
|
23
27
|
it "writes multiple kinds of statements" do
|
@@ -28,7 +32,7 @@ describe JSON::LD::StreamingWriter do
|
|
28
32
|
<https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
|
29
33
|
)
|
30
34
|
obj = serialize(input)
|
31
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse
|
35
|
+
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
32
36
|
expect(obj).to eql JSON.parse(%{[{
|
33
37
|
"@id": "https://senet.org/gm",
|
34
38
|
"@type": ["http://vocab.org/frbr/core#Work"],
|
@@ -46,8 +50,8 @@ describe JSON::LD::StreamingWriter do
|
|
46
50
|
<http://example.com/test-cases/0002> a :TestCase .
|
47
51
|
)
|
48
52
|
obj = serialize(input)
|
49
|
-
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse
|
50
|
-
expect(obj).to
|
53
|
+
expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
|
54
|
+
expect(obj).to contain_exactly *JSON.parse(%{[
|
51
55
|
{"@id": "http://example.com/test-cases/0001", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]},
|
52
56
|
{"@id": "http://example.com/test-cases/0002", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]}
|
53
57
|
]})
|
@@ -88,7 +92,7 @@ describe JSON::LD::StreamingWriter do
|
|
88
92
|
context title do
|
89
93
|
subject {serialize(input)}
|
90
94
|
it "matches expected json" do
|
91
|
-
expect(subject).to
|
95
|
+
expect(subject).to contain_exactly *JSON.parse(matches)
|
92
96
|
end
|
93
97
|
end
|
94
98
|
end
|
@@ -103,13 +107,15 @@ describe JSON::LD::StreamingWriter do
|
|
103
107
|
describe m.name do
|
104
108
|
m.entries.each do |t|
|
105
109
|
next unless t.positiveTest? && !t.property('input').include?('0016')
|
106
|
-
t.
|
110
|
+
t.logger = RDF::Spec.logger
|
111
|
+
t.logger.info "test: #{t.inspect}"
|
112
|
+
t.logger.info "source: #{t.input}"
|
107
113
|
specify "#{t.property('input')}: #{t.name}" do
|
108
114
|
repo = RDF::Repository.load(t.input_loc, format: :nquads)
|
109
|
-
jsonld = JSON::LD::Writer.buffer(stream: true, context: ctx,
|
115
|
+
jsonld = JSON::LD::Writer.buffer(stream: true, context: ctx, logger: t.logger) do |writer|
|
110
116
|
writer << repo
|
111
117
|
end
|
112
|
-
t.
|
118
|
+
t.logger.info "Generated: #{jsonld}"
|
113
119
|
|
114
120
|
# And then, re-generate jsonld as RDF
|
115
121
|
expect(parse(jsonld, format: :jsonld)).to be_equivalent_graph(repo, t)
|
@@ -129,8 +135,9 @@ describe JSON::LD::StreamingWriter do
|
|
129
135
|
# Serialize ntstr to a string and compare against regexps
|
130
136
|
def serialize(ntstr, options = {})
|
131
137
|
g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
|
132
|
-
|
133
|
-
|
138
|
+
logger = RDF::Spec.logger
|
139
|
+
logger.info(g.dump(:ttl))
|
140
|
+
result = JSON::LD::Writer.buffer(options.merge(logger: logger, stream: true)) do |writer|
|
134
141
|
writer << g
|
135
142
|
end
|
136
143
|
puts result if $verbose
|
data/spec/suite_helper.rb
CHANGED
@@ -32,7 +32,7 @@ module Fixtures
|
|
32
32
|
end
|
33
33
|
|
34
34
|
class Entry < JSON::LD::Resource
|
35
|
-
attr_accessor :
|
35
|
+
attr_accessor :logger
|
36
36
|
|
37
37
|
# Base is expanded input file
|
38
38
|
def base
|
@@ -79,14 +79,15 @@ module Fixtures
|
|
79
79
|
property('@type').include?('jld:PositiveEvaluationTest')
|
80
80
|
end
|
81
81
|
|
82
|
-
def trace; @debug.join("\n"); end
|
83
82
|
|
84
83
|
# Execute the test
|
85
84
|
def run(rspec_example = nil)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
logger = @logger = RDF::Spec.logger
|
86
|
+
logger.info "test: #{inspect}"
|
87
|
+
logger.info "source: #{input}"
|
88
|
+
logger.info "context: #{context}" if context_loc
|
89
|
+
logger.info "options: #{options.inspect}" unless options.empty?
|
90
|
+
logger.info "frame: #{frame}" if frame_loc
|
90
91
|
|
91
92
|
options = if self.options[:useDocumentLoader]
|
92
93
|
self.options.merge(documentLoader: Fixtures::SuiteTest.method(:documentLoader))
|
@@ -95,43 +96,41 @@ module Fixtures
|
|
95
96
|
end
|
96
97
|
|
97
98
|
if positiveTest?
|
98
|
-
|
99
|
+
logger.info "expected: #{expect rescue nil}" if expect_loc
|
99
100
|
begin
|
100
101
|
result = case testType
|
101
102
|
when "jld:ExpandTest"
|
102
|
-
JSON::LD::API.expand(input_loc, options.merge(
|
103
|
+
JSON::LD::API.expand(input_loc, options.merge(logger: logger))
|
103
104
|
when "jld:CompactTest"
|
104
|
-
JSON::LD::API.compact(input_loc, context_json['@context'], options.merge(
|
105
|
+
JSON::LD::API.compact(input_loc, context_json['@context'], options.merge(logger: logger))
|
105
106
|
when "jld:FlattenTest"
|
106
|
-
JSON::LD::API.flatten(input_loc, context_loc, options.merge(
|
107
|
+
JSON::LD::API.flatten(input_loc, context_loc, options.merge(logger: logger))
|
107
108
|
when "jld:FrameTest"
|
108
|
-
JSON::LD::API.frame(input_loc, frame_loc, options.merge(
|
109
|
+
JSON::LD::API.frame(input_loc, frame_loc, options.merge(logger: logger))
|
109
110
|
when "jld:FromRDFTest"
|
110
111
|
# Use an array, to preserve input order
|
111
112
|
repo = RDF::NQuads::Reader.open(input_loc) do |reader|
|
112
113
|
reader.each_statement.to_a
|
113
114
|
end.extend(RDF::Enumerable)
|
114
|
-
|
115
|
-
JSON::LD::API.fromRdf(repo, options.merge(
|
115
|
+
logger.info "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
|
116
|
+
JSON::LD::API.fromRdf(repo, options.merge(logger: logger))
|
116
117
|
when "jld:ToRDFTest"
|
117
|
-
|
118
|
-
|
119
|
-
repo << statement
|
118
|
+
JSON::LD::API.toRdf(input_loc, options.merge(logger: logger)).map do |statement|
|
119
|
+
to_quad(statement)
|
120
120
|
end
|
121
|
-
repo
|
122
121
|
else
|
123
122
|
fail("Unknown test type: #{testType}")
|
124
123
|
end
|
125
124
|
if evaluationTest?
|
126
125
|
if testType == "jld:ToRDFTest"
|
127
|
-
expected =
|
126
|
+
expected = expect
|
128
127
|
rspec_example.instance_eval {
|
129
|
-
expect(result).to
|
128
|
+
expect(result.sort.join("")).to produce(expected, logger)
|
130
129
|
}
|
131
130
|
else
|
132
131
|
expected = JSON.load(expect)
|
133
132
|
rspec_example.instance_eval {
|
134
|
-
expect(result).to produce(expected,
|
133
|
+
expect(result).to produce(expected, logger)
|
135
134
|
}
|
136
135
|
end
|
137
136
|
else
|
@@ -145,26 +144,28 @@ module Fixtures
|
|
145
144
|
fail("Invalid Frame: #{e.message}")
|
146
145
|
end
|
147
146
|
else
|
148
|
-
|
147
|
+
logger.info "expected: #{property('expect')}" if property('expect')
|
149
148
|
t = self
|
150
149
|
rspec_example.instance_eval do
|
151
150
|
if t.evaluationTest?
|
152
151
|
expect do
|
153
152
|
case t.testType
|
154
153
|
when "jld:ExpandTest"
|
155
|
-
JSON::LD::API.expand(t.input_loc, options.merge(
|
154
|
+
JSON::LD::API.expand(t.input_loc, options.merge(logger: logger))
|
156
155
|
when "jld:CompactTest"
|
157
|
-
JSON::LD::API.compact(t.input_loc, t.context_json['@context'], options.merge(
|
156
|
+
JSON::LD::API.compact(t.input_loc, t.context_json['@context'], options.merge(logger: logger))
|
158
157
|
when "jld:FlattenTest"
|
159
|
-
JSON::LD::API.flatten(t.input_loc, t.context_loc, options.merge(
|
158
|
+
JSON::LD::API.flatten(t.input_loc, t.context_loc, options.merge(logger: logger))
|
160
159
|
when "jld:FrameTest"
|
161
|
-
JSON::LD::API.frame(t.input_loc, t.frame_loc, options.merge(
|
160
|
+
JSON::LD::API.frame(t.input_loc, t.frame_loc, options.merge(logger: logger))
|
162
161
|
when "jld:FromRDFTest"
|
163
162
|
repo = RDF::Repository.load(t.input_loc)
|
164
|
-
|
165
|
-
JSON::LD::API.fromRdf(repo, options.merge(
|
163
|
+
logger.info "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
|
164
|
+
JSON::LD::API.fromRdf(repo, options.merge(logger: logger))
|
166
165
|
when "jld:ToRDFTest"
|
167
|
-
JSON::LD::API.toRdf(t.input_loc, options.merge(
|
166
|
+
JSON::LD::API.toRdf(t.input_loc, options.merge(logger: logger)).map do |statement|
|
167
|
+
t.to_quad(statement)
|
168
|
+
end
|
168
169
|
else
|
169
170
|
success("Unknown test type: #{testType}")
|
170
171
|
end
|
data/spec/suite_to_rdf_spec.rb
CHANGED
@@ -9,8 +9,6 @@ describe JSON::LD do
|
|
9
9
|
describe m.name do
|
10
10
|
m.entries.each do |t|
|
11
11
|
specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
|
12
|
-
skip "Native value fidelity" if %w(toRdf-0035-in.jsonld).include?(t.property('input'))
|
13
|
-
pending "Generalized RDF" if %w(toRdf-0118-in.jsonld).include?(t.property('input'))
|
14
12
|
t.run self
|
15
13
|
end
|
16
14
|
end
|
data/spec/to_rdf_spec.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift "."
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe JSON::LD::API do
|
6
|
-
|
6
|
+
let(:logger) {RDF::Spec.logger}
|
7
7
|
|
8
8
|
context ".toRdf" do
|
9
9
|
it "should implement RDF::Enumerable" do
|
@@ -35,7 +35,7 @@ describe JSON::LD::API do
|
|
35
35
|
}.each do |title, (js, ttl)|
|
36
36
|
it title do
|
37
37
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
38
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
38
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -52,7 +52,7 @@ describe JSON::LD::API do
|
|
52
52
|
}.each do |title, (js, ttl)|
|
53
53
|
it title do
|
54
54
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
55
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
55
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -82,7 +82,7 @@ describe JSON::LD::API do
|
|
82
82
|
}.each do |title, (js, ttl)|
|
83
83
|
it title do
|
84
84
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
85
|
-
expect(parse(js, base: "http://example.org/")).to be_equivalent_graph(ttl,
|
85
|
+
expect(parse(js, base: "http://example.org/")).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -111,7 +111,7 @@ describe JSON::LD::API do
|
|
111
111
|
}.each do |title, (js, ttl)|
|
112
112
|
it title do
|
113
113
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
114
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
114
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
@@ -145,7 +145,7 @@ describe JSON::LD::API do
|
|
145
145
|
}.each do |title, (js, ttl)|
|
146
146
|
it title do
|
147
147
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
148
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
148
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -194,7 +194,7 @@ describe JSON::LD::API do
|
|
194
194
|
}.each do |title, (js, ttl)|
|
195
195
|
it title do
|
196
196
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
197
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
197
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
198
198
|
end
|
199
199
|
end
|
200
200
|
end
|
@@ -216,7 +216,7 @@ describe JSON::LD::API do
|
|
216
216
|
}.each_pair do |title, (js, ttl)|
|
217
217
|
it title do
|
218
218
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
219
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
219
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
end
|
@@ -238,7 +238,7 @@ describe JSON::LD::API do
|
|
238
238
|
}.each do |title, (js, ttl)|
|
239
239
|
it title do
|
240
240
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
241
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
241
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
242
242
|
end
|
243
243
|
end
|
244
244
|
end
|
@@ -277,7 +277,7 @@ describe JSON::LD::API do
|
|
277
277
|
}.each do |title, (js, ttl)|
|
278
278
|
it title do
|
279
279
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
280
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
280
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
281
281
|
end
|
282
282
|
end
|
283
283
|
end
|
@@ -299,7 +299,7 @@ describe JSON::LD::API do
|
|
299
299
|
}.each do |title, (js, ttl)|
|
300
300
|
it title do
|
301
301
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
302
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
302
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
303
303
|
end
|
304
304
|
end
|
305
305
|
end
|
@@ -360,7 +360,7 @@ describe JSON::LD::API do
|
|
360
360
|
}.each do |title, (js, ttl)|
|
361
361
|
it title do
|
362
362
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
363
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
363
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
364
364
|
end
|
365
365
|
end
|
366
366
|
end
|
@@ -483,7 +483,7 @@ describe JSON::LD::API do
|
|
483
483
|
}.each do |title, (js, ttl)|
|
484
484
|
it title do
|
485
485
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
486
|
-
expect(parse(js)).to be_equivalent_graph(ttl, base: "http://example/",
|
486
|
+
expect(parse(js)).to be_equivalent_graph(ttl, base: "http://example/", logger: logger, inputDocument: js)
|
487
487
|
end
|
488
488
|
end
|
489
489
|
|
@@ -536,7 +536,7 @@ describe JSON::LD::API do
|
|
536
536
|
}.each do |title, (js, ttl)|
|
537
537
|
it title do
|
538
538
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
539
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
539
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
540
540
|
end
|
541
541
|
end
|
542
542
|
end
|
@@ -572,7 +572,7 @@ describe JSON::LD::API do
|
|
572
572
|
}.each do |title, (js, ttl)|
|
573
573
|
it title do
|
574
574
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
575
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
575
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
576
576
|
end
|
577
577
|
end
|
578
578
|
end
|
@@ -654,16 +654,15 @@ describe JSON::LD::API do
|
|
654
654
|
}.each do |title, (js, ttl)|
|
655
655
|
it title do
|
656
656
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
657
|
-
expect(parse(js)).to be_equivalent_graph(ttl,
|
657
|
+
expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
|
658
658
|
end
|
659
659
|
end
|
660
660
|
end
|
661
661
|
end
|
662
662
|
|
663
663
|
def parse(input, options = {})
|
664
|
-
@debug = []
|
665
664
|
graph = options[:graph] || RDF::Graph.new
|
666
|
-
options = {
|
665
|
+
options = {logger: logger, validate: true, canonicalize: false}.merge(options)
|
667
666
|
JSON::LD::API.toRdf(StringIO.new(input), options) {|st| graph << st}
|
668
667
|
graph
|
669
668
|
end
|
data/spec/writer_spec.rb
CHANGED
@@ -4,6 +4,10 @@ require 'spec_helper'
|
|
4
4
|
require 'rdf/spec/writer'
|
5
5
|
|
6
6
|
describe JSON::LD::Writer do
|
7
|
+
let(:logger) {RDF::Spec.logger}
|
8
|
+
|
9
|
+
after(:each) {|example| puts logger.to_s if example.exception}
|
10
|
+
|
7
11
|
it_behaves_like 'an RDF::Writer' do
|
8
12
|
let(:writer) {JSON::LD::Writer.new(StringIO.new(""))}
|
9
13
|
end
|
@@ -29,7 +33,7 @@ describe JSON::LD::Writer do
|
|
29
33
|
expect(serialize(input)).to produce([{
|
30
34
|
'@id' => "http://a/b",
|
31
35
|
"http://a/c" => [{"@id" => "http://a/d"}]
|
32
|
-
}],
|
36
|
+
}], logger)
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should use qname URIs with standard prefix" do
|
@@ -40,7 +44,7 @@ describe JSON::LD::Writer do
|
|
40
44
|
},
|
41
45
|
'@id' => "foaf:b",
|
42
46
|
"foaf:c" => {"@id" => "foaf:d"}
|
43
|
-
},
|
47
|
+
}, logger)
|
44
48
|
end
|
45
49
|
|
46
50
|
it "should use qname URIs with parsed prefix" do
|
@@ -65,7 +69,7 @@ describe JSON::LD::Writer do
|
|
65
69
|
"dc:title" => {"@value" => "Rhythm Paradise","@language" => "en"},
|
66
70
|
"senet:unofficialTitle" => {"@value" => "Rhythm Tengoku","@language" => "en"},
|
67
71
|
"senet:urlkey" => "rhythm-tengoku"
|
68
|
-
},
|
72
|
+
}, logger)
|
69
73
|
end
|
70
74
|
|
71
75
|
it "should use CURIEs with empty prefix" do
|
@@ -78,10 +82,10 @@ describe JSON::LD::Writer do
|
|
78
82
|
},
|
79
83
|
'@id' => ":b",
|
80
84
|
":c" => {"@id" => ":d"}
|
81
|
-
},
|
85
|
+
}, logger)
|
82
86
|
rescue JSON::LD::JsonLdError, JSON::LD::JsonLdError, TypeError => e
|
83
87
|
fail("#{e.class}: #{e.message}\n" +
|
84
|
-
"#{
|
88
|
+
"#{logger}\n" +
|
85
89
|
"Backtrace:\n#{e.backtrace.join("\n")}")
|
86
90
|
end
|
87
91
|
end
|
@@ -93,7 +97,7 @@ describe JSON::LD::Writer do
|
|
93
97
|
"@context" => {"foaf" => "http://xmlns.com/foaf/0.1/"},
|
94
98
|
'@id' => "foaf",
|
95
99
|
"foaf" => {"@id" => "foaf"}
|
96
|
-
},
|
100
|
+
}, logger)
|
97
101
|
end
|
98
102
|
|
99
103
|
it "should not use CURIE with illegal local part" do
|
@@ -113,7 +117,7 @@ describe JSON::LD::Writer do
|
|
113
117
|
},
|
114
118
|
'@id' => "db:Michael_Jackson",
|
115
119
|
"dbo:artistOf" => {"@id" => "db:%28I_Can%27t_Make_It%29_Another_Day"}
|
116
|
-
},
|
120
|
+
}, logger)
|
117
121
|
end
|
118
122
|
|
119
123
|
it "should not use provided node identifiers if :unique_bnodes set" do
|
@@ -139,7 +143,7 @@ describe JSON::LD::Writer do
|
|
139
143
|
{'@id' => "http://example.com/test-cases/0001", '@type' => ":TestCase"},
|
140
144
|
{'@id' => "http://example.com/test-cases/0002", '@type' => ":TestCase"}
|
141
145
|
]
|
142
|
-
},
|
146
|
+
}, logger)
|
143
147
|
end
|
144
148
|
|
145
149
|
it "serializes Wikia OWL example" do
|
@@ -182,7 +186,7 @@ describe JSON::LD::Writer do
|
|
182
186
|
"rdfs:subClassOf" => {"@id" => "_:a"}
|
183
187
|
}
|
184
188
|
]
|
185
|
-
},
|
189
|
+
}, logger)
|
186
190
|
end
|
187
191
|
end
|
188
192
|
|
@@ -217,8 +221,8 @@ describe JSON::LD::Writer do
|
|
217
221
|
# Serialize ntstr to a string and compare against regexps
|
218
222
|
def serialize(ntstr, options = {})
|
219
223
|
g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
|
220
|
-
|
221
|
-
result = JSON::LD::Writer.buffer(options.merge(
|
224
|
+
logger.info g.dump(:ttl)
|
225
|
+
result = JSON::LD::Writer.buffer(options.merge(logger: logger)) do |writer|
|
222
226
|
writer << g
|
223
227
|
end
|
224
228
|
if $verbose
|