Re: JSON-LD and Drupal

On Mon, Jun 18, 2012 at 10:23 PM, Larry Garfield <larry@garfieldtech.com> wrote:
> On 06/18/2012 03:34 AM, Henri Bergius wrote:
>>
>> On Mon, Jun 18, 2012 at 6:12 AM, Larry Garfield<larry@garfieldtech.com>
>>  wrote:
>>>
>>> Perhaps I'm just missing a detail (highly likely, in fact), but I am
>>> thinking of an equivalent of the link element in Atom.  There doesn't
>>> seem
>>> to be a standard place in JSON-LD I can see for explicitly external
>>> references, in contrast to nesting internal or external data.
>>
>> This is basically just up to the vocabulary you use with JSON-LD.
>> Linking between things happens with URIs, but you need a vocabulary to
>> give meaning to them. One option would be for instance be SKOS:
>> http://www.w3.org/TR/2009/NOTE-skos-primer-20090818/
>>
>> You could even use the Atom vocabulary, but with JSON-LD serialization
>> instead of XML.
>
>
> Are there any semi-standard Atom-in-JSON-LD implementations out there we
> could model on?
>
> --Larry Garfield
>

AtomOwl might be of use:
http://bblfish.net/work/atom-owl/2006-06-06/AtomOwl.html

I've been meaning to play around with that and JSON-LD to see how well
it works.  Here's some notes on a quick first try.

You can run examples through the distiller to get some idea of what it
would look like:
http://rdf.greggkellogg.net/distiller

But that output will be raw and gross.  That AtomOwl schema is cool
and uses lots of linked data.  You need a JSON-LD context to make the
data look sane.  And you need to frame the data to make it easy to
process.

If you take the example in the "AtomOwl Overview" section, run it
through the distiller to convert from turtle to JSON-LD, copy result
into the JSON-LD playground as input, and apply a frame with a context
and Feed as the root, then you can get something fairly usable.

I would post the link to the playground for this, but the URL was too long! :-)

Frame with context:
{
  "@context":{
    "owl": "http://www.w3.org/2002/07/owl#",
    "owl:sameAs": { "@type": "@id" },
    "awol": "http://bblfish.net/work/atom-owl/2006-06-06/#",
    "awol:to": { "@type": "@id" },
    "awol:author": { "@type": "@id" },
    "awol:link": { "@type": "@id" },
    "awol:id": { "@type": "http://www.w3.org/2001/XMLSchema#anyURI" },
    "awol:summary": { "@type": "@id" },
    "awol:rel": { "@type": "@id" },
    "awol:entry": { "@type": "@id", "@container": "@set"},
    "awol:title": { "@type": "@id" },
    "awol:updated": { "@type": "http://www.w3.org/2001/XMLSchema#dateTime" },
    "awol:src": { "@type": "@id" }
  },
  "@type": "awol:Feed"
}

Framed example:
{
  "@context": {
    "owl": "http://www.w3.org/2002/07/owl#",
    "owl:sameAs": { "@type": "@id" },
    "awol": "http://bblfish.net/work/atom-owl/2006-06-06/#",
    "awol:to": { "@type": "@id" },
    "awol:author": { "@type": "@id" },
    "awol:link": { "@type": "@id" },
    "awol:id": { "@type": "http://www.w3.org/2001/XMLSchema#anyURI" },
    "awol:summary": { "@type": "@id" },
    "awol:rel": { "@type": "@id" },
    "awol:entry": {
      "@type": "@id",
      "@container": "@set"
    },
    "awol:title": { "@type": "@id" },
    "awol:updated": { "@type": "http://www.w3.org/2001/XMLSchema#dateTime" },
    "awol:src": { "@type": "@id" }
  },
  "@graph": [
  {
    "@id": "_:t10",
    "@type": "awol:Feed",
    "awol:author": {
      "@id": "_:t6",
      "@type": "awol:Person",
      "awol:name": "John Doe",
      "owl:sameAs": "_:t5"
    },
    "awol:entry": [
    {
      "@id": "_:t4",
      "@type": "awol:Entry",
      "awol:author": "_:t5",
      "awol:id": "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
      "awol:link": {
        "@id": "_:t2",
        "@type": "awol:Link",
        "awol:rel": "http://www.iana.org/assignments/relation/alternate",
        "awol:to": {
          "@id": "_:t1",
          "awol:src": "http://example.org/2003/12/13/atom03"
        }
      },
      "awol:summary": {
        "@id": "_:t0",
        "@type": "awol:Content",
        "awol:body": "Some text.",
        "awol:type": "text/plain"
      },
      "awol:title": {
        "@id": "_:t3",
        "@type": "awol:Content",
        "awol:body": "Atom-Powered Robots Run Amok",
        "awol:type": "text/plain"
      },
      "awol:updated": "2003-12-13T18:30:02Z"
    }],
    "awol:id": "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6",
    "awol:link": {
      "@id": "_:t8",
      "@type": "awol:Link",
      "awol:rel": "http://www.iana.org/assignments/relation/alternate",
      "awol:to": {
        "@id": "_:t7",
        "awol:src": "http://example.org/"
      }
    },
    "awol:title": {
      "@id": "_:t9",
      "@type": "awol:Content",
      "awol:body": "Example Feed",
      "awol:type": "text/plain"
    },
    "awol:updated": "2003-12-13T18:30:02Z"
  }]
}

That was just a quick first pass and is not a complete context for the
AtomOwl schema, may not be fully correct, and is probably not the best
frame.  But it should give an idea of what is possible.  I'm not sure
how much effort is needed to convert between XML Atom and AtomOwl.

Depending on your use case, you could probably get rid of all the
awol/owl prefixes to make it more readable JSON:
   ..., "title": {
      "@id": "_:t9",
      "@type": "Content",
      "body": "Example Feed",
      "type": "text/plain"
    },
   "updated": "...",  ...

Some of the property names in AtomOwl are fairly generic so the
prefixes might be needed to not clash with, say, dc: properties.

Also note that this example uses owl:sameAs.  Processors probably need
to special case things like that to make the output easier to deal
with.  I'm not sure what the semantics of that are but maybe an
extension could just unify ids so you don't have to do manual
association of ids like _:t5 and _:t6 in the example above.

An in-memory representation would probably be even easier to manipulate as well.

Futher experimentation is needed but this looks like an interesting
way to deal with Atom data.

-dave

Received on Tuesday, 19 June 2012 22:15:02 UTC