Reputation: 2940
I have a problem to construct IRI for the object using a prefix and a data value when converting non-edited JSON data into JSON-LD. The example code I have running is:
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab" : "http://example.com/" ,
"load" : "prefix:load"
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "prefix:t1" ,
"items" :
[
{ "@id" : "prefix:t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "prefix:t3",
"@type" : "item",
"load" : "some2222"
}
]
}
but when I change the @id
values from "prefix:t1" to the plain data values I have in the original JSON (i.e. to just "t1", "t2" and "t3") the objects are not dealt with anymore.
The code which is not proper JSON-LD (at least not read by riot
)
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab" : "http://example.com/" ,
"load" : "prefix:load"
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "t1" ,
"items" :
[
{ "@id" : "t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "t3",
"@type" : "item",
"load" : "some2222"
}
]
}
The value "t1" etc. are unique and I would like to use them with a prefix as IRI to link the data with other data. Is there a way to produce the IRI with some addition to the context without changing the program which produces the JSON data or edit the file.
I found a solution (based on the solution of Json-LD > Define a "person" for easy reuse as values on different keys for WebPage schema) but do not understand why it works.
{
"@context" :
{ "prefix" : "http://www.gerastree.at/",
"rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@base" : "http://example.com/" ,
"load" : "prefix:load",
"items" : "prefix:item"
},
"@type" : "tree",
"@id" : "t1" ,
"items" :
[
{ "@id" : "t2",
"@type" : "item",
"load" : "some111"
},
{ "@id" : "t3",
"@type" : "item",
"load" : "some2222"
}
]
}
I do not think this is a duplicate of Any way to specify the default URI for the @id of a @type or the values of a property? .
What additions and changes to the context are necesary?
Upvotes: 3
Views: 664
Reputation: 2940
I found the explanation why my third version works as desired with some more reading of the JSON-LD recommendations and experimentation.
@vocab
is applied to properties and objects only
@base
is used to complete IRI for the subject.
not really obvious but flexible enough for my application.
Upvotes: 1