RDFAuthor does SPARQL

Damian is working on a new version of RDFAuthor that generates SPARQL queries (instead of the older Squish notation). It can also (not sure which protocol(s)) get results from a query service. Here’s a screenshot:

Example screenshot of RDFAuthor for query authoring and result display. Nodes and arcs at top of window, tabular results at bottom

The automatically generated (and hence not 100% user-friendly) query was as follows:

      ?var_4 <http ://xmlns.filsa.net/emir/0.2/#subject> ?var_1 .
      ?var_4 <http ://xmlns.filsa.net/emir/0.2/#from> ?var_5 .
      ?var_4 <http ://xmlns.filsa.net/emir/0.2/#date> ?var_2 .
      ?var_5 <http ://xmlns.com/foaf/0.1/name> ?var_3 .
      ?var_5 <http ://xmlns.com/foaf/0.1/mbox> <mailto :pldms@mac.com> .

What does this say? Pretty much just the following:

Match where we have (in some default RDF graph) the foaf:name of any things with a foaf:mbox of mailto:pldms@mac.com,
whenever there is something that has an emir:subject and emir:date, and that is also emir:from the first thing. SELECT from that the name, subject and date.

This is based on a template graph whose structure can be seen in the screenshot, decorated with yellow variable markers where a node is marked as unknown. Actually I screwed up after the query executed and subsequently marked the mailbox node as unknown too, before taking the screenshot; if that query had been executed, the resultset would have been much larger. The target database is a Joseki service that has an RDF version of the jena-dev mail archives.

A more readable version of the query (untested) might be:

PREFIX emir: <http ://xmlns.filsa.net/emir/0.2/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?name ?date ?sub

emir:subject ?sub ;
emir:date ?date ;
foaf:name ?name;
foaf:mbox>mailto:pldms@mac.com> .

geo/photo raw materials from a walk around Bristol

I’ve just been for a walk around town, taking a few photos on the way, with the camera’s clock sync’d to that of my new GPS. I’ve not yet figured out the best tool to use (other than write my own) for hooking up the photo and location metadata. It’s easy enough to get the data off of the device using GPSBabel; for now I’ve saved tracks and waypoints in GPX format. GPSBabel offers a wealth of other options, none of which I’ve explored yet.

The first thing I had to hand that consumed GPX was Google Earth on my WinXP laptop; it plotted the tracks happily enough:

2004-07-24 walk around town, plotted via google earth

I’m sure there are other, more open-data and hackable systems out there that I can feed this data to, but for a quick test, Google Earth (formerly ‘Keyhole’) is quite fun.

For Windows users, there are WorldWind scripts that convert GPX into World Wind Layers, available as an online service. I’ve just tried that; it produced me XML document that references a PNG image. I need to read the instructions again a bit more carefully, but nice to see that there’s more to the world than Google. There are also some notes on the OpenStreetMap site on MakingGpxTracks.

The next thing I should try is getting the location and photo metadata integrated, and then I can play around with associating images on maps. There is also a growing geo-tagger community using Flickr (by creating odd ‘tags’ that embed lat/long data). For example see various of jip’s photos, and the geobloggers website (which seems to use HTTP REFERER to plot geotagged flickr images with Google maps).

Update: as I suspected, the Locative guys have already done the work :)

After CPAN-installing the Perl dependencies Image::EXIF and RDF::Simple::Serialiser, Time::Piece, LWP::UserAgent, XML::Simple, Data::Compare and Geo::Track::Log, it looks like geoloc_media.pl is just what I’m after (thanks!).

geoloc_media.pl 0 http://rdfweb.org/people/danbri/media/2005/07/ ../../mydata/2005-07-24-Tracks.gpx    danbri@foaf-project.org 2004-07-24-BristolWalk/*jpg

The resulting RDF looks about right, from a quick look.

Here’s a quick query of the data using the online Redland SPARQL service. The query I ran was as follows (basically echoing back the core data structure emitted by the perl script above):

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX locative: <http://locative.net/2004/packet#>

SELECT DISTINCT ?image, ?lat, ?long, ?email 
  ?x rdf:type locative:Packet .
  ?x locative:media ?image .
  ?x geo:lat ?lat .
  ?x geo:long ?long .
  ?image foaf:maker ?who .
  ?who foaf:mbox ?email . 

See the Locative wiki for more uses of the data, including some nice SVG hacks. Or the OpenStreetMap view of the area (seems to be bitmap imagery there but no streets etc yet).

Sample SPARQL query

PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?book ?title ?authorname
?book dc:creator ?author .
?author dc:type <http ://hoppa.com/Painters/> .
      ?author dc:title ?authorname .
      ?book dc:title ?title .

…works with rdf data describing some books by painters. I tested in Dave Beckett’s Redland-based online SPARQL demo. The query finds 5 results. Seems to have some encoding errors, but apart from that, is fine. There are more DawgShows in the ESW wiki. The sparql.org demo (using Jena) also works.

Dublin Core “RDF idiom conversion rules” in SPARQL

This note is both an earlybird (and partial) technical review of the new SPARQL RDF query spec and a proposal to the DC-Architecture Working Group for a possible representation language that captures some rules that explain how some different forms of DC relate to each other. As a review, I have to say that I now find CONSTRUCT more useful than I originally expected. Maybe a full W3C RDF Rules language would be a useful thing to do after all… :)

The Dublin Core metadata vocabulary is used sometimes as a set of relationships between documents (etc.) and other resources (entities, things); and sometimes as a set of relationships to textual strings associated with those things. The DCMI Abstract Model document gives some more detail on this, and proposes a model to explain DC thinking on this issue. Appendix B of that
document describes the mapping of this abstraction into RDF.

One option (todo: find url of Andy’s doc listing options) being explored by the DC-Architecture WG is for Dublin Core to publish explicit guidelines explaining how the two representational idioms can be interconverted. What I try to do below is capture DC community concensus about how the two styles of using properties from the http://purl.org/dc/elements/1.1/ vocabulary compare.

The rules in prose:

Rule 1: Whenever we see a DC property from http://purl.org/dc/elements/1.1/ applied to some resource ‘x’, and the value of that resource is something that is not a literal (ie. a string or markup), then any values of the rdfs:label property which apply to that thing, are also values of our DC property. eg. if a document has a dc:creator whose value is a thing that has an rdfs:label “Andy Powell”, then it is also true that the document has a dc:creator property whose value is the literal string “Andy Powell”.

Rule 2: As above, but reversed. Whenever there is some string that is an rdfs:Literal that is the value of a DC property for some resource ‘x’, then it will also be true that there exists some resource that is not an rdfs:Literal, and that has an rdfs:label whose value is that string, and that ‘x’ stands in the same DC property relationship to that resource.

Problem statement: this sort of thing is (see above) hard to express in prose, we’d like a clean machine-readable way of expressing these rules, so that test cases can be formulated, mailing list discussions can be made more precise, and (perhaps) so that software tools can directly exploit these rules to use with RDF.

The SPARQL query language is a W3C work-in-progress for querying RDF data. It mainly provides some mechanisms for specifying bits of RDF to match in some query, but also provides a basic mechanism for CONSTRUCTing further RDF statements based on combining matched data with a template structure. This is a preliminary investigation into the possibility of using SPARQL’s CONSTRUCT mechanism to express the rules being discussed in the DC community. Readers should note that both SPARQL and the DC “idiom conversion rules” are both works in progress, and that I might not have full grasp of either.

Anyway, here goes:

Rule 1 in SPARQL: generate simple form from explicit form

PREFIX dc:   <http ://purl.org/dc/elements/1.1/>
PREFIX rdfs: <http ://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http ://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT   ( ?x ?relation ?string )
WHERE       ( ?x ?relation ?thing )
            ( ?thing rdf:type x:NonLiteralResource)
            ( ?thing rdfs:label ?string)
            ( ?relation rdfs:isDefinedBy http://purl.org/dc/elements/1.1/) 

Rule 2 in SPARQL: explicit form from string form (harder)

PREFIX dc:   <http ://purl.org/dc/elements/1.1/>
PREFIX rdfs: <http ://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http ://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT   ( ?x ?relation ?thing )
            ( ?thing rdfs:label ?string)
WHERE    ( ?x ?relation ?string )
            ( ?string rdf:type rdfs:Literal)
            ( ?relation rdfs:isDefinedBy http://purl.org/dc/elements/1.1/)

See also: comments in SPARQL draft on “what if construct graph includes unbound variables”…

followup: Dan Connolly and others have noted that I should be careful not to advocate the use of SPARQL as a Rule language. I lost his specific comments due to problems with WordPress, but agree entirely. What I was trying to do here was see how it might look if one did try to express rules using these queries, to better understand how the two technologies relate. Please don’t consider SPARQL a rule language (but please do share your experiences with having RDF Rule, Query and OWL languages work together…).