简体   繁体   中英

SPARQL query to retrieve individuals of a class

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.

  • I am using eclipse as editor in java
  • I am using Protege to build the ontology

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 }

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.

如果将z3的域设置为CLASS A,则检查z3中的exampla的数据类型属性的域和范围,尽管您在z3中将该个人指定为B类个体,但将每个参与此属性的个人都视为A类成员。你的本体

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM