On Mon, Sep 9, 2013 at 12:33 PM, Phil Ashworth <[email protected]> wrote:
>
> HI Joshua
> Sorry I think I caused some confusion.
> The code was the example from the web site you pointed me to.
> That code used a second model to capture all the information from all of the 
> constructs.
> Basically I want to do the same but for a select statement.
> Selects come back as result set of query solutions so I was wondering if 
> there an easy way of combining all the querysolutions from all of the result 
> sets from multiple selects and then have an resultsets to iterate over them.

How about ResultSetMem [1]?  It's got a constructor that looks like it
does what you want:

public ResultSetMem(ResultSet... sets)

Create an in-memory result set from an array of ResulSets. It is
assumed that all the ResultSets from the array have the same
variables.
Parameters:sets - the ResultSet objects to concatenate.

[1] 
http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/sparql/resultset/ResultSetMem.html


> On Mon, Sep 9, 2013 at 2:08 PM, Joshua TAYLOR <[email protected]> wrote:
>>
>> On Fri, Sep 6, 2013 at 5:11 PM, Phil Ashworth <[email protected]> wrote:
>> > Sorry to revisit this thread
>> > In one of the links you kindly provided there is a great example for using
>> > PSS in a construct ( see below)
>> > I really like the example. It's neat that you combine the models together 
>> > in
>> > a new model before writing it out.
>> >
>> > I have a similar problem but I want to run a series of select queries
>> > combing the results of the resultsets before doing something with all the
>> > results.
>> >
>> > I've tried a couple ways of doing this but I keep hitting hurdles.
>> > The obvious way is to add each resultset querysolution into a
>> > list<querysolution> and then use an iterator over the list.
>> > But then I can't cast the list Iterator as a resultset which I would like 
>> > to
>> > do to try and reuse variables in the code whether the it is running 
>> > multiple
>> > selects or just one.
>> >
>> > Is using a list<querysolution>.iterator() the best way to achieve the
>> > outcome?
>> >
>> > public class DBPediaQuery {
>> >   public static void main( String[] args ) {
>> >     final String dbpedia = "http://dbpedia.org/sparql";;
>> >     final ParameterizedSparqlString queryString
>> >       = new ParameterizedSparqlString(
>> >             "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>"+
>> >             "PREFIX dbo: <http://dbpedia.org/ontology/>" +
>> >             "CONSTRUCT WHERE {" +
>> >             "  ?s a dbo:Place ." +
>> >             "  ?s geo:lat ?lat ." +
>> >             "  ?s geo:long ?long ." +
>> >             "}" );
>> >     Model allResults = ModelFactory.createDefaultModel();
>> >     for ( String mountain : new String[] { "Mount_Monadnock",
>> > "Mount_Lafayette" } ) {
>> >       queryString.setIri( "?s", "http://dbpedia.org/resource/"; + mountain 
>> > );
>> >       QueryExecution exec = QueryExecutionFactory.sparqlService( dbpedia,
>> > queryString.toString() );
>> >       Model results = exec.execConstruct();
>> >       allResults.add( results );
>> >     }
>> >     allResults.setNsPrefix( "geo",
>> > "http://www.w3.org/2003/01/geo/wgs84_pos#"; );
>> >     allResults.setNsPrefix( "dbo", "http://dbpedia.org/ontology/"; );
>> >     allResults.setNsPrefix( "dbr", "http://dbpedia.org/resource/"; );
>> >     allResults.write( System.out, "N3" );
>> >   }
>> > }
>>
>> Sorry for the delay in response.  I'm not quite clear from the code
>> that you posted what exactly you're trying to do.  ResultSet is just
>> an interface, and it wouldn't be all that hard to implement a
>> ResultSet that wraps a iterator over QuerySolutions.  However, if the
>> problem is that you're using QEF.sparqlService:
>>
>> >       QueryExecution exec = QueryExecutionFactory.sparqlService( dbpedia, 
>> > queryString.toString() );
>>
>> perhaps you could use the 'service' keyword in the query, e.g.,
>>
>> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
>> PREFIX dbo: <http://dbpedia.org/ontology/>
>> CONSTRUCT WHERE {
>>   SERVICE <http://dbpedia.org/sparql> {
>>     ?s a dbo:Place .
>>     ?s geo:lat ?lat .
>>     ?s geo:long ?long .
>>   }
>> }
>>
>> and execute the query as you would if you weren't using
>> QEF.sparqlService.  I'm not sure whether that works or not, but if it
>> does, and your problem arises from using QEF.sparqlService, it seems
>> like a relatively quick workaround.
>>
>> --
>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
>



-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to