- From: Gregg Kellogg <gregg@greggkellogg.net>
- Date: Sun, 20 Dec 2015 12:21:02 -0800
- To: Jindřich Mynarz <mynarzjindrich@gmail.com>
- Cc: public-linked-json@w3.org
- Message-Id: <BA1B7123-C602-47CA-9AE9-70CF354127DE@greggkellogg.net>
> On Dec 20, 2015, at 12:11 AM, Jindřich Mynarz <mynarzjindrich@gmail.com> wrote: > > Hi Gregg, > > thanks for your suggestion. I was able to reproduce it with http://rdf.greggkellogg.net/distiller <http://rdf.greggkellogg.net/distiller>. However, why do you need to change the input JSON-LD? I tried to follow the same procedure with my JSON-LD provided with the @context, but I ended up with rdf:first and rdf:rest instead of @list. Is there a problem in my @context? The Input your provided used “ex”, “rdf”, and “foaf” prefixes without defining them in a context. They need to be in the source document so that JSON-LD knows how to expand them. Additionally, unless you define the @container typ of “rdf:first” and “rdf:rest”, they are treated as literals, not IRIs/BNodes. I expanded them to clarified that the values should be treated as resources and not strings. Gregg > - Jindřich > > On Sun, Dec 20, 2015 at 2:05 AM, Gregg Kellogg <gregg@greggkellogg.net <mailto:gregg@greggkellogg.net>> wrote: >> On Dec 19, 2015, at 9:56 AM, Jindřich Mynarz <mynarzjindrich@gmail.com <mailto:mynarzjindrich@gmail.com>> wrote: >> >> Hi, >> >> is it possible to compact rdf:Seq? >> >> For example, let's have this JSON-LD: >> >> { >> "@graph": [{ >> "ex:list": "_:b1" >> }, { >> "@id": "_:b1", >> "rdf:first": "_:b2", >> "rdf:rest": "_:b3" >> }, { >> "@id": "_:b2", >> "foaf:name": "Alice" >> }, { >> "@id": "_:b3", >> "rdf:first": "_:b4", >> "rdf:rest": "rdf:nil" >> }, { >> "@id": "_:b4", >> "foaf:name": "Bob" >> }] >> } >> >> We try to compact it with this context: >> >> { >> "@context": { >> "ex": "http://example.com/ <http://example.com/>", >> "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>", >> "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", >> "ex:list": {"@container": "@list", >> "@type": "@id"}, >> "rdf:first": {"@type": "@id"}, >> "rdf:rest": {"@type": "@id"} >> } >> } >> >> JSON-LD playground (jsonld.js) returns the following: >> >> { >> "@context": { >> "ex": "http://example.com/ <http://example.com/>", >> "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>", >> "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", >> "ex:list": { >> "@container": "@list", >> "@type": "@id" >> }, >> "rdf:first": { >> "@type": "@id" >> }, >> "rdf:rest": { >> "@type": "@id" >> } >> }, >> "@graph": [ >> { >> "ex:list": [ >> "_:b1" >> ] >> }, >> { >> "@id": "_:b1", >> "rdf:first": "_:b2", >> "rdf:rest": "_:b3" >> }, >> { >> "@id": "_:b2", >> "foaf:name": "Alice" >> }, >> { >> "@id": "_:b3", >> "rdf:first": "_:b4", >> "rdf:rest": "rdf:nil" >> }, >> { >> "@id": "_:b4", >> "foaf:name": "Bob" >> } >> ] >> } >> >> Is it possible to get to a compact representation of rdf:Seq (http://www.w3.org/TR/json-ld/#sets-and-lists <http://www.w3.org/TR/json-ld/#sets-and-lists>), like the following? >> >> { >> "@context": { >> "ex": "http://example.com/ <http://example.com/>", >> "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>", >> "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", >> "ex:list": { >> "@container": "@list", >> "@type": "@id" >> }, >> "rdf:first": { >> "@type": "@id" >> }, >> "rdf:rest": { >> "@type": "@id" >> } >> }, >> "@graph": [ >> { >> "ex:list": [ >> "_:b2", "_:b4" >> ] >> }, >> { >> "@id": "_:b2", >> "foaf:name": "Alice" >> }, >> { >> "@id": "_:b4", >> "foaf:name": "Bob" >> } >> ] >> } > > You can do much of what you want by going through RDF. If you turn the original input into N-Quads, and then serialize that back to JSON-LD you’ll get an @list. They playground doesn’t show N-Quads to JSON-LD, but you can do this through my Distiller (http://rdf.greggkellogg.net/distiller <http://rdf.greggkellogg.net/distiller>). I modified your input a bit: > > { > "@context": { > "ex": "http://example.com/ <http://example.com/>", > "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>", > "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" > }, > "@graph": [{ > "ex:list": {"@id": "_:b1"} > }, { > "@id": "_:b1", > "rdf:first": {"@id": "_:b2"}, > "rdf:rest": {"@id": "_:b3"} > }, { > "@id": "_:b2", > "foaf:name": "Alice" > }, { > "@id": "_:b3", > "rdf:first": {"@id": "_:b4"}, > "rdf:rest": {"@id": "rdf:nil"} > }, { > "@id": "_:b4", > "foaf:name": "Bob" > }] > } > > If you transform from JSON-LD to RDF and then serialize back to JSON-LD you get the following: > > { > "@context": { > "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>" > }, > "@graph": [ > { > "@id": "_:b0", > "http://example.com/list <http://example.com/list>": { > "@list": [ > { > "@id": "_:b2" > }, > { > "@id": "_:b4" > } > ] > } > }, > { > "@id": "_:b2", > "foaf:name": "Alice" > }, > { > "@id": "_:b4", > "foaf:name": "Bob" > } > ] > } > > To improve further requires framing, but not that it is using the @list shorthand. You can use the playground with your context to get the following: > > { > "@context": { > "ex": "http://example.com/ <http://example.com/>", > "foaf": "http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>", > "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", > "ex:list": { > "@container": "@list", > "@type": "@id" > }, > "rdf:first": { > "@type": "@id" > }, > "rdf:rest": { > "@type": "@id" > } > }, > "@graph": [ > { > "@id": "_:b0", > "ex:list": [ > "_:b2", > "_:b4" > ] > }, > { > "@id": "_:b2", > "foaf:name": "Alice" > }, > { > "@id": "_:b4", > "foaf:name": "Bob" > } > ] > } > > Gregg > >> - Jindřich >> >> -- >> Jindřich Mynarz >> http://mynarz.net/#jindrich <http://mynarz.net/#jindrich> >
Received on Sunday, 20 December 2015 20:21:34 UTC