- From: Joshua Shinavier <josh@fortytwo.net>
- Date: Thu, 10 Mar 2011 16:29:02 +0800
- To: Toby Inkster <tai@g5n.co.uk>
- Cc: public-rdf-wg@w3.org, semantic-web@w3.org
Hi Toby, On Thu, Mar 10, 2011 at 7:17 AM, Toby Inkster <tai@g5n.co.uk> wrote: > Here's a simple criterion... > [...] I like what you're trying to do, although I think the criterion as it stands is a bit *too* simple. For one thing, it's not hard trade off compactness of the client code with that of the serialization format. E.g. these 14 lines of code should do what you asked: function get_name_new(d, homepage) { var foaf = function(term) { return 'http://xmlns.com/foaf/0.1/' + term; } var s = d['ops'][homepage][foaf('homepage')]; for (var i in s) { var o = d['spo'][s[i]][foaf('name')]; for (var j in o) { if (o[j]['type'] == 'literal') { return o[j]['value']; } } } } ...provided that you're willing to put up with weird, verbose JSON like this: { 'spo' : { 'http://example.org/ns#toby' : { 'http://xmlns.com/foaf/0.1/homepage' : [{ 'value' : 'http://tobyinkster.co.uk/', 'type' : 'uri' }], 'http://xmlns.com/foaf/0.1/name' : [{ 'value' : 'toby', 'type' : 'literal' }] } }, 'ops' : { 'http://tobyinkster.co.uk/' : { 'http://xmlns.com/foaf/0.1/homepage' : [ 'http://example.org/ns#toby' ] }, 'literal toby' : { 'http://xmlns.com/foaf/0.1/name' : [ 'http://example.org/ns#toby' ] } } }; Best regards, Joshua -- Joshua Shinavier Tetherless World Constellation PhD student http://tw.rpi.edu/wiki/Joshua_Shinavier http://fortytwo.net > > 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 Thursday, 10 March 2011 08:29:37 UTC