Skip to content

Commit 3dbd1b2

Browse files
committed
Change to use "@vocab": "" semantics, and vocabulary expansion/compaction just as if the effective document base was specified as @vocab.
1 parent 29e4472 commit 3dbd1b2

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

lib/json/ld/context.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,16 @@ def version=(value)
354354
# @param [String] value must be an absolute IRI
355355
def vocab=(value)
356356
@vocab = case value
357-
when /_:/, '@base'
357+
when /_:/
358358
value
359359
when String, RDF::URI
360-
v = as_resource(value.to_s)
361-
raise JsonLdError::InvalidVocabMapping, "@vocab must be an absolute IRI: #{value.inspect}" if v.uri? && v.relative? && @options[:validate]
360+
v = as_resource(value.to_s, base)
361+
raise JsonLdError::InvalidVocabMapping, "@vocab must be an IRI: #{value.inspect}" if !v.valid? && @options[:validate]
362362
v
363363
when nil
364364
nil
365365
else
366-
raise JsonLdError::InvalidVocabMapping, "@vocab must be an absolute IRI: #{value.inspect}"
366+
raise JsonLdError::InvalidVocabMapping, "@vocab must be an IRI: #{value.inspect}"
367367
end
368368
end
369369

@@ -1034,10 +1034,10 @@ def expand_iri(value, documentRelative: false, vocab: false, local_context: nil,
10341034
end
10351035
#log_debug("") {"=> #{result.inspect}"} unless quiet
10361036

1037-
result = if vocab && self.vocab && self.vocab != '@base'
1037+
result = if vocab && self.vocab
10381038
# If vocab is true, and active context has a vocabulary mapping, return the result of concatenating the vocabulary mapping with value.
10391039
self.vocab + value
1040-
elsif (documentRelative || self.vocab == '@base') && (base ||= self.base)
1040+
elsif (documentRelative || self.vocab == '') && (base ||= self.base)
10411041
# Otherwise, if document relative is true, set value to the result of resolving value against the base IRI. Only the basic algorithm in section 5.2 of [RFC3986] is used; neither Syntax-Based Normalization nor Scheme-Based Normalization are performed. Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of [RFC3987].
10421042
value = RDF::URI(value)
10431043
value.absolute? ? value : RDF::URI(base).join(value)
@@ -1221,7 +1221,7 @@ def compact_iri(iri, value: nil, vocab: nil, reverse: false, quiet: false, **opt
12211221
return candidates.term_sort.first if !candidates.empty?
12221222
end
12231223

1224-
if !vocab || self.vocab == '@base'
1224+
if !vocab
12251225
# transform iri to a relative IRI using the document's base IRI
12261226
iri = remove_base(iri)
12271227
#log_debug("") {"=> relative iri: #{iri.inspect}"} unless quiet

spec/compact_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,11 +2153,11 @@
21532153
"ex:bar": "term"
21542154
})
21552155
},
2156-
"compacts using base if @vocab: @base" => {
2156+
"compacts using base if @vocab: relative" => {
21572157
input: %({"http://example.org/foo/bar": "term"}),
2158-
context: %({"@base": "http://example.org/foo/", "@vocab": "@base"}),
2158+
context: %({"@base": "http://example.org/foo/", "@vocab": ""}),
21592159
output: %({
2160-
"@context": {"@base": "http://example.org/foo/", "@vocab": "@base"},
2160+
"@context": {"@base": "http://example.org/foo/", "@vocab": ""},
21612161
"bar": "term"
21622162
})
21632163
},

spec/context_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,11 @@ def containers
859859
end
860860
end
861861

862-
context "set to @base" do
862+
context "set to ''" do
863863
subject {
864864
context.parse({
865865
'@base' => 'http://base/base',
866-
'@vocab' => '@base',
866+
'@vocab' => '',
867867
'ex' => 'http://example.org/',
868868
'' => 'http://empty/',
869869
'_' => 'http://underscore/'
@@ -876,9 +876,9 @@ def containers
876876
"prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
877877
"keyword" => ["@type", "@type"],
878878
"empty" => [":suffix", RDF::URI("http://empty/suffix")],
879-
"unmapped" => ["foo", RDF::URI("http://base/foo")],
880-
"relative" => ["foo/bar", RDF::URI("http://base/foo/bar")],
881-
"dotseg" => ["../foo/bar", RDF::URI("http://base/foo/bar")],
879+
"unmapped" => ["foo", RDF::URI("http://base/basefoo")],
880+
"relative" => ["foo/bar", RDF::URI("http://base/basefoo/bar")],
881+
"dotseg" => ["../foo/bar", RDF::URI("http://base/base../foo/bar")],
882882
"empty term" => ["", RDF::URI("http://empty/")],
883883
"another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
884884
"absolute IRI looking like a curie" =>
@@ -971,9 +971,9 @@ def containers
971971
not_to produce("name", logger)
972972
end
973973

974-
context "with @vocab: @base" do
974+
context "with @vocab: relative" do
975975
before(:each) {
976-
subject.vocab = "@base"
976+
subject.vocab = ""
977977
subject.base = 'http://base/base'
978978
}
979979

spec/expand_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
{
178178
"base": {
179179
input: %({
180-
"@context": {"@vocab": "http:///vocab/"},
180+
"@context": {"@vocab": "http://vocab/"},
181181
"http://a/b": "foo"
182182
}),
183183
output: %([{
@@ -216,11 +216,11 @@
216216
end
217217
end
218218

219-
context "with @vocab: @base" do
219+
context "with @vocab: ''" do
220220
{
221221
"base": {
222222
input: %({
223-
"@context": {"@vocab": "@base"},
223+
"@context": {"@vocab": ""},
224224
"http://a/b": "foo"
225225
}),
226226
output: %([{
@@ -229,7 +229,7 @@
229229
},
230230
"relative": {
231231
input: %({
232-
"@context": {"@vocab": "@base"},
232+
"@context": {"@vocab": ""},
233233
"a/b": "foo"
234234
}),
235235
output: %([{
@@ -238,7 +238,7 @@
238238
},
239239
"hash": {
240240
input: %({
241-
"@context": {"@vocab": "@base"},
241+
"@context": {"@vocab": ""},
242242
"#a": "foo"
243243
}),
244244
output: %([{
@@ -247,18 +247,18 @@
247247
},
248248
"dotseg": {
249249
input: %({
250-
"@context": {"@vocab": "@base"},
250+
"@context": {"@vocab": ""},
251251
"../a": "foo"
252252
}),
253253
output: %([{
254-
"http://example.org/a": [{"@value": "foo"}]
254+
"http://example.org/../a": [{"@value": "foo"}]
255255
}])
256256
},
257257
"example": {
258258
input: %({
259259
"@context": {
260260
"@base": "http://example/document",
261-
"@vocab": "@base"
261+
"@vocab": ""
262262
},
263263
"@id": "http://example.org/places#BrewEats",
264264
"@type": "#Restaurant",

0 commit comments

Comments
 (0)