A NodeIterator for what? A ResultSet wraps an iterator of QuerySolution
objects, each of which contains the mapping of a variable name to the
corresponding RDF resource (if bound). Thus, each QuerySolution can wrap
a set of nodes...
Clearly, you could generate a wrapping iterator by yourself. Just
implement the NodeIterator interface and the corresponding methods. The
constructor indeed should take the ResultSet and a variable name as
arguments (if you want all nodes for each QuerySolution, it'S also
possible) - the rest is straightforward Java coding.
Untested stub:
class ResultSetWrappingNodeIterator implements NodeIterator {
final ResultSet rs;
final String varName;
ResultSetWrappingNodeIterator(ResultSet rs, String varName) {
this.rs = rs;
this.varName = varName;
}
public RDFNode next() {
return rs.next().get(varName).asNode();
}
...
}
On 11.07.2018 07:27, Myungjin Lee wrote:
> Hi.
>
>
>
> I have a question. I am developing small application with Jena and ARQ.
>
>
>
> Is it possible to create NodeIterator instance from SPARQL result?
>
> In Jena and ARQ APIs, SPARQL query(qexec.execSelect() method) returns an
> instance of ResultSet interface.
>
>
>
> But I want to create a method that returns NodeIterator instance after
> executing SPARQL query like below.
>
>
>
> public NodeIterator getObjects(Resource s, Property p) {
>
> String queryString = "SELECT ?o WHERE { <" + s.getURI() + "> <" +
> p.getURI() + "> ?o . }";
>
> Query query = QueryFactory.create(queryString);
>
> QueryExecution qexec =
> QueryExecutionFactory.sparqlService("SPARQL_ENDPOINT_ADDRESS", query);
>
> ResultSet results = qexec.execSelect();
>
> NodeIterator ni = ??? // to create NodeIterator instance from
> ResultSet
>
> return ni;
>
> }
>
>
>
> Is it possible?
>
> Thank you for your help.
>
>
>
> Best regards,
>
> Myungjin Lee
>
>