我正在尝试创建一个 Sparql-Query 来获取与讲座相关的所有消息。我是整个“语义网”故事的新手,所以如果使用命名空间完全错误,请耐心等待。
我尝试执行的查询是:
PREFIX siocNS: <http://rdfs.org/sioc/ns#>
PREFIX rdfPred: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX purlPred: <http://purl.org/dc/terms/>
PREFIX purlPredLecture: <http://purl.org/<CENSORED>/lecture/>
select ?post ?title ?content ?time ?creator where
{
?post rdfPred:type siocNS:Post.
?post purlPred:title ?title.
?post purlPred:content ?content.
?post purlPred:created ?time.
?post purlPred:creator ?creator.
?post purlPred:context purlPredLecture:1337-7331.
}
ID在哪里1337-7331
。
在 Sesame-Workbench 上,查询似乎工作正常(因为我得到了 2 个预期的行)。在 Java 上,使用 Jena,似乎我QueryExecuion
的不正确。
这是我的代码:
String prefix = "PREFIX siocNS: <http://rdfs.org/sioc/ns#>\n"
+ "PREFIX rdfPred: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX purlPred: <http://purl.org/dc/terms/>\n"
+ "PREFIX purlPredLecture: <http://purl.org/<CENSORED>/lecture/>\n";
String queryString = "select ?post ?title ?content ?time ?creator where\n"
+ "{\n"
+ "?post rdfPred:type siocNS:Post.\n"
+ "?post purlPred:title ?title. \n"
+ "?post purlPred:content ?content. \n"
+ "?post purlPred:created ?time. \n"
+ "?post purlPred:creator ?creator.\n"
+ "?post purlPred:context purlPredLecture:"
+ lectureID + ".\n" + "}";
logger.info("Created Query:" + prefix + queryString);
Query query = QueryFactory.create(prefix
+ queryString, Syntax.syntaxSPARQL);
query.addResultVar("?post");
query.addResultVar("?title");
query.addResultVar("?content");
query.addResultVar("?time");
query.addResultVar("?creator");
Model model = ModelFactory.createDefaultModel();
QueryExecution execution = QueryExecutionFactory
.create(query, model);
ResultSet execSelect = execution.execSelect();
while (execSelect.hasNext()) {
...
DO SOME STUFF
...
}
上面显示的查询是从 java-debugger 复制的。我是否在准备过程中遗漏了一些东西,Query(Execution)
Sesame-Workbench 是否完成了遗漏的东西?
谢谢你的帮助!
dpa