Re: Criteria for a good JSON RDF serialisation

Hi Toby,

I'd suggest that this illustrates exactly why we should either go for a 
serialization which encourages using RDF tooling, or stick to simple 
objects, and /not/ do anything in the middle.

In the "RDF in JSON" case, well you'd just use the SPARQL query.

In the plain old data objects case, well you can do it as such:

   d = [
    { name: "nathan", homepage: "http://webr3.org/" },
    { name: "toby", homepage: "http://tobyinkster.co.uk/" }
   ];

   function get_name(d,homepage) {
    return d.filter( function(o) { return o.homepage == homepage 
}).pop().name;
   }

   get_name(d, "http://webr3.org");

That would be 1-3 lines, depending on how verbose you were.

Thanks for illustrating the point I've been trying to make [1,2] so 
clearly :)

Best,

Nathan

[1] http://lists.w3.org/Archives/Public/public-rdf-wg/2011Mar/0336.html
[2] http://lists.w3.org/Archives/Public/public-rdf-wg/2011Mar/0334.html

Toby Inkster wrote:
> 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.
> 

Received on Thursday, 10 March 2011 00:59:16 UTC