jena.query.ResultSet和jena.query.QuerySolution:在SPARQL请求之后为空的迭代器 [英] jena.query.ResultSet and jena.query.QuerySolution: empty iterator after SPARQL request

查看:88
本文介绍了jena.query.ResultSet和jena.query.QuerySolution:在SPARQL请求之后为空的迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A在接收SPARQL响应时遇到问题.问题是方法 尽管响应不应为空,但((ResultSet) response).hasNext()返回false.

A have a problem with receiving SPARQL response. A problem is method ((ResultSet) response).hasNext() returns false despite response shouldn't be empty.

请求是:

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 ontology: <http://www.semanticweb.org/kseniia/ontologies/2013/1/untitled-ontology-12#> SELECT ?x 
WHERE {?x rdfs:subClassOf ontology:Visual}

这在Protege中可以正常工作,并返回3个对象:

This works correctly in Protege and returns 3 objects:

Location
Relation
Descriptive

查询是通过耶拿执行的:

Query was executed in jena such way:

Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
Object response = qexec.execSelect();
qexec.close();
for ( ; ((ResultSet) response).hasNext(); ) {   // always false
   QuerySolution soln = ((ResultSet) response).nextSolution();
   // etc
}

也许我错过了什么?

推荐答案

您要使用qexec.close关闭执行,然后遍历结果.除非结果被qexec.close关闭并且不再可用.

You are closing the execution with qexec.close, then iterating over the results. Except the results are closed by the qexec.close and no longer available.

qexec.close移至循环之后.

改进:

Object response ==> ResultSet response

这篇关于jena.query.ResultSet和jena.query.QuerySolution:在SPARQL请求之后为空的迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆