as title describes, resultset.hasnext()
returns false
unexpectedly.
here sparql query , java source code based on jena:
select ?s ?label { ?s rdfs:label ?label. filter(contains(lcase(?label), "university"@en)). } limit 5 query query = queryfactory.create(prefix + sparqlquery); queryexecution queryexecution = queryexecutionfactory.sparqlservice("https://query.wikidata.org/sparql", prefix + sparqlquery); try { resultset results = queryexecution.execselect(); resultsetformatter.out(system.out, results, query); while (results.hasnext()) { // returns false querysolution querysolution = results.next(); system.out.println(querysolution.getresource("s")); } } catch (exception ex) { system.err.println(ex.getmessage()); } { queryexecution.close(); }
here output:
------------------------------------------------------ | s | label | ====================================================== | wd:q1060 | "technical university of hamburg"@en | | wd:q1060 | "technical university of hamburg"@en-ca | | wd:q1060 | "technical university of hamburg"@en-gb | | wd:q1060 | "technical university of hamburg"@nl | | wd:q4027 | "jean moulin university lyon 3"@en | ------------------------------------------------------
you can iterate once on resultset
, , happens in convenience method resultsetformatter.out(...)
i don't know whether need process resultset
twice, if can create resultsetrewindable
allows reset cursor:
query query = queryfactory.create(prefix + sparqlquery); queryexecution queryexecution = queryexecutionfactory.sparqlservice("https://query.wikidata.org/sparql", prefix + sparqlquery); try { resultset rs = queryexecution.execselect(); resultsetrewindable results = resultsetfactory.copyresults(rs); resultsetformatter.out(system.out, results, query); results.reset(); while (results.hasnext()) { // returns false querysolution querysolution = results.next(); system.out.println(querysolution.getresource("s")); } } catch (exception ex) { system.err.println(ex.getmessage()); } { queryexecution.close(); }
Comments
Post a Comment