The capabilities of Jena's OWL reasoner listed here would seem to imply that Jena supports inference over restriction classes.
However, I am not observing this to be true. Specifically, I have an entity that is detected to be of a particular class, even though it's missing a property which a restriction with a minCardinality indicates must be present.
However, I am not sure if I am doing something wrong, my OWL is a bit rusty.
My data:
<?xml version="1.0"?>
<rdf:RDF xmlns = "http://www.example.com/people#"
xml:base = "http://www.example.com/people#"
xmlns:owl = "http://www.w3.org/2002/07/owl#"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema#">
<owl:DatatypeProperty rdf:ID="name">
<rdfs:domain rdf:resource="#Person"/>
<rdfs:range rdf:resource="xsd:string"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:ID="age">
<rdfs:domain rdf:resource="#Person"/>
<rdfs:range rdf:resource="xsd:nonNegativeInteger"/>
</owl:DatatypeProperty>
<owl:Class rdf:ID="Person">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#name"/>
<owl:cardinality rdf:datatype="xsd:nonNegativeInteger">1</owl:cardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#age"/>
<owl:cardinality rdf:datatype="xsd:nonNegativeInteger">1</owl:cardinality>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<!-- Is a person, because it's got a name and age -->
<rdf:Description rdf:about="#john">
<name>John</name>
<age rdf:datatype="xsd:nonNegativeInteger">42</age>
</rdf:Description>
<!-- Should not be a person, because it's missing an age -->
<rdf:Description rdf:about="#zeus">
<name>Zeus</name>
</rdf:Description>
</rdf:RDF>
My Code:
public static void main(String args[]) {
System.out.println("hello world");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
model.read("src/main/resources/sample.owl");
String queryString =
"PREFIX ppl: <http://www.example.com/people#>" +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"SELECT ?obj " +
"WHERE {" +
" ?obj rdf:type ppl:Person ." +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
This outputs:
------------
| obj |
============
| ppl:john |
| ppl:zeus |
------------
I would not expect ppl:zeus
to be an instance of Person
, because it does not satisfy the minCardinality restriction on age.
Any advice on what I'm doing wrong here? Is reasoning around rdfs:domain
overriding the reasoning around the restriction class?