On Mon, 2011-08-29 at 17:40 +0000, David Jordan wrote: > 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?
There are at least a couple of problems here ... > @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 . The :diagnosis assertions should point to an instance, e.g. :b1, not the classes. > :PatientSubset1 rdfs:subClassOf :Patient ; > a [ > a owl:Restriction ; > owl:onProperty :diagnosis ; > owl:someValuesFrom (:B1) > ] . > > > OntModel omodel = ModelFactory.createOntologyModel(); If you want OWL inference then you need to specify an appropriate configuration such as OntModelSpec.OWL_MEM_MICRO_RULE_INF Dave > 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.
