Subscribe

Archive for the 'Ideas and Experiments' Category

Which Store to SPARQL?

We’ve got quite a lot of different stores in the Talis Platfom, some of which have some pretty interesting data. The question is, what’s in them? A while ago, I polled all the stores in the platform (you can get a list as HTML or RDF at http://api.talis.com/stores) for some basic stats on the rdf:types and predicates in each store, and saved them in the silkworm-dev store.

It just occurred to me that, using (for example), ARC’s standalone SPARQL parser, I ought to be able to parse a query, and generate another query for the silkworm-dev store, to find a list of stores that you could run that query on and get some data back.

I guess this will get even more interesting when we add Store Groups into the mix (a coming-feature, where you can query a group of stores at once).

I’ll have to try it sometime soon :)

Client-side Sem Web Apps

In my last post, I said, a little tentatively, that it should be possible to build entirely client-side semweb applications using the Convert service. I was tentative because it seemed like it ought to work, but I hadn’t actually tried it.

So I tried it, and yes, it works! :)

Yesterday, I put together a widget that adds comments functionality to any page, or page section. Just add this markup to the section you want to have comments on:

<div class="sioc-has_reply"></div>
<script type="text/javascript"
charset="utf-8"
src="http://n2.talis.com/svn/playground/kwijibo/javascript/sioc-comments/bundle.js">
</script>

Ok caveat – I only wrote it yesterday afternoon, it worked for me, on my macbook, but haven’t tested it on IE of any flavour, and tuukah, in #sioc (who was kind enough to try it for me) had problems with firefox on linux.

Anyway, what it does is this: You add the markup, and the page gets a comments form, with fields for your URI, and your comment. When you type in your URI and move to the next field, it will try to dereference your URI and retrieve your foaf:name.
When you submit the form, it will save your comment as RDF to a platform store. The comment will be retrieved from the platform, and displayed on the page. Next to your name in the comments list, is a button called ‘Activity’, which will retrieve a list of all the other posts you have commented on using the widget – these could be anywhere on the web.

I put up a test page you can try it out on.

Now admittedly, it doesn’t look very pretty (assuming you get it to work), and some blatently lacking features are some kind of identity authentication process, and a way for page owners to remove spammers and trolls from their comments. These would take a little bit of custom server-side code to implement.

That asides, as a proof of concept, I think it’s pretty cool (if I do say so myself!) – it takes an existing style of application (a js comments widget), and shows that by adding a URI, you get all kinds of other possibilities. You could have another widget that analysed the FOAF profile’s of the commenters through their URIs, and visualised how incestuous your readership is (eg: do they all know each other? do they all comment on the same blogs?).

It also provokes all kinds of other interesting ideas – there are lots of other sorts of widgets that could take this idea of user input distributed across the web, and working locally on their own pages, but using the network to build up a value greater than the sum of its parts. And here, RDFa starts to look like a good way of exposing the retrieved RDF in HTML for the browser to potentially do more stuff with. Perhaps not just exposing the RDF, but also the SPARQL endpoint it pulls it from.

Editing the Web of Data

Another feature of the experimental Convert service is the ability to pull RDF (extracted from RDF/XML, turtle, RDF/JSON, and HTML) into an editing interface – either form fields, or editing free text as Turtle, edit the data, transform it (options include describing the edit as a ChangeSet, reifying, or dereifying the data), convert it, and POST or PUT the results to any URI.

This might not seem so exciting if you are already quite happy doing this on the commandline with Vim and cURL, but what is potentially interesting about it is the syntax used in the name attributes of the form widgets to roundtrip the data from the web, through the HTML forms ( you can read about the forms syntax on the n2 wiki ).

Javascript and JSONP

What this means, is that the Convert service can be used as a proxy for purely client side javascript applications. You can retrieve RDF data form anywhere on the web by requesting a JSONP conversion of it from the service.

JSONP

The JSONP service allows you to specify a callback function, and it will return the data wrapped in a call to that function.

So you define a function called ,eg, my_callback which accepts the json data object as the first parameter, and then create a script tag pointing to the JSON data, with a url parameter of callback=my_callback. The browser will then load the remote javascript into your page, which will call your my_callback function, passing it the data you requested.

RDF in HTML forms

You can then load the data into HTML form widgets, using the same forms syntax as the Convert service’s editor page for the @name attribute, and point the @action attribute of the form at the Convert service. Pass in the appropriate form values describing how you want the data transformed and converted, and where you want to POST or PUT it to. Then when the form is submitted, the POST array will be transformed and converted into the format you chose, and forwarded on to the URI you chose.

The upshot of which, I think, is that you can write pure client-side applications that read, write, and edit data across the web.

It’s kind of like that formmail.pl script, for RDF ;)

Experimental Convert Service

Lately I’ve been working on an experimental Convert service. The idea is much like dajobe’s triplr or Simile’s babel – accept a variety of semantic formats as input, and make them available in other flavours as output.

RDF -> RDF

The service accepts HTML (preferrably with eRDF, RDF, or microformats), RDF/XML, turtle, or RDF/JSON as input, outputting to a variety of RDF serialisations. For the parsing of most of these RDF formats, the service uses Benjamin Nowack’s excellent ARC library for PHP.

SPARQL/XML and Facet/XML

The service also accepts SPARQL/XML and the XML from the Talis Platform Facet service, transforming to either JSON, JSONP, or HTML.

Doing the conversions is a PHP library, available in the n2 SVN repository