=Paper= {{Paper |id=None |storemode=property |title=Posh - The Prolog OWL Shell |pdfUrl=https://ceur-ws.org/Vol-796/owled2011_submission_15.pdf |volume=Vol-796 |dblpUrl=https://dblp.org/rec/conf/owled/Mungall11 }} ==Posh - The Prolog OWL Shell== https://ceur-ws.org/Vol-796/owled2011_submission_15.pdf
               Posh - The Prolog OWL Shell

                                   Chris Mungall



      Abstract. Two of the most common ways of processing and manip-
      ulating 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 read-
      eval-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


1   Motivation

Powerful and feature-rich java libraries such as Jena and the OWLAPI[3] pro-
vide 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.
   Posh is a simple wrapper for the Thea library[11], 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.


2   Posh: The Prolog OWL Shell

The best way to describe Posh is by example. The following example command
initiates Posh with java enabled and the fruitfly anatomy ontology[6] loaded into
memory:

thea-poshj http://purl.obolibrary.org/obo/fbbt.owl

   This puts the user into an enhanced prolog REPL shell with provides ex-
pected features such as readline support and history.
   A little knowledge of prolog syntax helps - variables are indicated by a lead-
ing upper case character or underscore, and queries are terminated by a “.”.
Posh makes use of prolog’s infix operators to define a Manchester Syntax[4]-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 en-
tity, v to visualize a graph focused on an entity, and q for performing a structural
query on asserted axioms.
    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 < connected_to some Y.
   The < 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 < connected_to some ’antennal lobe’.
’cortex of antennal lobe’ has_part some part_of some Y.
   (any OWL expression can be used here, arbitrary levels deep).
   The same thing can be done using the powerful visitor pattern in the OWL
API, albeit at the cost of more lines of code.
   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.
   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 ex-
ample, 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.
      This can then be consulted and used in the following POPL directive:
add X==Y where shares_stemmd_label(X,Y).


3      Pathologically Obfuscated Semantic Hacking
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[8] 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.
    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[2] and LSW2 (LSW also allows scripting from with Protege 4). Never-
theless, 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/
    In the spirit of what was once the hacking language of choice for bioinformati-
cians, 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     Conclusions
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.


References
 1. M. Egana, A. Rector, R. Stevens, and E. Antezana. Applying Ontology Design
    Patterns in Bio-ontologies. In proceedings of EKAW, volume 2008. Springer, 2008.
 2. R. Hoehndorf, M. Dumontier, A. Oellrich, S. Wimalaratne, D. Rebholz-
    Schuhmann, P. Schofield, and G.V. Gkoutos. A common layer of interoperability
    for biomedical ontologies based on OWL EL. Bioinformatics, 2011.
 3. M. Horridge. The OWL API: A Java API for Working with OWL 2 Ontologies.
    In 6th OWL Experiences and Directions Workshop (OWLED 2009), 2009.
 4. M. Horridge, N. Drummond, J. Goodwin, A. Rector, R. Stevens, and H.H. Wang.
    The manchester owl syntax. OWL: Experiences and Directions, pages 10–11, 2006.
 5. Thorsten Liebig, Marko Luther, Olaf Noppens, Mariano Rodriguez, Diego Cal-
    vanese, Michael Wessel, Matthew Horridge, Sean Bechhofer, Dmitry Tsarkov, and
    Evren Sirin. OWLlink: DIG for OWL 2. In 5th OWL Experiences and Directions
    Workshop (OWLED 2008), 2008.
 6. D.J. Osumi-Sutherland, M. Longair, and J.D. Armstrong. Virtual Fly Brain: An
    ontology-linked schema of the Drosophila Brain. 2009.
 7. R. Shearer, B. Motik, and I. Horrocks. HermiT: A Highly-Efficient OWL Rea-
    soner. In Proceedings of the 5th International Workshop on OWL: Experiences
    and Directions (OWLED 2008), 2008.
 8. E. Sirin and B. Parsia. Sparql-dl: Sparql query for owl-dl. In 3rd OWL Experiences
    and Directions Workshop (OWLED-2007), volume 4. Citeseer, 2007.
 9. E. Sirin, B. Parsia, B.C. Grau, A. Kalyanpur, and Y. Katz. Pellet: A practical
    owl-dl reasoner. Web Semantics: science, services and agents on the World Wide
    Web, 5(2):51–53, 2007.
10. D. Tsarkov and I. Horrocks. FaCT++ description logic reasoner: System descrip-
    tion. Lecture Notes in Computer Science, 4130:292, 2006.
11. Vangelis Vassiliadis, Jan Wielemaker, and Chris Mungall. Processing OWL2 on-
    tologies using Thea: An application of logic programming. In 6th OWL Experiences
    and Directions Workshop (OWLED 2009), 2009.
12. J. Wielemaker. An overview of the SWI-Prolog programming environment. In 13th
    International Workshop on Logic Programming Environments, pages 1–16, 2003.

3
    whose alternative acronym is “Pathologically Eclectic Rubbish Lister”
4
    http://github.com/vangelisv/thea