簡體   English   中英

jena.query.ResultSet和jena.query.QuerySolution:SPARQL請求后的空迭代器

[英]jena.query.ResultSet and jena.query.QuerySolution: empty iterator after SPARQL request

A有接收SPARQL響應的問題。 問題是方法((ResultSet) response).hasNext()返回false盡管響應不應為空。

要求是:

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個對象:

Location
Relation
Descriptive

查詢以jena的方式執行:

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關閉且不再可用。

qexec.close移動到循環之后。

改進:

Object response ==> ResultSet response

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM