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.