Search code examples
rdfjenaowlrdfsreasoning

Does Apache Jena support reasoning over OWL restrictions?


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?


Solution

  • The explanation for this is actually because I made a rookie mistake in thinking about OWL and RDF inference.

    The simple explanation (as pointed out in the comments) is that the rdfs:domain on the property is sufficient for the inferencer to decide that the entity is a Person. If an entity is the subject of a name then it is an instance of Person, Q.E.D.

    This leads to another question, however. The restriction class clearly states that it is not a person unless it has both a name and an age. So why isn't this a logical inconsistency? I have one piece of data that says Zeus is a Person, and another piece of data that says he's not, don't I?

    Well, no. Because even though I've encountered it many times before, I once again tripped over the Open World model of reasoning. Which is that all inferencing occurs with the assumption that you don't actually have all the facts, and that things might be true even if the system hasn't explicitly asserted them to be true.

    In other words, just because my data doesn't explicitly state that Zeus has an age, doesn't mean he doesn't. Someone else could come along and assert an age at any time.

    As such, in general, minCardinality constraints can't really be enforced or checked via open-world reasoning.

    maxCardinality is a different story, and does result in an inconsistent ontology error in a similar situation.