[英]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. 我正在尝试使用Java中的rdf:type
Jena检索类的个人(注意:该类没有子类)。
Onto Data (x individuals): 数据(x个人):
Class A: x1, x2, x3, x4 Class B: x5, x6, x7, x8 Class C: x9, x10, x11, x12 A类:x1,x2,x3,x4 B类:x5,x6,x7,x8 C类:x9,x10,x11,x12
Object Properties: z1 (CLASS A with B), z2 (CLASS A WITH C), z3 (CLASS B with C) 对象属性:z1(带有B的CLASS A),z2(带有C的CLASS A),z3(带有C的CLASS B)
RESULTS for rdf:type of CLassA: rdf:CLassA类型的结果:
In Protege: x1, x2, x3, x4 In Eclipse through jena: x1, x2, x3, x4, x5, x6, x7, x8, x9.... 在Protege中:x1,x2,x3,x4在通过耶拿的Eclipse中: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. 但是,在Java中,当我执行查询时,我也会得到不属于该类的个人,但它们通过属性与其中一个类个人相连。 Anyone knows how to fix this? 有人知道如何解决这个问题吗? The ontology is correct. 本体是正确的。
Eclipse/Jena: Eclipse /耶拿:
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é: 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? 你确定“:Class”是正确的吗?
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. 如果默认名称空间是owl或其他词汇表,则有可能返回使用该词汇表的所有个人,或者Jena中使用的推理规则可能有所不同。 This is an assumption. 这是一个假设。
如果将z3的域设置为CLASS A,则检查z3中的exampla的数据类型属性的域和范围,尽管您在z3中将该个人指定为B类个体,但将每个参与此属性的个人都视为A类成员。你的本体
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.