Category Archives: semantic web

Prolog OWL Shell at OWLED 2011

My slides and paper for POSH are now online:

Manuscript: owled2011_submission_15.pdf

Slides: POSH (slideshare)

Support for OWLAPIv3 in Thea2

Thea2 now wraps OWLAPI v3. Support is provided for pellet and hermit out of the box.

There is now also additional command line support.

  • download and install SWI-Prolog
  • download Thea2 (for now you have to git clone and get the owlapi3 branch)
  • Add Thea2 to your path:

(assuming you install in ~/thea2)

export PATH="$PATH:$HOME/thea2"

You can then use the thea-jpl script, which takes care of JPL setup, adding the owlapiv3 jars to your classpath etc:

e.g.

thea-jpl testfiles/pizza.owl --reasoner pellet --reasoner-ask-all

shows all inferred axioms

For more examples, see Cookbook.txt

Advertisement

Thea paper accepted for OWLED2009

Provisional version of the paper up on:

(new) Thea website

(pending reivisions)

Translating between logic programs and OWL/SWRL

Using the Thea2 library, it’ possible to translate certain OWL-DL ontologies into logic programs, and then query over them using LP systems such as Yap or XSB. Only the DLP subset is translated, and care must be taken to avoid common pitfalls.

It’s now also possible to do the reverse translation for a similar subset of LP programs. For example, if we have a file uncle.pl, with contents:
uncle_of(U,C) :- brother_of(U,P),parent_of(P,C).

We can do a simple syntactic translation to SWRL from the command line as follows:
swipl -g "[owl2_io],convert_axioms('uncle.pl',pl_swrl, 'uncle.swrl',owl, [])"

This yields the rather voluminous SWRL ontology:


<swrl:Imp>
<swrl:body>
<swrl:AtomList>
<rdf:first>
<swrl:IndividualPropertyAtom>
<swrl:argument1 rdf:resource="#v1"/>
<swrl:argument2 rdf:resource="#v3"/>
<swrl:propertyPredicate rdf:resource="http://example.org#brother_of"/>
</swrl:IndividualPropertyAtom>
</rdf:first>
<rdf:rest>
<swrl:AtomList>
<rdf:first>
<swrl:IndividualPropertyAtom>
<swrl:argument1 rdf:resource="#v3"/>
<swrl:argument2 rdf:resource="#v2"/>
<swrl:propertyPredicate rdf:resource="http://example.org#parent_of"/>
</swrl:IndividualPropertyAtom>
</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</swrl:AtomList>
</rdf:rest>
</swrl:AtomList>
</swrl:body>
<swrl:head>
<swrl:AtomList>
<rdf:first>
<swrl:IndividualPropertyAtom>
<swrl:argument1 rdf:resource="#v1"/>
<swrl:argument2 rdf:resource="#v2"/>
<swrl:propertyPredicate rdf:resource="http://example.org#uncle_of"/>
</swrl:IndividualPropertyAtom>
</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</swrl:AtomList>
</swrl:head>
</swrl:Imp>

Personally I prefer authoring rules in prolog syntax in emacs and then converting via Thea, but YMMV.

We can also translate the SWRL into a property chain axiom subPropertyOf(propertyChain([uncle_of,brother_of]),uncle_of), eliminating the rule altogether:


swipl -g "[owl2_io],convert_axioms('uncle.pl',pl_swrl_owl, 'uncle.owl',owl, [])"

If you look at the results in Protege4 you will see:


brother_of o parent_of ➞ uncle_of

Other patterns also recognized include domain/ranges, transitivity, invereProperties, etc

These kind of syntactic translations are useful for interoperability. The benefits of writing ontology fragments as rules becomes more apparent if we consider the following program processual_part_of.pl:


% if part_of holds for a process, the specific
% relation is processual_part_of
processual_part_of(P,W) :- part_of(P,W),process(W). %
% if part_of holds for an object, the specific
% relation is spatial_part_of
static_part_of(P,W) :- part_of(P,W),object(W). %
part_of(p1,p2).
part_of(ob1,ob2).
process(p1).
process(p2).
object(ob1).
object(ob2).

The two rules in this program can distinguish two relations based on the domain of the relation. For example, we can ask


?- processual_part_of(X,Y).

And get back the answers p1-p2, but not ob1-ob2.

This is a fairly trivial program. Yet it’s not immediately obvious how to code this in OWL. There is a way but it is rather ingenious/baroque, involving the creation of two fake properties and some self-restrictions and property chains.

Fortunately, Thea2 will help us with this too.


swipl -g "[owl2_io],convert_axioms('testfiles/processual_part_of.pl',pl_swrl_owl,'ppo.owl',owl,[])"

Here I show the results in Thea/owlpl syntax:


subClassOf('_d:process', hasSelf('_d:process_p')).
subClassOf('_d:object', hasSelf('_d:object_p')).
subPropertyOf(propertyChain(['_d:part_of', '_d:process_p']), '_d:processual_part_of').
subPropertyOf(propertyChain(['_d:part_of', '_d:object_p']), '_d:static_part_of').
propertyAssertion('_d:part_of', p1, p2).
propertyAssertion('_d:part_of', ob1, ob2).
classAssertion('_d:process', p1).
classAssertion('_d:process', p2).
classAssertion('_d:object', ob1).
classAssertion('_d:object', ob2).

here all the nasty ‘fake property’ stuff is taken care of for us behind the scenes.

We can demonstrate it works with the following sparql query via Pellet2:


SELECT * WHERE {?x <http://x.org#processual_part_of> ?y}

which yields:


Query Results (1 answers):
x | y
=======
p1 | p2

Of course, there are many prolog programs that cannot be translated to OWL, and many OWL ontologies for which logic programs cannot be created. Each paradigm has its own strengths and weaknesses. Greater interoperability between the two can only help.

A prolog library for OWL2 and SWRL

Ontologies are vital for the life sciences. The Web Ontology Language (OWL) offers decidability of reasoning, and now with OWL2 and SWRL reasonably high levels of expressivity.

Vangelis Vassilidis and I are writing Thea2, based on his original Thea library. The redesign introduces prolog predicates for every OWL2 axiom, and prolog terms for owl class and property expressions. We use the SWI-Prolog semweb library for reading/writing to RDF. There is also an (optional) JPL bridge wrapping the Manchester OWLAPI.

There are a number of different reasoning strategies, including:

  • simple but limited backward chaining reasoning
  • using Grosof’s translation to DLP in conjunction with systems such as Yap, XSB or DLV
  • using standard OWL reasoners via JPL (DIG interface from Thea1 still needs ported)

Source: github
Documentation: pldoc