Thank you for your help.

As you know, there are several triple stores such as Virtuoso, AllegroGraph,
and so forth.
So I want to develop Jena base interfaces for different triple stores.
I know that some triple stores already support Jena, but some triple stores
that are not famous only support SPARQL endpoint.

For these triple stores, I need some classes that implements Jena
interfaces.
It is one of classes and methods to return NodeIterator from SPARQL result.

I thought there are, maybe, a simple way to create NodeIterator from
ResultSet.
But your code is a good solution for me.

Thank you.



-----Original Message-----
From: Lorenz Buehmann <buehm...@informatik.uni-leipzig.de> 
Sent: Wednesday, July 11, 2018 3:25 PM
To: users@jena.apache.org
Subject: Re: Create NodeIterator from SPARQL Result

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
>
>



Reply via email to