Criteria for a good JSON RDF serialisation

Here's a simple criterion...

Let's assume we have a serialisation 's' and an object 'd' that has
been parsed using a standard JSON parser with no special RDF knowledge,
so it's just a structure of arrays and objects.

Now, write a function get_name(o, homepage) which, given 'd' as its
input data and a foaf:homepage URI, returns the foaf:name for the owner
of the homepage. (The function is not required to perform any RDFS/OWL
inference.)

i.e. it is asked to perform the equivalent of:

	PREFIX foaf: <http://xmlns.com/foaf/0.1/>
	SELECT ?name
	WHERE {
		GRAPH ?d {
			?person foaf:homepage ?homepage
				foaf:name ?name .
		}
		FILTER(is_iri(?homepage) && is_literal(?name))
	}
	LIMIT 1

Use Javascript, pseudo-code or whatever.

Here's my example for Talis' RDF/JSON:

	function get_name (d, homepage)
	{
	  var foaf = function (term)
	    { return 'http://xmlns.com/foaf/0.1/' + term; }
	  for (var s in d) {
	    var matches_homepage = false;
	    if (d[s][foaf('homepage')]) {
	      for (var i in d[s][foaf('homepage')]) {
	        o = d[s][foaf('homepage')][i];
	        if (o['value']==homepage && o['type']=='uri') {
	          matches_homepage = true;
	        }
              }
            }
	    if (matches_homepage && d[s][foaf('name')]) {
	      for (var i in d[s][foaf('name')]) {
	        o = d[s][foaf('name')][i];
	        if (o['type']=='literal') {
	          return o['value'];
	        }
	      }
	    }
	  }
	}

24 lines. I think that line count is a good measure of the quality of
the serialisation. (Low line counts being good.)

The challenge for people proposing supposedly friendly JSON
serialisations with features like CURIEs, arbitrarily nested objects,
heuristics, etc is to beat that line count.

-- 
Toby A Inkster
<mailto:mail@tobyinkster.co.uk>
<http://tobyinkster.co.uk>

Received on Wednesday, 9 March 2011 23:17:04 UTC