W3C home > Mailing lists > Public > public-hydra@w3.org > July 2014

RE: Introduction and a question about JSON-LD

From: john.walker <john.walker@semaku.com>
Date: Fri, 25 Jul 2014 22:37:51 +0200 (CEST)
To: public-hydra@w3.org, Markus Lanthaler <markus.lanthaler@gmx.net>, info@dimitrivanhees.com
Message-ID: <38829080.963997.1406320671827.open-xchange@oxweb02.eigbox.net>
Hi Dimitri,

I took the liberty to modify your original a little bit:

{
  "@context": [
    "https://rawgit.com/json-ld/json-ld.org/master/contexts/schema.org.jsonld",
    {
      "@base": "http://data.freshheads.com/",
      "id": "@id",
      "type": "@type"
    }
  ],
  "id": "dimitri",
  "type": "Person",
  "givenName": "Dimitri",
  "additionalName": "van",
  "familyName": "Hees",
  "gender": "male",
  "homeLocation": "Tilburg"
}

I combined an external and local context as shown in example 29 of Advanced
Context Usage section of the JSON-LD spec [1].
As you can see I used the Schema.org context off GitHub served via RawGit so
that it plays nice in the JSON-LD playground.
Ideally you would just need to use "http://schema.org/", but that doesn't work
in the playground (guess it sends wrong Accept header when fetching the
context).

Anyway, when you look at the N-Quads output, you'll see that Tilburg is
magically turned into the URI <http://data.freshheads.com/Tilburg> (which has
been resolved against the @base URI).

A client that followed that link would hopefully find more JSON-LD there that
describes Tilburg.
That might include a schema:sameAs link to the Wikipedia page, Freebase page, or
official website for Tilburg.

Of course you might decide to just link directly to an existing URI, but minting
your own URI would also give Freshheads the possibility to publish your own
description of Tilburg (remember Anyone can say Anything about Anything :) ).

Groetjes,
John

[1] http://www.w3.org/TR/json-ld/#advanced-context-usage


> On July 25, 2014 at 7:45 PM Markus Lanthaler <markus.lanthaler@gmx.net> wrote:
>
>
> Hi Dimitri,
>
> On Thursday, July 24, 2014 12:36 PM, Dimitri van Hees wrote:
> > I've been following this list for a few months now but have not yet
> > been in the opportunity to introduce myself or contribute anything. As
> > I have a question about JSON-LD, I think this might be the right time
> > to do so ;-)
>
> Great! Good to see you here :-)
>
>
> > That said, it was time for me to actually start implementing this
> > model in our own API's. For this purpose we created a demo API which
> > represents our 26 employees, including birthdates, hometowns, hobbies,
> > functions, education, etc. I want to add Hydra in the JSON-LD
>
> Cool!
>
>
> > representation, HATEOAS in the JSON representation (does that sound
> > reasonable by the way?)
>
> Sounds a bit weird to me as HATEOAS is a description of what drives the
> application. I would say "add hypermedia controls to JSON" instead.
>
>
> > and also provide an application/nquads
> > representation to fetch the triples and load them into a triplestore
> > one by one.
> >
> > After spending hours reading the documentation I still can't find what
> > I'm doing wrong with the conversion to JSON-LD. I hope this list will
> > help me out a little bit. Let's say I have this response (in real life
> > this is valid JSON but my mail client sucks at the moment 😉):
> >
> > id: dimitri,
> > givenName: Dimitri,
> > additionalName: van,
> > familyName: Hees,
> > gender: male,
> > birthplace: Nijmegen,
> > residence: Tilburg
> >
> > As you might have noticed the properties are all schema.org except
> > birthplace and residence. When converting this to JSON-LD I think I
> > could say:
> >
> > @context: {
> > schema: http://schema.org/,
> > givenName: {@id: schema:givenName},
> > addition…
> > birthplace: {@id: schema:City, @type: @id},
> > residence: {@id: schema:City, @type: @id},
>
> These two mappings here are the problem. You map two properties, birthplace
> and residence to schema:City which isn't a property but a class. There's no
> property for birthplace in Schema.org yet (I think it would make sense to
> propose one on public-vocabs@w3.org). For residence, you could use either
> schema:homeLocation or schema:workLocation.
>
>
> > },
> > @id: http://data.freshheads.com/dimitri,
> > givenName: Dimitri,
> > additon…,
> > birthplace: {
> > @id: http://www.nijmegen.nl
> > },
> > residence: {
> > @id: http://www.tilburg.nl
> > }
> >
> > The problem is that both birthplace and residence are being converted
> > to City while they don't seem to be an actual 'City' anymore. When I
> > add it to the valueobject itself:
> >
> > birthplace: {
> > @id: http://www.nijmegen.nl
> > @type: http://schema.org/City
> > }
> >
> > then it works they way I'd expect. But I don't really understand why.
> > Any thoughts?
>
> Type coercion in the context only works for literals, i.e., simple strings. In
> other words, you can convert a simple string to an @id object by setting
> @type: @id or to a @value object with a @type by setting @type to the desired
> datatype in the context. Please not that you can NOT type nodes (@id objects)
> from within the context. You need to do so directly in the document itself.
> Node types and value types are treated differently.
>
>
> HTH,
> Markus
>
>
> --
> Markus Lanthaler
> @markuslanthaler
>
>
>
>
Received on Friday, 25 July 2014 20:38:14 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:29:42 UTC