Photo-annotating bot

January 9th, 2003  |  Published in bots, java, photos, rdf, rest

A background project for a while has been to write a bot to help me annotate the fairly large number of pictures I post to picdiary (1496 at the last count). Creating a document of RSS-based metadata is a slightly cumbersome text-editor job every time I post a new set of pics.

After much thought, coding and discussion over the summer with #bots people, I came to the conclusion that a good architectural style for bots is, as jo puts it, “a stateful conversational interface to an aspect of the semantic web”. Querying and updating information is modeled by HTTP GET and POST respectively. The code is structured after the Model-View-Controller pattern commonly used in GUI development: the View is a represention over IRC or another messaging system, the Controller responds to messages generated by running a grammar-based parser over the user’s input, and the Model lives on the web. The bot only keeps state relevant to the conversation (e.g. which picture we are currently talking about).

To get the bot up and running, I started by creating a GET-able query system based on jena. It has a nice RDF query language that’s somewhat SQLish, and can use berkeleydb and rdbms backends. I modeled a store of queries in RDF and wrote a java servlet to run queries and return results in naive XML or RDF formats.

With this flexible backend, I was able to write a commandline version of a bot using simple HTTP requests and the Jakarta Digester to extract information from the XML. Adding a new feature is mostly a case of augmenting the parser’s grammar and adding a new query to the query store.

Here’s a sample session with the commandline version of the bot:

> find depicted in
> read xcom
> current file
> use 0
Using pic with uri
> current pic
> depicts
> use 1
Using pic with uri
> depicts

The next step is to extend the query system to allow updates and creates, and I’ll be nearly done.

Comments are closed.