Re: @context vs. Turtle @prefix

On Sep 6, 2013, at 12:19 AM, Adrian Gschwend <ml-ktk@netlabs.org> wrote:

> Hi group,
> 
> (repost, didn't make it trough the queue last night it seems)
> 
> I'm working on a Pubby-like basic LDP frontend which so far can return
> classical RDF representations of URIs, like text/turtle,
> application/rdf+json etc.
> 
> To convince web developers to use it I would like to introduce json-ld
> as well. My goal is to have something like a well prefixed turtle
> representation but in json-ld. This means that I want to see as few URIs
> as absolutely necessary for the predicates itself.
> 
> The prefixed sample turtle output looks like this
> 
> http://ktk.netlabs.org/misc/12099-shrink.ttl
> 
> With the help of http://rdf-translator.appspot.com/ I managed to get a
> basic json-ld version of this:
> 
> http://ktk.netlabs.org/misc/12099.jsonld
> 
> I do see that it did compact some things compared to the
> application/rdf+json output. But I guess it's not "sexy" enough yet so
> that a web developer would be able to use it without big issues.

The key is in using the proper context when compacting. My own RDF Writer interface to JSON-LD, takes the prefixes found on input and uses them to automatically generate a context for the JSON-LD output. You can see it in operation at <http://rdf.greggkellogg.net/distiller?format=jsonld&in_fmt=turtle&uri=http://ktk.netlabs.org/misc/12099-shrink.ttl>, although note that my service has been flaky lately due to something else which is eating up memory on my VPS. It basically gives you what I think you want:

{
  "@context": {
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "dac": "http://data.admin.ch/vocab/",
    "dbp": "http://dbpedia.org/property/",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "geo": "http://www.w3.org/2003/01/geo/wgs84_pos#",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "dbo": "http://dbpedia.org/ontology/",
    "dbpedia": "http://dbpedia.org/resource/",
    "owl": "http://www.w3.org/2002/07/owl#"
  },
  "@id": "http://data.admin.ch/bfs/municipality/12099",
  "@type": "dac:Municipality",
  "dac:canton": {
    "@id": "http://data.admin.ch/bfs/canton/GE"
  },
  "dac:cantonAbbreviation": "GE",
  "dac:district": {
    "@id": "http://data.admin.ch/bfs/district/10187"
  },
  "dac:districtHistId": 10187,
  "dac:historyMunicipalityId": 12099,
  "dac:municipalityAdmissionDate": {
    "@value": "1960-01-01",
    "@type": "xsd:date"
  },
  "dac:municipalityAdmissionMode": 20,
  "dac:municipalityAdmissionNumber": 1000,
  "dac:municipalityDateOfChange": {
    "@value": "1960-01-01",
    "@type": "xsd:date"
  },
  "dac:municipalityEntryMode": 11,
  "dac:municipalityId": 6621,
  "dac:municipalityLongName": "Genève",
  "dac:municipalityShortName": "Genève",
  "dac:municipalityStatus": 1,
  "dac:neighboringMunicipality": [
    {
      "@id": "http://data.admin.ch/bfs/municipality/10902"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/10918"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/11400"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/11431"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/11599"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/12606"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/12624"
    },
    {
      "@id": "http://data.admin.ch/bfs/municipality/13110"
    }
  ],
  "dbo:abstract": {
    "@value": "Genf ist eine politische Gemeinde und der Hauptort des Kantons Genf in der Schweiz. Genf ist mit seinen rund 192'000 Einwohnern nach Zürich die zweitgrösste Stadt der Schweiz. Mit 46,8 Prozent Ausländern zählt Genf, neben Leysin (61,7 Prozent) und Kreuzlingen (50,0 Prozent), zu den Städten mit hohem Ausländeranteil. Die Stadt liegt am südwestlichen Rand der französischsprachigen Schweiz (Romandie) am Ausfluss der Rhone aus dem Genfersee. Die Stadt Genf ist Sitz vieler internationaler Organisationen, darunter UNO, CERN, IKRK, WHO, IAO, ISO, ITU, WIPO, WMO, WOSM, WTO und UNHCR. Zudem ist Genf nach Zürich der zweitgrösste Finanzplatz der Schweiz, gefolgt von Lugano. Seit Jahren wird Genf neben Zürich als eine der Städte mit den teuersten Lebenshaltungskosten und mit höchster Lebensqualität weltweit gelistet. Seit 2012 gilt Genf als drittteuerste Stadt der Welt, hinter Zürich und Tokio. Genf Klimadiagramm JFMAMJJASOND     69  4 -2     70  6 -1     68  10 1     56  14 4     66  18 8     77  22 11     58  25 13     68  24 13     70  21 10     66  15 7     79  8 2     75  5 -1 Temperatur in °C,  Niederschlag in mmQuelle: Weltorganisation für Meteorologie Monatliche Durchschnittstemperaturen und -niederschläge für Genf Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez Max. Temperatur 3,7 5,9 9,8 13,9 18,4 22,2 25,3 24,4 20,8 14,9 8,4 4,5 Ø 14,4 Min. Temperatur (°C) -1,9 -0,9 0,8 4,1 8,0 11,3 13,3 13,0 10,3 6,6 2,1 -0,5 Ø 5,5 Niederschlag 69 70 68 56 66 77 58 68 70 66 79 75 Σ 822 Regentage 10 9 10 9 11 10 8 9 8 8 10 10 Σ 112 Temperatur 3,7 -1,9 5,9 -0,9 9,8 0,8 13,9 4,1 18,4 8,0 22,2 11,3 25,3 13,3 24,4 13,0 20,8 10,3 14,9 6,6 8,4 2,1 4,5 -0,5 Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez Niederschlag 69 70 68 56 66 77 58 68 70 66 79 75   Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez Quelle: Weltorganisation für Meteorologie",
    "@language": "de"
  },
  "dbo:thumbnail": {
    "@id": "http://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Views_of_Geneva.jpg/200px-Views_of_Geneva.jpg"
  },
  "dbp:imagepathCoa": {
    "@value": "Wappen Genf matt.svg",
    "@language": "en"
  },
  "dbp:map": {
    "@value": "Karte Kanton Genf.png",
    "@language": "en"
  },
  "dbp:neighboringMunicipalities": [
    {
      "@id": "dbpedia:Carouge"
    },
    {
      "@id": "dbpedia:Ch%C3%AAne-Bougeries"
    },
    {
      "@id": "dbpedia:Cologny"
    },
    {
      "@id": "dbpedia:Grand-Saconnex"
    },
    {
      "@id": "dbpedia:Lancy"
    },
    {
      "@id": "dbpedia:Pregny-Chamb%C3%A9sy"
    },
    {
      "@id": "dbpedia:Vernier,_Switzerland"
    },
    {
      "@id": "dbpedia:Veyrier"
    }
  ],
  "foaf:depiction": {
    "@id": "http://upload.wikimedia.org/wikipedia/commons/e/e6/Views_of_Geneva.jpg"
  },
  "foaf:homepage": {
    "@id": "http://www.ville-ge.ch/index_e.htm"
  },
  "geo:lat": {
    "@value": "46.2",
    "@type": "xsd:float"
  },
  "geo:long": {
    "@value": "6.15",
    "@type": "xsd:float"
  },
  "owl:sameAs": {
    "@id": "dbpedia:Geneva"
  }
}

You could also hand-build a context and use that for compaction.

Gregg

> In the samples on the homepage I found the compacted versions, the node
> demo did a nice sample on the payswarm URI. But after having a look at
> the specs I fail to understand if this really provides what I would like
> to have:
> 
> - can I get JSON-LD in the style of the prefixed turtle output which
> gets rid of the URIs?
> - in the samples I found mostly one URI in @context, can I have multiple
> shortcuts in a way like multiple @prefix in turtle?
> - How do I get a compacted sample with the commandline node tools from
> my basic JSON-LD version? I tried this:
> 
> ../jsonld.js/bin/jsonld compact -c
> "http://data.admin.ch/bfs/municipality/" 12099.jsonld

You can use the ruby tools (gem install linkeddata) using the following:

rdf serialize http://ktk.netlabs.org/misc/12099-shrink.ttl --output-format jsonld

Gregg

> jsonld.CompactError: Could not process context before compaction.
> 
> thanks
> 
> regards
> 
> Adrian
> 
> 

Received on Friday, 6 September 2013 17:43:28 UTC