Monthly Archives: June 2009

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, 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('',pl_swrl, 'uncle.swrl',owl, [])"

This yields the rather voluminous SWRL ontology:

<swrl:argument1 rdf:resource="#v1"/>
<swrl:argument2 rdf:resource="#v3"/>
<swrl:propertyPredicate rdf:resource=""/>
<swrl:argument1 rdf:resource="#v3"/>
<swrl:argument2 rdf:resource="#v2"/>
<swrl:propertyPredicate rdf:resource=""/>
<rdf:rest rdf:resource="&rdf;nil"/>
<swrl:argument1 rdf:resource="#v1"/>
<swrl:argument2 rdf:resource="#v2"/>
<swrl:propertyPredicate rdf:resource=""/>
<rdf:rest rdf:resource="&rdf;nil"/>

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('',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

% 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). %

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/',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 <; ?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.

Robot Scientist

This story received a bit of coverage last month: [BBC]

There are more details in the Science publication, “the automation of science”:

The system generates scientific hypotheses about gene functions, then devises and carries out experiments to test these hypotheses. The system appears to be written in Prolog, with the hypothesis generation using Inductive/Abductive Logic Programming, in particular the ProGol system.

More details can be found on the group’s website.