- From: Asbjørn Ulsberg <asbjorn@ulsberg.no>
- Date: Wed, 4 Nov 2015 12:06:07 +0100
- To: Melvin Carvalho <melvincarvalho@gmail.com>
- Cc: Dimitri van Hees <info@dimitrivanhees.com>, "public-hydra@w3.org" <public-hydra@w3.org>
2015-11-04 10:04 GMT+01:00 Melvin Carvalho <melvincarvalho@gmail.com>: > > > On 4 November 2015 at 09:25, Dimitri van Hees <info@dimitrivanhees.com> > wrote: >> >> Hi all, >> >> I've been digging into all the JSON-LD specs to make sure that I >> understand all the possibilities of using an external context file. I have >> two questions about this. Please not that I am not trying to start a >> discussion, I just want to make sure if I understood it correct and can >> start looking for another solution :-) >> >> Image I have the following plain JSON. I have no influence on this, only >> on the external JSON-LD context file. >> >> { >> "results": [ >> { >> "id": 1, >> "title": "Event 1" >> }, >> { >> "id": 2, >> "title": "Event 2" >> } >> ] >> } >> >> Question 1) "id": "@id" won't work, because "id" is an integer instead of >> a string. Event when using "@base" : "http://my.example.com/events/" this >> doesn't work. Is it correct that there currently isn't a way to 'map' these >> things using an external context file? > > > @id must be a URI. It must expand to an URI in combination with the (implicit) "@base", is how I read the specification. > Not sure it can be a number literal. I can't find anything restricting the type of @id in the specification, but according to the Playground, it needs to be a string unless you wrangle the context quite a bit. Here's a pretty wrangled context: { "@context": { "@base" : "http://base.com/", "@vocab" : "http://vocab.com/vocab#", "id" : { "@type" : "@id", "@id" : "Id" }, "title" : "Title", "results": { "@id" : "Event", "@container" : "@index" } }, "results": [ { "id": 1, "title": "Event 1" }, { "id": 2, "title": "Event 2" } ] } If you don't want the "id" to be a URL, remove "@type" : "@id". > Mapping an number to an id would be to add a scheme e.g. urn:uuid: > before it. You don't need to do anything else with the "id" properties than wrap their values in quotes so they are strings. Not sure why JSON-LD (Playground) has this limitation, but it's there. > Unsure this can be done in @context, dont think so. I think I managed to do it in the above example, but I'm not confident it's right. >> Question 2) I want the items in the "results" array to be of the type >> "http://my.example.com/Event". Is it correct that I cannot achieve this >> without inserting "@type" : "http://my.example.com/Event" within each item >> in the plain JSON, thus cannot achieve this using an external context file? > > If title was mapped to something with "range" = http://my.example.com/Event > then software could infer it by dereferencing "title" at it's full URI. > Ordinarily Im unsure type can be inserted from the @context. Id be happy to > be corrected there! Well, the "Event" type isn't something I've been able to map. Ideally, I'd say that the "results" property is a "@graph", but then you'd loose type information. With the above context, there's at least a hint given in that "results" has an "@id" of "Event", but that is not its "@type". You can add "@type" : "Event", but that does not have any effect, as far as I can tell. -- Asbjørn Ulsberg -=|=- asbjorn@ulsberg.no «He's a loathsome offensive brute, yet I can't look away»
Received on Wednesday, 4 November 2015 11:06:38 UTC