<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>SPARQLBot: The Semantic Web Command Line (Scripting Challenge Submission)</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Benjamin Nowack</string-name>
          <email>bnowack@semsol.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>semsol</institution>
          ,
          <addr-line>Bielefelder Str. 5, 40468 Düsseldorf</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>SPARQLBot is an RDF-driven agent that loads structured information from the Web and reacts to user-defined questions and commands via an IRC interface. The bot is implemented using a small number of PHP scripts and ARC, an open-source PHP/MySQL-based RDF system for storage and query functionality.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Motivation</title>
      <p>SPARQLBot1 was developed during a single-day coding session to demonstrate a) the
potential of tools that support structured and linked Web data, b) the
developerfriendliness of SPARQL, and c) how very little custom code can be used to build
useful applications. It consists of three core user interface components: An
HTMLbased command editor that simplifies the definition of custom bot operations, a
longrunning process that listens to command calls on an IRC channel2, and a standard
SPARQL endpoint3 for simplified debugging of SPARQL Queries and HTTP-based
data access.</p>
    </sec>
    <sec id="sec-2">
      <title>2 Implementation</title>
      <p>SPARQLBot is built on top of two open-source toolkits. For core RDF functionality
(RDF storage, parsing, microformats extraction, querying, etc.), it uses ARC4, a
lightweight RDF toolkit written in PHP, and the user-facing applications are implemented
as Trice5 modules. Trice is a Web development framework that extends ARC with
session management, HTML forms processing, IRC access, themes, and similar
standard Web CMS functionality.
The SPARQLBot-specific code consists of only four custom PHP Classes (~25KB /
800 LOC altogether). A generic RequestHandler dispatches HTTP requests to the
three user-facing Sub-Handlers (the IRC ProcessHandler that implements the bot, a
Command Editor, and the SPARQL endpoint). Only very few commands had to be
built directly into the bot (e.g. "quit", or "smush"). As ARC supports LOAD,
INSERT, and DELETE via SPARQL, both read and write operations can be defined
using the command editor.</p>
    </sec>
    <sec id="sec-3">
      <title>3 Examples: XFN Lookups</title>
      <p>XFN6, the "Xhtml Friends Network" is a widely deployed microformat7 to specify a
person's social network in XHTML pages. SPARQLBot's RDF toolkit can convert
XFN markup to RDF triples and then make them accessible to SPARQL queries. The
code below shows the command's essential parts which can be defined using an
online form.</p>
      <sec id="sec-3-1">
        <title>Command Pattern (a regular expression):</title>
        <p>(.*)'s? (contact|friend|me)s
Triggered SPARQL Query ($i can be used for command matches):
SELECT DISTINCT ?name WHERE {
{?res foaf:nick "$1"} UNION {?res foaf:name "$1"}
?res xfn:$2 [ foaf:name ?name ] .</p>
        <p>}</p>
      </sec>
      <sec id="sec-3-2">
        <title>Result Template ($var can be used for result bindings):</title>
        <p>$nick, I found {$name, }
Example Conversation:
&lt;bengee&gt; sparqlbot, load http://twitter.com/bengee
&lt;sparqlbot&gt; 290 triples loaded in 4.9s seconds
&lt;bengee&gt; sparqlbot, smush
&lt;sparqlbot&gt; OK
&lt;bengee&gt; sparqlbot, Benjamin Nowack's contacts
&lt;sparqlbot&gt; bengee, I found Danny Ayers, Tom,
Gregory Williams, Arto Bendiken, Paul Miller, John
Breslin,Uldis Bojars, Alexandre Passant, ...</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list />
  </back>
</article>