<!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>Posh - The Prolog OWL Shell</article-title>
      </title-group>
      <abstract>
        <p>Two of the most common ways of processing and manipulating OWL ontologies are through an ontology editing environment (e.g. Protege or TopBraid) or via a programmatic interface, such as the OWL API. A complementary method is to use an OWL-aware command line shell. Posh, the Prolog OWL Shell is an interactive toplevel readeval-print-loop interface that provides powerful capabilities for querying and transforming ontologies. It includes a bridge to the OWLAPI and to multiple OWL reasoners, and allows a mixture of closed-world rule-based querying on top of open world reasoning. It also provides an interface to POPL, the Prolog Ontology Processing Language. Posh is available from http://blipkit.wordpress.com/posh</p>
      </abstract>
      <kwd-group>
        <kwd>The best way to describe Posh is by example</kwd>
        <kwd>The following example command initiates Posh with java enabled and the fruitfly anatomy ontology[6] loaded into memory</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Motivation</title>
      <p>
        Powerful and feature-rich java libraries such as Jena and the OWLAPI[
        <xref ref-type="bibr" rid="ref13 ref3">3</xref>
        ]
provide a means of developing infrastructure and applications that leverage OWL
technology. However, these libraries are not always appropriate for lightweight
exploratory programming, scripting or hacking purposes.
      </p>
      <p>
        Posh is a simple wrapper for the Thea library[
        <xref ref-type="bibr" rid="ref11">11</xref>
        ], a prolog environment for
OWL ontologies. Posh extends Thea with convenient commands designed to be
used in a REPL (Read-Eval-Print Loop), and opens up some the capabilities of
Thea for non-Prolog programmers.
      </p>
      <p>This puts the user into an enhanced prolog REPL shell with provides
expected features such as readline support and history.</p>
      <p>
        A little knowledge of prolog syntax helps - variables are indicated by a
leading upper case character or underscore, and queries are terminated by a “.”.
Posh makes use of prolog’s infix operators to define a Manchester Syntax[
        <xref ref-type="bibr" rid="ref14 ref4">4</xref>
        ]-like
Domain Specific Language with quasi-DL style symbols. You can type arbitrary
prolog goals during a posh session, but posh also provides a number of top-level
convenience commands, such as l to list all axioms associated with a named
entity, v to visualize a graph focused on an entity, and q for performing a structural
query on asserted axioms.
      </p>
      <p>The following query finds all subclass axioms whose second argument is an
existential restriction using the connected to property (in other words, it finds
the connected parts of a fly):
?- q X &lt; connected_to some Y.</p>
      <p>The &lt; operator is shorthand for SubClassOf (posh favors brevity at the
possible expense of obfuscation). We can query more specifically for all asserted
connections to the antennal lobe, getting back a singe axiom as an answer:
?- q X &lt; connected_to some ’antennal lobe’.
’cortex of antennal lobe’&lt;connected_to some ’antennal lobe’.</p>
      <p>This illustrates a useful configurable feature whereby labels in queries are
substituted for the corresponding IRI; this is very handy for bio-ontologies where
the convention is to use numeric IDs.</p>
      <p>A standard SELECT-WHERE type construct is also supported:
?- q X where X &lt; connected_to some ’antennal lobe’.
’cortex of antennal lobe’.
2.1</p>
      <sec id="sec-1-1">
        <title>Reasoner Integration</title>
        <p>
          Posh comes bundled with jars for Pellet[
          <xref ref-type="bibr" rid="ref9">9</xref>
          ], HermiT[
          <xref ref-type="bibr" rid="ref7">7</xref>
          ] and FaCT++[
          <xref ref-type="bibr" rid="ref10">10</xref>
          ], as well
as an OWLLink client library[
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] and an experimental OWL2-RL reasoner
implemented in prolog (Vassiladis, unpublished). The init command can be used to
fire up a reasoner, reasoner queries are embedded in curly braces. At this point
we introduce another feature, the ability to feed in arbitrary prolog goals to
constrain which axioms are passed on to the reasoner (for example, to optimize
reasoner behavior[
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]):
?- init pellet with [
filter(A,(A\=annotationProperty(_),
        </p>
        <p>A\=annotationAssertion(_,_,_)))].
?- q {X &lt; connected_to some ’antennal lobe’}.</p>
        <p>Annotations are not given to the reasoner, and after initialization the reasoner
is queried for the contents of the curly braces. Closed-world prolog queries can be
freely mixed with open-world reasoner queries. We can use the prolog
negationas-failure operator to find all neuron classes that are not known to be restricted
to the head:
?- q X where {X &lt; neuron},\+{X &lt; part_of some head}.</p>
        <p>
          Users can write their own prolog predicates and mix these in with their
queries, or they can take advantage of powerful SWI-Prolog library[
          <xref ref-type="bibr" rid="ref12">12</xref>
          ] queries,
such as those for spatial queries, NLP or relational database access.
2.2
        </p>
      </sec>
      <sec id="sec-1-2">
        <title>POPL : Prolog Ontology Processing Language</title>
        <p>
          Posh also makes use of a new extension of Thea called the Prolog Ontology
Process Language. This is similar to OPPL2[
          <xref ref-type="bibr" rid="ref1">1</xref>
          ], but offers additional features as
well as the full expressive power of prolog.
        </p>
        <p>POPL directives can be issued directly from within an interactive Posh
session. For exampe, the following command will rewrite all overlaps
SomeValuesFrom expressions to use a nested class expression:
overlaps some Y ===&gt; has_part some part_of some Y.</p>
        <p>(any OWL expression can be used here, arbitrary levels deep).</p>
        <p>The same thing can be done using the powerful visitor pattern in the OWL
API, albeit at the cost of more lines of code.</p>
        <p>The following example adds equivalence axioms wherever two classes have
the same label:
add X==Y where X label N, Y label N, X\=Y.</p>
        <p>Here the predicate label/2 is a convenience wrapper for rdfs:label triples. We
are not restricted to built-in predicates, and can easily define our own. For
example, if we wanted to add equivalence axioms for all class pairs whose stemmed
labels match, we can define a predicate using the porter stem predicate from the
SWI prolog NLP library:
stemmed_label(X,N) :- X label N1, porter_stem(N1,N).
shares_stemmed_label(X,Y) :- stemmed_label(X,N),stemmed_label(Y,N),X\=Y.</p>
        <p>This can then be consulted and used in the following POPL directive:
add X==Y where shares_stemmd_label(X,Y).
3</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Pathologically Obfuscated Semantic Hacking</title>
      <p>
        Posh occupies something of a niche in the ecosystem of OWL tooling. Upstanding
software engineers are likely to favour solid java APIs, and ontology power users
can make use of an increasing number of plugins for their ontology development
environment of choice. In particular, the new SPARQL-DL[
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] extension for the
OWL API1 removes many of the limitations of pure DL queries (e.g. use of
annotations in queries, closed-world negation), and consequently some of the
comparative advantages of hybrid prolog-reasoner querying.
      </p>
      <p>
        Furthermore, REPLs to the java OWL API are available in a number of
scripting languages from Groovy to Lisp, exemplified in toolkits such as El
Vira[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and LSW2 (LSW also allows scripting from with Protege 4).
Nevertheless, there are many advantages to a pure prolog/Thea based environment,
such as the ability to manipulate OWL constructs directly in the host language.
1 http://www.derivo.de/en/resources/sparql-dl-api/
2 http://svn.mumble.net:8080/svn/lsw/trunk/
      </p>
      <p>In the spirit of what was once the hacking language of choice for
bioinformaticians, Perl3, an alternative acronym for Posh is the “Pathologically Obfuscated
Semantic Hacker”. Posh aims to fill a similar niche, allowing powerful ontology
operations to be scripted quickly and easily.
4</p>
    </sec>
    <sec id="sec-3">
      <title>Conclusions</title>
      <p>Posh is a powerful and somewhat ad-hoc shell that allows prolog, OWL reasoning
and unix operations to be mashed up interactively on the command line. It is
available as part of the Thea library4, but to obtain the latest version please see
the main Posh page (http://blipkit.wordpress.com/posh/) which also includes a
collection of examples and a companion guide to the examples in this note.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>M.</given-names>
            <surname>Egana</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Rector</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Stevens</surname>
          </string-name>
          , and
          <string-name>
            <given-names>E.</given-names>
            <surname>Antezana</surname>
          </string-name>
          .
          <article-title>Applying Ontology Design Patterns in Bio-ontologies</article-title>
          .
          <source>In proceedings of EKAW</source>
          , volume
          <year>2008</year>
          . Springer,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>R.</given-names>
            <surname>Hoehndorf</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Dumontier</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Oellrich</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Wimalaratne</surname>
          </string-name>
          , D. RebholzSchuhmann, P. Schofield, and
          <string-name>
            <given-names>G.V.</given-names>
            <surname>Gkoutos</surname>
          </string-name>
          .
          <article-title>A common layer of interoperability for biomedical ontologies based on OWL EL</article-title>
          . Bioinformatics,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>M.</given-names>
            <surname>Horridge</surname>
          </string-name>
          .
          <article-title>The OWL API: A Java API for Working with OWL 2 Ontologies</article-title>
          .
          <source>In 6th OWL Experiences and Directions Workshop (OWLED</source>
          <year>2009</year>
          ),
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>M.</given-names>
            <surname>Horridge</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Drummond</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Goodwin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Rector</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Stevens</surname>
          </string-name>
          , and
          <string-name>
            <given-names>H.H.</given-names>
            <surname>Wang</surname>
          </string-name>
          .
          <article-title>The manchester owl syntax</article-title>
          .
          <source>OWL: Experiences and Directions</source>
          , pages
          <fpage>10</fpage>
          -
          <lpage>11</lpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Thorsten</given-names>
            <surname>Liebig</surname>
          </string-name>
          , Marko Luther, Olaf Noppens, Mariano Rodriguez, Diego Calvanese, Michael Wessel, Matthew Horridge, Sean Bechhofer, Dmitry Tsarkov, and Evren Sirin.
          <article-title>OWLlink: DIG for OWL 2</article-title>
          .
          <source>In 5th OWL Experiences and Directions Workshop (OWLED</source>
          <year>2008</year>
          ),
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>D.J.</given-names>
            <surname>Osumi-Sutherland</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Longair</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.D.</given-names>
            <surname>Armstrong</surname>
          </string-name>
          .
          <article-title>Virtual Fly Brain: An ontology-linked schema of the Drosophila Brain</article-title>
          .
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>R.</given-names>
            <surname>Shearer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Motik</surname>
          </string-name>
          ,
          <string-name>
            <surname>and I. Horrocks.</surname>
          </string-name>
          <article-title>HermiT: A Highly-Efficient OWL Reasoner</article-title>
          .
          <source>In Proceedings of the 5th International Workshop on OWL: Experiences and Directions (OWLED</source>
          <year>2008</year>
          ),
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>E.</given-names>
            <surname>Sirin</surname>
          </string-name>
          and
          <string-name>
            <given-names>B.</given-names>
            <surname>Parsia</surname>
          </string-name>
          .
          <article-title>Sparql-dl: Sparql query for owl-dl</article-title>
          .
          <source>In 3rd OWL Experiences and Directions Workshop (OWLED-2007)</source>
          , volume
          <volume>4</volume>
          .
          <string-name>
            <surname>Citeseer</surname>
          </string-name>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>E.</given-names>
            <surname>Sirin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Parsia</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.C.</given-names>
            <surname>Grau</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kalyanpur</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Y.</given-names>
            <surname>Katz. Pellet</surname>
          </string-name>
          :
          <article-title>A practical owl-dl reasoner</article-title>
          .
          <source>Web Semantics: science, services and agents on the World Wide Web</source>
          ,
          <volume>5</volume>
          (
          <issue>2</issue>
          ):
          <fpage>51</fpage>
          -
          <lpage>53</lpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>D.</given-names>
            <surname>Tsarkov</surname>
          </string-name>
          and
          <string-name>
            <surname>I. Horrocks.</surname>
          </string-name>
          <article-title>FaCT++ description logic reasoner: System description</article-title>
          .
          <source>Lecture Notes in Computer Science</source>
          ,
          <volume>4130</volume>
          :
          <fpage>292</fpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Vangelis</surname>
            <given-names>Vassiliadis</given-names>
          </string-name>
          , Jan Wielemaker, and
          <string-name>
            <given-names>Chris</given-names>
            <surname>Mungall</surname>
          </string-name>
          .
          <article-title>Processing OWL2 ontologies using Thea: An application of logic programming</article-title>
          .
          <source>In 6th OWL Experiences and Directions Workshop (OWLED</source>
          <year>2009</year>
          ),
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <given-names>J.</given-names>
            <surname>Wielemaker</surname>
          </string-name>
          .
          <article-title>An overview of the SWI-Prolog programming environment</article-title>
          .
          <source>In 13th International Workshop on Logic Programming Environments</source>
          , pages
          <fpage>1</fpage>
          -
          <lpage>16</lpage>
          ,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          <article-title>3 whose alternative acronym is “Pathologically Eclectic Rubbish Lister”</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>4 http://github.com/vangelisv/thea</mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>