Skip to content

Commit f94d69e

Browse files
committed
Use graph_name instead of context from RDF.rb.
1 parent 4791ba9 commit f94d69e

File tree

9 files changed

+51
-48
lines changed

9 files changed

+51
-48
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

json-ld.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Gem::Specification.new do |gem|
3939
gem.add_development_dependency 'rdf-spec', '~> 1.1'
4040
gem.add_development_dependency 'rdf-trig', '~> 1.1'
4141
gem.add_development_dependency 'rdf-turtle', '~> 1.1'
42+
gem.add_development_dependency 'rdf-vocab', '~> 0.8'
4243
gem.add_development_dependency 'rdf-xsd', '~> 1.1'
4344
gem.add_development_dependency 'rspec', '~> 3.2.0'
4445
gem.add_development_dependency 'rspec-its', '~> 1.0'

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/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/context_spec.rb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -1044,9 +1044,9 @@ def containers
10441044
describe "#expand_value" do
10451045
subject {
10461046
ctx = context.parse({
1047-
"dc" => RDF::DC.to_uri.to_s,
1047+
"dc" => RDF::Vocab::DC.to_uri.to_s,
10481048
"ex" => "http://example.org/",
1049-
"foaf" => RDF::FOAF.to_uri.to_s,
1049+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
10501050
"xsd" => "http://www.w3.org/2001/XMLSchema#",
10511051
"foaf:age" => {"@type" => "xsd:integer"},
10521052
"foaf:knows" => {"@type" => "@id"},
@@ -1136,9 +1136,9 @@ def containers
11361136
describe "#compact_value" do
11371137
let(:ctx) do
11381138
c = context.parse({
1139-
"dc" => RDF::DC.to_uri.to_s,
1139+
"dc" => RDF::Vocab::DC.to_uri.to_s,
11401140
"ex" => "http://example.org/",
1141-
"foaf" => RDF::FOAF.to_uri.to_s,
1141+
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
11421142
"xsd" => RDF::XSD.to_s,
11431143
"langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
11441144
"list" => {"@id" => "http://example.org/list", "@container" => "@list"},
@@ -1158,7 +1158,7 @@ def containers
11581158
"integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
11591159
"date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
11601160
"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}],
1161+
"no IRI (CURIE)" => ["foo", {"@id" => RDF::Vocab::FOAF.Person.to_s}, {"@id" => RDF::Vocab::FOAF.Person.to_s}],
11621162
"no boolean" => ["foo", {"@value" => "true", "@type" => RDF::XSD.boolean.to_s},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
11631163
"no integer" => ["foo", {"@value" => "54", "@type" => RDF::XSD.integer.to_s},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
11641164
"no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],

spec/flatten_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"embedded object" => {
1717
input: {
1818
"@context" => {
19-
"foaf" => RDF::FOAF.to_s
19+
"foaf" => RDF::Vocab::FOAF.to_s
2020
},
2121
"@id" => "http://greggkellogg.net/foaf",
2222
"@type" => ["foaf:PersonalProfileDocument"],
@@ -28,19 +28,19 @@
2828
output: [
2929
{
3030
"@id" => "http://greggkellogg.net/foaf",
31-
"@type" => [RDF::FOAF.PersonalProfileDocument.to_s],
32-
RDF::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
31+
"@type" => [RDF::Vocab::FOAF.PersonalProfileDocument.to_s],
32+
RDF::Vocab::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
3333
},
3434
{
3535
"@id" => "http://greggkellogg.net/foaf#me",
36-
"@type" => [RDF::FOAF.Person.to_s]
36+
"@type" => [RDF::Vocab::FOAF.Person.to_s]
3737
}
3838
]
3939
},
4040
"embedded anon" => {
4141
input: {
4242
"@context" => {
43-
"foaf" => RDF::FOAF.to_s
43+
"foaf" => RDF::Vocab::FOAF.to_s
4444
},
4545
"@id" => "http://greggkellogg.net/foaf",
4646
"@type" => "foaf:PersonalProfileDocument",
@@ -51,12 +51,12 @@
5151
output: [
5252
{
5353
"@id" => "_:b0",
54-
"@type" => [RDF::FOAF.Person.to_s]
54+
"@type" => [RDF::Vocab::FOAF.Person.to_s]
5555
},
5656
{
5757
"@id" => "http://greggkellogg.net/foaf",
58-
"@type" => [RDF::FOAF.PersonalProfileDocument.to_s],
59-
RDF::FOAF.primaryTopic.to_s => [{"@id" => "_:b0"}]
58+
"@type" => [RDF::Vocab::FOAF.PersonalProfileDocument.to_s],
59+
RDF::Vocab::FOAF.primaryTopic.to_s => [{"@id" => "_:b0"}]
6060
}
6161
]
6262
},

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'rdf/nquads'
99
require 'rdf/turtle'
1010
require 'rdf/trig'
11+
require 'rdf/vocab'
1112
require 'rdf/spec'
1213
require 'rdf/spec/matchers'
1314
require 'yaml'

spec/writer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
it "should use CURIEs with empty prefix" do
7272
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
7373
begin
74-
expect(serialize(input, prefixes: { "" => RDF::FOAF})).
74+
expect(serialize(input, prefixes: { "" => RDF::Vocab::FOAF})).
7575
to produce({
7676
"@context" => {
7777
"" => "http://xmlns.com/foaf/0.1/"
@@ -133,7 +133,7 @@
133133
to produce({
134134
'@context' => {
135135
"" => "http://www.w3.org/2006/03/test-description#",
136-
"dc" => RDF::DC.to_s
136+
"dc" => RDF::Vocab::DC.to_s
137137
},
138138
'@graph' => [
139139
{'@id' => "http://example.com/test-cases/0001", '@type' => ":TestCase"},

0 commit comments

Comments
 (0)