Reputation: 379
I am trying to retrieve the individuals of a class (note: the class has no subclasses) with rdf:type
Jena in Java.
Onto Data (x individuals):
Class A: x1, x2, x3, x4 Class B: x5, x6, x7, x8 Class C: x9, x10, x11, x12
Object Properties: z1 (CLASS A with B), z2 (CLASS A WITH C), z3 (CLASS B with C)
RESULTS for rdf:type of CLassA:
In Protege: x1, x2, x3, x4 In Eclipse through jena: x1, x2, x3, x4, x5, x6, x7, x8, x9....
Select ?x
where { ?x rdf:type :ClassA }
In the ontology editor it works perfectly. However, in Java, when I execute the query I also get individuals which do not belong in that class, but they are connected through a property with one of the class individuals. Anyone knows how to fix this? The ontology is correct.
Eclipse/Jena:
PropertyConfigurator.configure("D:\\apache-jena-2.10.1\\jena-log4j.properties");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
FileManager.get().readModel( model, "file:.owl" );
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Bio#> " +
" SELECT ?x " +
" WHERE { ?x rdf:type bio:Class } " ;
Query query = QueryFactory.create(queryString);
QueryExecution qe= QueryExecutionFactory.create(query, model);
com.hp.hpl.jena.query.ResultSet resultset = qe.execSelect();
ResultSetFormatter.out(System.out, resultset, query);
Protégé:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Bio#>
SELECT ?x
WHERE { ?x rdf:type bio:ClassA }
Upvotes: 0
Views: 6938
Reputation: 1
check the domain and range of your data type proprties for exampla in z3 if you set domain of z3 as CLASS A every individual which take part in this property is consider as a member of class A although you specify that individual as an class B individual in your ontology
Upvotes: 0
Reputation: 586
If the ontology is correct then could you show us your code?
Are you sure ":Class" is correct?
If the default namespace is owl or another vocabulary then it could be possible its returning all individuals using that vocabulary or possibly a difference in inference rules used in Jena. This is an assumption.
Upvotes: 1