这是我的CS.owl的一部分,它显示了类CloudService的单个DropBox。
<!-- http://www.semanticweb.org/ontologies/SaaS-24-03-2013.owl#DropBox -->
<owl:NamedIndividual rdf:about="&SaaS-24-03-2013;DropBox">
<rdf:type rdf:resource="&SaaS-24-03-2013;CloudService"/>
<hasPriceModel rdf:resource="&SaaS-24-03-2013;Freemium"/>
<hasDeliveryModel rdf:resource="&SaaS-24-03-2013;Software-as-a-Service"/>
</owl:NamedIndividual>我需要使用Jena检索类DropBox的个人(如CloudService )。下面的SPARQL查询在Protege 4.3中运行得很好。它检索许多服务,包括"DropBox“。我需要用Jena来运行它。这是我的密码
String 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 : <http://www.semanticweb.org/ontologies/SaaS-24-03-2013.owl#> "+
"SELECT ?Service "+
" WHERE {"+
" ?Service a :CloudService} ";
model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
model.read("ontologies/CS.owl");
Query query = QueryFactory.create(SparqlQuery);
QueryExecution qe = QueryExecutionFactory.create(query, model);
com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
qe.close();
ResultSetFormatter.out(System.out, results);
}查询返回列标题下的空结果,而它在Protege上工作,并返回结果(包括DropBox),我的代码有什么问题?
发布于 2016-02-26 11:26:37
您关闭了执行qe,然后尝试打印结果。代码必须完成调用qe.close的结果的处理。移动ResultSetFormatter线。
https://stackoverflow.com/questions/35646637
复制相似问题