OWL reasoning example

62 views
Skip to first unread message

Jean Ivanoff

unread,
May 7, 2013, 11:15:50 AM5/7/13
to fuxi-discussion
Dear community,

I am a pythonist and beginner in logic programming. I wonder, how to
traverse an ontology programmatically with Python, so this is a beg to
show a FuXi usage example.

Suppose we have a simple ontology with two classes "Man" and "Woman",
two properties "isChildOf" and "isMarriedTo" and 4 individuals "John",
"Mary", "Tim" and "Kate". John is married to Mary, their common
children are Tim and Kate, like this:

<?xml version="1.0"?>
<!DOCTYPE Ontology [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://example.com#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
ontologyIRI="http://example.com#">
<Prefix name="" IRI="http://example.com#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-
ns#"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/
>
<Declaration>
<ObjectProperty IRI="isChildOf"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="isMarriedTo"/>
</Declaration>
<EquivalentObjectProperties>
<ObjectProperty IRI="isMarriedTo"/>
<ObjectInverseOf>
<ObjectProperty IRI="isMarriedTo"/>
</ObjectInverseOf>
</EquivalentObjectProperties>
<SubClassOf>
<Class IRI="Man"/>
<ObjectComplementOf>
<Class IRI="Woman"/>
</ObjectComplementOf>
</SubClassOf>
<SubClassOf>
<Class IRI="Man"/>
<ObjectAllValuesFrom>
<ObjectProperty IRI="isMarriedTo"/>
<Class IRI="Woman"/>
</ObjectAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="Woman"/>
<ObjectAllValuesFrom>
<ObjectProperty IRI="isMarriedTo"/>
<Class IRI="Man"/>
</ObjectAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class abbreviatedIRI="owl:Thing"/>
<ObjectMinCardinality cardinality="1">
<ObjectProperty IRI="isMarriedTo"/>
</ObjectMinCardinality>
</SubClassOf>
<ClassAssertion>
<Class IRI="Man"/>
<NamedIndividual IRI="John"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="Woman"/>
<NamedIndividual IRI="Kate"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="Woman"/>
<NamedIndividual IRI="Mary"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="Man"/>
<NamedIndividual IRI="Tim"/>
</ClassAssertion>
<ClassAssertion>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="isMarriedTo"/>
<ObjectOneOf>
<NamedIndividual IRI="Mary"/>
</ObjectOneOf>
</ObjectSomeValuesFrom>
<NamedIndividual IRI="John"/>
</ClassAssertion>
<ClassAssertion>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="isChildOf"/>
<ObjectOneOf>
<NamedIndividual IRI="John"/>
</ObjectOneOf>
</ObjectSomeValuesFrom>
<NamedIndividual IRI="Kate"/>
</ClassAssertion>
<ClassAssertion>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="isChildOf"/>
<ObjectOneOf>
<NamedIndividual IRI="Mary"/>
</ObjectOneOf>
</ObjectSomeValuesFrom>
<NamedIndividual IRI="Tim"/>
</ClassAssertion>
</Ontology>

Provided this ontology is loaded with **Graph().parse()**, how to
answer with FuXi, whether Tim is married to John? How to extract all
the individuals and check, whether they have children? Should I
compose and load some external rules for that?

Cross-post on http://answers.semanticweb.com/questions/22619/owl-reasoning-example-with-fuxi-rdflib-python

Kindly thank you for your knowledge sharing.

Jean Ivanoff

unread,
May 8, 2013, 4:16:22 AM5/8/13
to fuxi-discussion
Sorry for the mess with tags in XML/OWL, the actual ontology is
located at https://skydrive.live.com/redir?resid=44978370DAE7A961!112&authkey=!AA7A8NccR4gxr3w

Chimezie Ogbuji

unread,
May 8, 2013, 11:54:49 AM5/8/13
to fuxi-discussion
Hey Jean.

See my response here (repeated again below):

http://answers.semanticweb.com/questions/22619/owl-reasoning-example-with-fuxi-rdflib-python/22633

An additional caveat is that the example is run with the latest
version of FuXi in the mercurial repository and layercake-python.

-----------

A few caveats. As FuXi is a Logic Programming engine it is limited in
the kinds of OWL reasoning it can do. In particular it can handle OWL
2 RL semantics but nothing more expressive, without external rules.
So, for example, the ObjectComplementOf axiom between **ex:Man** and
**ex:Woman** can not be handled.

Similarly, the "*every thing is married to at least one thing*" axiom
cannot be handled (AFAICT). Otherwise, I have create a python
[file][1] that uses InfixOWL to programmatically create the OWL
ontology into an rdflib graph (making a few exceptions including the
removal of the complement axiom and the simplification of the who Tim
and Kate are children of). Then it uses the OWL 2 RL in RIF (DLP)
mechanism to extract the LP rules that it can. When you run the file,
you get the following RIF Core rules:

Forall ?X ?VAR1 ( ex:Woman(?VAR1) :- And( ex:Man(?X)
ex:isMarriedTo(?X ?VAR1)) )
Forall ?X ?VAR2 ( ex:Man(?VAR2) :- And( ex:Woman(?X)
ex:isMarriedTo(?X ?VAR2)) )

So, this is the extent of the semantics that FuXi can handle as a
[SPARQL 1.1 OWL 2 RL entailment regime implementation][2].

It then uses the [Backward Chaining Store][3] to answer "*is Tim
married to John?*" ( ASK { ex:Tim ex:isMarriedTo ex:John } ). This
just results in a query against the OWL RDF graph, as none of the
rules derive **isMarriedTo** statements. It queries the graph for
individuals via:

SELECT ?ind { ?ind a ?class FILTER(isUri(?ind) && ?class != owl:Class ) }

And for each result it queries for their children via:

SELECT ?child { ?child ex:isChildOf <.. the individual ..> }

This also results in a direct query against the OWL RDF graph. The
complete output is below:

BGP((ex:Tim,ex:isMarriedTo,ex:John))

False
Individual: http://example.com#Tim
--- Children ---
----------------
Individual: http://example.com#John
--- Children ---
- http://example.com#Kate
----------------
Individual: http://example.com#isChildOf
--- Children ---
----------------
Individual: http://example.com#isMarriedTo
--- Children ---
----------------
Individual: http://example.com#Kate
--- Children ---
----------------
Individual: http://example.com#Mary
--- Children ---
- http://example.com#Tim
----------------

[1]: https://code.google.com/p/fuxi/source/browse/test/test_example.py
[2]: http://www.w3.org/TR/sparql11-entailment/#OWL2RLDS
[3]: https://code.google.com/p/fuxi/wiki/TopDownSW

On Wed, May 8, 2013 at 4:16 AM, Jean Ivanoff <lvina...@yandex.ru> wrote:
> Sorry for the mess with tags in XML/OWL, the actual ontology is
> located at https://skydrive.live.com/redir?resid=44978370DAE7A961!112&authkey=!AA7A8NccR4gxr3w
>
> --
> You received this message because you are subscribed to the Google Groups "fuxi-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fuxi-discussi...@googlegroups.com.
> To post to this group, send email to fuxi-di...@googlegroups.com.
> Visit this group at http://groups.google.com/group/fuxi-discussion?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages