W3C home > Mailing lists > Public > public-linked-json@w3.org > December 2015

Re: Casting literals as IRIs

From: Jindřich Mynarz <mynarzjindrich@gmail.com>
Date: Fri, 18 Dec 2015 12:40:10 +0100
Message-ID: <CAE=8Bu8DQ0p=r2m4zsePXQBg+xV+0Bk_xpT5D7qQjnr1jeJ8WA@mail.gmail.com>
To: public-linked-json@w3.org
I see. When I compact my data:

{
  "@id": "http://mynarz.net/#jindrich",
  "http://xmlns.com/foaf/0.1/knows": [
    "http://ruben.verborgh.org/#me",
    "http://richard.cyganiak.de/foaf.rdf#cygri"
  ]
}

With this @context:

{
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "http://xmlns.com/foaf/0.1/knows": {
      "@type": "@id"
    }
  }
}

I get this:

{
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "http://xmlns.com/foaf/0.1/knows": {
      "@type": "@id"
    }
  },
  "@id": "http://mynarz.net/#jindrich",
  "foaf:knows": [
    "http://ruben.verborgh.org/#me",
    "http://richard.cyganiak.de/foaf.rdf#cygri"
  ]
}

Objects of foaf:knows are not explicitly marked as IRIs (e.g., {"@id": "
http://ruben.verborgh.org/#me"}), because this is inferred from the
@context.

Permalink:
http://json-ld.org/playground/#startTab=tab-compacted&json-ld=%7B%22%40id%22%3A%22http%3A%2F%2Fmynarz.net%2F%23jindrich%22%2C%22http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fknows%22%3A%5B%22http%3A%2F%2Fruben.verborgh.org%2F%23me%22%2C%22http%3A%2F%2Frichard.cyganiak.de%2Ffoaf.rdf%23cygri%22%5D%7D&context=%7B%22%40context%22%3A%7B%22foaf%22%3A%22http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%22%2C%22http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fknows%22%3A%7B%22%40type%22%3A%22%40id%22%7D%7D%7D

Thanks!

- Jindřich

On Fri, Dec 18, 2015 at 12:35 PM, Dietrich Schulten <ds@escalon.de> wrote:

> Your source json-ld is already expanded, so compaction only will be
> sufficient.
> Expansion means: removing the @context by applying its term definitions.
>
> You can experiment in the json-ld playground [1]
>
> There are a number of json ld api implementations, if your language is
> among them, you probably wouldn't implement the api yourself.
>
> [1] http://json-ld.org/playground/
> Am 18.12.2015 10:15 schrieb Jindřich Mynarz <mynarzjindrich@gmail.com>:
>
> Hi all,
>
> Markus, thank you for the solution, and Dietrich, thank you for implying
> an explanation.
>
> However, I wonder if it's not possible to coerce objects as IRIs (
> http://www.w3.org/TR/json-ld/#h3_type-coercion) *and* compact the
> property IRI in a single operation of the JSON-LD API.
>
> Currently, I understand I need to do the following to coerce objects as
> IRIs and compact the property IRI.
>
> Starting with this JSON-LD:
>
> {
>   "@id": "http://mynarz.net/#jindrich",
>   "http://xmlns.com/foaf/0.1/knows": [
>     "http://ruben.verborgh.org/#me",
>     "http://richard.cyganiak.de/foaf.rdf#cygri"
>   ]
> }
>
> I need to jam this @context in:
>
> {
>   "@context": {
>     "http://xmlns.com/foaf/0.1/knows": {
>       "@type": "@id"
>     }
>   }
> }
>
> Then I can expand (http://www.w3.org/TR/json-ld-api/#expansion) the
> JSON-LD and compact (http://www.w3.org/TR/json-ld-api/#compaction) the
> result of expansion with the following @context if compact IRIs are desired:
>
> {
>   "@context": {
>     "foaf": "http://xmlns.com/foaf/0.1/"
>   }
> }
>
> Is that a correct approach?
>
> - Jindřich
>
> --
> Jindřich Mynarz
> http://mynarz.net/#jindrich
>
> On Fri, Dec 18, 2015 at 9:24 AM, Adrian Pohl <pohl@hbz-nrw.de> wrote:
>
>> Sorry for prematurely sending the former mail. Thinking about what I
>> wanted to say, my intended response isn't that relevant to this thread. As
>> I am already writing this, I will just mention it anyway.
>>
>> I just recently stumbled over the ability to define both @type and
>> @container in the context, e.g.
>>
>> {
>>   "@context": {
>>     "foaf": "http://xmlns.com/foaf/0.1/",
>>     "foaf:knows": {
>>       "@type": "@id",
>>       "@container": "@set"
>>     }
>>   },
>>   "@id": "http://mynarz.net/#jindrich",
>>   "http://xmlns.com/foaf/0.1/knows": [
>>     "http://ruben.verborgh.org/#me",
>>     "http://richard.cyganiak.de/foaf.rdf#cygri"
>>   ]
>> }
>>
>> Actually, this doesn't make a big difference in this case. It would make
>> sense, though, if you had some foaf:knows triples with only one object and
>> also wanted these to be delivered as an array for the sake of homogeneity...
>>
>> All the best
>> Adrian
>>
>>
>>
>> Am 18.12.2015 um 09:13 schrieb Adrian Pohl:
>>
>>> Hello Jindřich,
>>>
>>> with this context:
>>>
>>> Am 17.12.2015 um 23:53 schrieb Markus Lanthaler:
>>>
>>>> Hi Jindřich,
>>>>
>>>>
>>>> On Thursday, December 17, 2015 11:04 AM, Jindřich Mynarz wrote:
>>>>
>>>>> I found that some services return JSON-LD, in which IRIs are serialized
>>>>> as literals. For example, consider the following example:
>>>>>
>>>>> {
>>>>>    "@id": "http://mynarz.net/#jindrich",
>>>>>    "http://xmlns.com/foaf/0.1/knows": [
>>>>>       "http://ruben.verborgh.org/#me",
>>>>>       "http://richard.cyganiak.de/foaf.rdf#cygri"
>>>>>    ]
>>>>> }
>>>>>
>>>>> The objects of foaf:knows are serialized as literals, even though they
>>>>> are IRIs.
>>>>>
>>>>> Now, if I want to recover the objects of foaf:knows as IRIs, the
>>>>> following context is of no use:
>>>>>
>>>>> {
>>>>>    "@context": {
>>>>>      "foaf": "http://xmlns.com/foaf/0.1/",
>>>>>      "foaf:knows": {"@type": "@id"}
>>>>>    }
>>>>> }
>>>>>
>>>>
>>>> What about this context:
>>>>
>>>>    "@context": {
>>>>      "http://xmlns.com/foaf/0.1/knows": { "@type": "@id" }
>>>>    }
>>>>
>>>> Result: http://tinyurl.com/hadcx4d
>>>>
>>>>
>>>> HTH,
>>>> Markus
>>>>
>>>>
>>>> --
>>>> Markus Lanthaler
>>>> @markuslanthaler
>>>>
>>>>
>>>>
>>>
>>
>
Received on Friday, 18 December 2015 11:41:03 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:18:46 UTC