我正在尝试使用 D2RQ 运行查询。当我按照将 D2RQ 引擎与 Jena 一起使用http://localhost:2020/sparql
中所述使用浏览器运行查询时,一切正常,但使用 Jena API 不会产生任何结果。查询是
PREFIX vocab: <http://localhost:2020/resource/vocab/>
SELECT ?personName WHERE {
?person vocab:people_Name ?personName .
}
这是构造查询并针对模型运行它的 Java 代码:
ModelD2RQ m = new ModelD2RQ( "file:///C:/Users/sabse/Downloads/d2rq-0.8.1/d2rq-0.8.1/mapping-ontology.ttl");
String sparql =
"PREFIX vocab: <http://localhost:2020/resource/vocab/>" +
"SELECT ?personName WHERE {" +
" ?person vocab:people_Name ?personName . " +
"}";
Query q = QueryFactory.create(sparql);
ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
ResultSetFormatter.out(System.out, rs, q);
m.close();
数据以以下前缀声明开头:
@prefix vocab: <vocab/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix jdbc: <http://d2rq.org/terms/jdbc/> .