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 mailto:jo@abduction.org
mailto:jo@abduction.org depicted in https://www.picdiary.com/xcom/IMG_1676.jpg
> read xcom
0: https://www.picdiary.com/xcom/IMG_1674.jpg
1: https://www.picdiary.com/xcom/IMG_1676.jpg
2: https://www.picdiary.com/xcom/IMG_1677.jpg
3: https://www.picdiary.com/xcom/IMG_1678.jpg
> current file
xcom
> use 0
Using pic with uri https://www.picdiary.com/xcom/IMG_1674.jpg
> current pic
https://www.picdiary.com/xcom/IMG_1674.jpg
> depicts
mailto:edd@usefulinc.com
mailto:ben@hammersley.com
> use 1
Using pic with uri https://www.picdiary.com/xcom/IMG_1676.jpg
> depicts
mailto:jo@abduction.org

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

Comments are closed.