0

我正在尝试使用rdf:type Java 中的 Jena 检索一个类的个体(注意:该类没有子类)。

数据(x 个人):

A 类:x1、x2、x3、x4 B 类:x5、x6、x7、x8 C 类:x9、x10、x11、x12

对象属性:z1(A 类和 B)、z2(A 类和 C)、z3(B 类和 C)

rdf 的结果:CLassA 的类型:

在 Protege 中:x1、x2、x3、x4 在 Eclipse 中通过耶拿:x1、x2、x3、x4、x5、x6、x7、x8、x9....

Select ?x
where { ?x rdf:type :ClassA }

在本体编辑器中,它可以完美运行。但是,在 Java 中,当我执行查询时,我还会得到不属于该类的个体,但它们通过属性与类个体之一连接。任何人都知道如何解决这个问题?本体是正确的。

  • 我在java中使用eclipse作为编辑器
  • 我正在使用 Protege 构建本体

日食/耶拿:

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);

门徒:

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 }
4

2 回答 2

1

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.

于 2013-09-07T11:29:45.860 回答
0

如果您将 z3 的域设置为 A 类,请检查 z3 中示例的数据类型属性的域和范围,尽管您在你的本体

于 2013-10-21T07:21:26.867 回答