I have a question about accessing instances of a restriction class. Below I 
have a simple ontology, followed by some Jena Java code. My issue is that the 
class PatientSubset1 is reporting it has no instances. Can you see what I have 
done wrong?

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix :       <http://example.org/ex1#> .

:A a owl:Class .

:B1 a owl:Class ;
        rdfs:subClassOf :A .

:B2 a owl:Class ;
        rdfs:subClassOf :A .

:C1 a owl:Class ;
        rdfs:subClassOf :B1 .

:C2 a owl:Class ;
        rdfs:subClassOf :B1 .

:C3 a owl:Class ;
        rdfs:subClassOf :B2 .

:C4 a owl:Class ;
        rdfs:subClassOf :B2 .

:b1 rdf:type :B1 .

:Set1 a owl:Class ;
        owl:distinctMembers (:b1) .

:Patient a owl:Class ;
        rdfs:label "Patient" .

:p1 rdf:type :Patient .
:p2 rdf:type :Patient .
:p3 rdf:type :Patient .

:p1 :diagnosis :B1 .
:p2 :diagnosis :C1 .

:PatientSubset1 rdfs:subClassOf :Patient ;
        a [
                a owl:Restriction ;
                owl:onProperty :diagnosis ;
                owl:someValuesFrom (:B1)
        ] .


                OntModel omodel = ModelFactory.createOntologyModel();
                InputStream in = FileManager.get().open(fileName);
                omodel.read(in, baseName, "TURTLE");
                String fulluri = baseName + className;
                OntClass oclass = omodel.getOntClass(fulluri);
                System.out.println("Class is " + oclass.getURI()); 
System.out.flush();
                ExtendedIterator<? extends OntResource> iter = 
oclass.listInstances();
                while( iter.hasNext() ){
                        OntResource res = iter.next();
                        String uri = res.getURI();
                        System.out.println(uri);
                }

Any ideas why this is not returning any instances? I would expect the resulting 
instances to include :p1 and :p2.


Reply via email to