Skip to content

Commit b3c7ab9

Browse files
committed
Release 1.99.0:
* Use `graph_name` instead of `context` from RDF.rb. * Don't resolve @base if it is an absolute IRI.
2 parents 5cd5170 + e4ea2bb commit b3c7ab9

15 files changed

+86
-62
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gem 'jsonlint', git: "git://github.com/dougbarth/jsonlint.git", platform
88
group :development do
99
gem 'rdf-turtle', git: "git://github.com/ruby-rdf/rdf-turtle.git", branch: "develop"
1010
gem 'rdf-trig', git: "git://github.com/ruby-rdf/rdf-trig.git", branch: "develop"
11+
gem 'rdf-vocab', git: "git://github.com/ruby-rdf/rdf-vocab.git", branch: "develop"
1112
gem 'fasterer'
1213
end
1314

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.11
1+
1.99.0

json-ld.gemspec

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@ Gem::Specification.new do |gem|
2727

2828
gem.required_ruby_version = '>= 1.9.2'
2929
gem.requirements = []
30-
gem.add_runtime_dependency 'rdf', '~> 1.1', '>= 1.1.7'
30+
gem.add_runtime_dependency 'rdf', '~> 1.99'
3131
gem.add_runtime_dependency 'multi_json', '~> 1.11'
3232
gem.add_development_dependency 'jsonlint', '~> 0.1.0' unless RUBY_ENGINE == "jruby"
3333
gem.add_development_dependency 'oj', '~> 2.12' unless RUBY_ENGINE == "jruby"
34-
gem.add_development_dependency 'yajl-ruby', '~> 1.2.1' unless RUBY_ENGINE == "jruby"
34+
gem.add_development_dependency 'yajl-ruby', '~> 1.2' unless RUBY_ENGINE == "jruby"
3535
gem.add_development_dependency "rack-cache", '~> 1.2'
3636
gem.add_development_dependency "rest-client", '~> 1.8'
3737
gem.add_development_dependency "rest-client-components", '~> 1.4'
3838
gem.add_development_dependency 'rdf-isomorphic', '~> 1.1'
39-
gem.add_development_dependency 'rdf-spec', '~> 1.1'
40-
gem.add_development_dependency 'rdf-trig', '~> 1.1'
41-
gem.add_development_dependency 'rdf-turtle', '~> 1.1'
39+
gem.add_development_dependency 'rdf-spec', '~> 1.99'
40+
gem.add_development_dependency 'rdf-trig', '~> 1.99'
41+
gem.add_development_dependency 'rdf-turtle', '~> 1.99'
42+
gem.add_development_dependency 'rdf-vocab', '~> 0.8'
4243
gem.add_development_dependency 'rdf-xsd', '~> 1.1'
43-
gem.add_development_dependency 'rspec', '~> 3.2.0'
44+
gem.add_development_dependency 'rspec', '~> 3.2'
4445
gem.add_development_dependency 'rspec-its', '~> 1.0'
4546
gem.add_development_dependency 'yard' , '~> 0.8'
4647

lib/json/ld/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def self.toRdf(input, options = {}, &block)
421421
# Start generating statements
422422
graphs.each do |graph_name, graph|
423423
context = as_resource(graph_name) unless graph_name == '@default'
424-
debug(".toRdf") {"context: #{context ? context.to_ntriples : 'null'}"}
424+
debug(".toRdf") {"graph_name: #{context ? context.to_ntriples : 'null'}"}
425425
# Drop results for graphs which are named with relative IRIs
426426
if graph_name.is_a?(RDF::URI) && !graph_name.absolute
427427
debug(".toRdf") {"drop relative graph_name: #{statement.to_ntriples}"}
@@ -445,7 +445,7 @@ def self.toRdf(input, options = {}, &block)
445445
next
446446
end
447447

448-
statement.context = context if context
448+
statement.graph_name = context if context
449449
if block_given?
450450
yield statement
451451
else

lib/json/ld/context.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def empty?
196196
def base=(value)
197197
if value
198198
raise JsonLdError::InvalidBaseIRI, "@base must be a string: #{value.inspect}" unless value.is_a?(String) || value.is_a?(RDF::URI)
199-
@base = @base ? @base.join(value) : RDF::URI(value).dup
199+
value = RDF::URI(value).dup
200+
value = @base.join(value) if @base && value.relative?
201+
@base = value
200202
@base.canonicalize! if @options[:canonicalize]
201203
raise JsonLdError::InvalidBaseIRI, "@base must be an absolute IRI: #{value.inspect}" unless @base.absolute? || !@options[:validate]
202204
@base

lib/json/ld/frame.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def cleanup_preserve(input)
157157
# If, after replacement, an array contains only the value null remove the value, leaving an empty array.
158158
input.map {|o| cleanup_preserve(o)}.compact
159159
when Hash
160-
output = Hash.new(input.size)
160+
output = Hash.new
161161
input.each do |key, value|
162162
if key == '@preserve'
163163
# replace all key-value pairs where the key is @preserve with the value from the key-pair

lib/json/ld/from_rdf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def from_statements(input)
2424
input.each do |statement|
2525
debug("statement") { statement.to_nquads.chomp}
2626

27-
name = statement.context ? ec.expand_iri(statement.context).to_s : '@default'
27+
name = statement.graph_name ? ec.expand_iri(statement.graph_name).to_s : '@default'
2828

2929
# Create a graph entry as needed
3030
node_map = graph_map[name] ||= {}

lib/json/ld/streaming_writer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def stream_prologue
3838
# @return [void] `self`
3939
def stream_statement(statement)
4040
debug("ss") {"state: #{@state.inspect}, stmt: #{statement}"}
41-
if @current_graph != statement.context
41+
if @current_graph != statement.graph_name
4242
end_graph
43-
start_graph(statement.context)
43+
start_graph(statement.graph_name)
4444
end
4545

4646
# If we're writing a list

spec/api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
end if File.exist?(framed) && File.exist?(frame)
9696

9797
it "toRdf" do
98-
expect(RDF::Repository.load(filename, adapter: adapter, debug: @debug)).to be_equivalent_graph(RDF::Repository.load(ttl), trace: @debug)
98+
expect(RDF::Repository.load(filename, format: :jsonld, adapter: adapter, debug: @debug)).to be_equivalent_graph(RDF::Repository.load(ttl), trace: @debug)
9999
end if File.exist?(ttl)
100100
end
101101
end

spec/context_spec.rb

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def containers
6565
end
6666

6767
it "notes non-existing @context" do
68-
expect {subject.parse(StringIO.new("{}"))}.to raise_error
68+
expect {subject.parse(StringIO.new("{}"))}.to raise_error(JSON::LD::JsonLdError::InvalidRemoteContext)
6969
end
7070

7171
it "parses a referenced context at a relative URI" do
@@ -262,7 +262,7 @@ def containers
262262
"@type as object" => {"foo" => {"@type" => {}}},
263263
"@type as array" => {"foo" => {"@type" => []}},
264264
"@type as @list" => {"foo" => {"@type" => "@list"}},
265-
"@type as @list" => {"foo" => {"@type" => "@set"}},
265+
"@type as @set" => {"foo" => {"@type" => "@set"}},
266266
"@container as object" => {"foo" => {"@container" => {}}},
267267
"@container as array" => {"foo" => {"@container" => []}},
268268
"@container as string" => {"foo" => {"@container" => "true"}},
@@ -364,130 +364,130 @@ def containers
364364
it "@type with dependent prefixes in a single context" do
365365
expect(subject.parse({
366366
'xsd' => "http://www.w3.org/2001/XMLSchema#",
367-
'homepage' => {'@id' => RDF::FOAF.homepage.to_s, '@type' => '@id'}
367+
'homepage' => {'@id' => RDF::Vocab::FOAF.homepage.to_s, '@type' => '@id'}
368368
}).
369369
send(:clear_provided_context).
370370
serialize).to produce({
371371
"@context" => {
372372
"xsd" => RDF::XSD.to_uri.to_s,
373-
"homepage" => {"@id" => RDF::FOAF.homepage.to_s, "@type" => "@id"}
373+
"homepage" => {"@id" => RDF::Vocab::FOAF.homepage.to_s, "@type" => "@id"}
374374
}
375375
}, @debug)
376376
end
377377

378378
it "@list with @id definition in a single context" do
379379
expect(subject.parse({
380-
'knows' => {'@id' => RDF::FOAF.knows.to_s, '@container' => '@list'}
380+
'knows' => {'@id' => RDF::Vocab::FOAF.knows.to_s, '@container' => '@list'}
381381
}).
382382
send(:clear_provided_context).
383383
serialize).to produce({
384384
"@context" => {
385-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
385+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
386386
}
387387
}, @debug)
388388
end
389389

390390
it "@set with @id definition in a single context" do
391391
expect(subject.parse({
392-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
392+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
393393
}).
394394
send(:clear_provided_context).
395395
serialize).to produce({
396396
"@context" => {
397-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
397+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
398398
}
399399
}, @debug)
400400
end
401401

402402
it "@language with @id definition in a single context" do
403403
expect(subject.parse({
404-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
404+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
405405
}).
406406
send(:clear_provided_context).
407407
serialize).to produce({
408408
"@context" => {
409-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
409+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
410410
}
411411
}, @debug)
412412
end
413413

414414
it "@language with @id definition in a single context and equivalent default" do
415415
expect(subject.parse({
416416
"@language" => 'en',
417-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
417+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
418418
}).
419419
send(:clear_provided_context).
420420
serialize).to produce({
421421
"@context" => {
422422
"@language" => 'en',
423-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
423+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
424424
}
425425
}, @debug)
426426
end
427427

428428
it "@language with @id definition in a single context and different default" do
429429
expect(subject.parse({
430430
"@language" => 'en',
431-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
431+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
432432
}).
433433
send(:clear_provided_context).
434434
serialize).to produce({
435435
"@context" => {
436436
"@language" => 'en',
437-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
437+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
438438
}
439439
}, @debug)
440440
end
441441

442442
it "null @language with @id definition in a single context and default" do
443443
expect(subject.parse({
444444
"@language" => 'en',
445-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
445+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
446446
}).
447447
send(:clear_provided_context).
448448
serialize).to produce({
449449
"@context" => {
450450
"@language" => 'en',
451-
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
451+
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
452452
}
453453
}, @debug)
454454
end
455455

456456
it "prefix with @type and @list" do
457457
expect(subject.parse({
458-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
458+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
459459
}).
460460
send(:clear_provided_context).
461461
serialize).to produce({
462462
"@context" => {
463-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
463+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
464464
}
465465
}, @debug)
466466
end
467467

468468
it "prefix with @type and @set" do
469469
expect(subject.parse({
470-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
470+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
471471
}).
472472
send(:clear_provided_context).
473473
serialize).to produce({
474474
"@context" => {
475-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
475+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
476476
}
477477
}, @debug)
478478
end
479479

480480
it "CURIE with @type" do
481481
expect(subject.parse({
482-
"foaf" => RDF::FOAF.to_uri.to_s,
482+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
483483
"foaf:knows" => {
484484
"@container" => "@list"
485485
}
486486
}).
487487
send(:clear_provided_context).
488488
serialize).to produce({
489489
"@context" => {
490-
"foaf" => RDF::FOAF.to_uri.to_s,
490+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
491491
"foaf:knows" => {
492492
"@container" => "@list"
493493
}
@@ -498,20 +498,20 @@ def containers
498498
it "does not use aliased @id in key position" do
499499
expect(subject.parse({
500500
"id" => "@id",
501-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
501+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
502502
}).
503503
send(:clear_provided_context).
504504
serialize).to produce({
505505
"@context" => {
506506
"id" => "@id",
507-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
507+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
508508
}
509509
}, @debug)
510510
end
511511

512512
it "does not use aliased @id in value position" do
513513
expect(subject.parse({
514-
"foaf" => RDF::FOAF.to_uri.to_s,
514+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
515515
"id" => "@id",
516516
"foaf:homepage" => {
517517
"@type" => "@id"
@@ -520,7 +520,7 @@ def containers
520520
send(:clear_provided_context).
521521
serialize).to produce({
522522
"@context" => {
523-
"foaf" => RDF::FOAF.to_uri.to_s,
523+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
524524
"id" => "@id",
525525
"foaf:homepage" => {
526526
"@type" => "@id"
@@ -531,14 +531,14 @@ def containers
531531

532532
it "does not use aliased @type" do
533533
expect(subject.parse({
534-
"foaf" => RDF::FOAF.to_uri.to_s,
534+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
535535
"type" => "@type",
536536
"foaf:homepage" => {"@type" => "@id"}
537537
}).
538538
send(:clear_provided_context).
539539
serialize).to produce({
540540
"@context" => {
541-
"foaf" => RDF::FOAF.to_uri.to_s,
541+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
542542
"type" => "@type",
543543
"foaf:homepage" => {"@type" => "@id"}
544544
}
@@ -548,13 +548,13 @@ def containers
548548
it "does not use aliased @container" do
549549
expect(subject.parse({
550550
"container" => "@container",
551-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
551+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
552552
}).
553553
send(:clear_provided_context).
554554
serialize).to produce({
555555
"@context" => {
556556
"container" => "@container",
557-
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
557+
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
558558
}
559559
}, @debug)
560560
end
@@ -881,7 +881,6 @@ def containers
881881
"unmapped" => ["foo", "foo"],
882882
"bnode" => ["_:a", RDF::Node("a")],
883883
"relative" => ["foo/bar", "http://base/foo/bar"],
884-
"odd CURIE" => ["exp:s", "http://example.org/perts"],
885884
"odd CURIE" => ["ex:perts", "http://example.org/perts"]
886885
}.each do |title, (result, input)|
887886
it title do
@@ -1044,9 +1043,9 @@ def containers
10441043
describe "#expand_value" do
10451044
subject {
10461045
ctx = context.parse({
1047-
"dc" => RDF::DC.to_uri.to_s,
1046+
"dc" => RDF::Vocab::DC.to_uri.to_s,
10481047
"ex" => "http://example.org/",
1049-
"foaf" => RDF::FOAF.to_uri.to_s,
1048+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
10501049
"xsd" => "http://www.w3.org/2001/XMLSchema#",
10511050
"foaf:age" => {"@type" => "xsd:integer"},
10521051
"foaf:knows" => {"@type" => "@id"},
@@ -1136,9 +1135,9 @@ def containers
11361135
describe "#compact_value" do
11371136
let(:ctx) do
11381137
c = context.parse({
1139-
"dc" => RDF::DC.to_uri.to_s,
1138+
"dc" => RDF::Vocab::DC.to_uri.to_s,
11401139
"ex" => "http://example.org/",
1141-
"foaf" => RDF::FOAF.to_uri.to_s,
1140+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
11421141
"xsd" => RDF::XSD.to_s,
11431142
"langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
11441143
"list" => {"@id" => "http://example.org/list", "@container" => "@list"},
@@ -1158,7 +1157,7 @@ def containers
11581157
"integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
11591158
"date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
11601159
"no IRI" => ["foo", {"@id" =>"http://example.com/"},{"@id" => "http://example.com/"}],
1161-
"no IRI (CURIE)" => ["foo", {"@id" => RDF::FOAF.Person.to_s}, {"@id" => RDF::FOAF.Person.to_s}],
1160+
"no IRI (CURIE)" => ["foo", {"@id" => RDF::Vocab::FOAF.Person.to_s}, {"@id" => RDF::Vocab::FOAF.Person.to_s}],
11621161
"no boolean" => ["foo", {"@value" => "true", "@type" => RDF::XSD.boolean.to_s},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
11631162
"no integer" => ["foo", {"@value" => "54", "@type" => RDF::XSD.integer.to_s},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
11641163
"no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],

0 commit comments

Comments
 (0)