You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Phil Ashworth <pa...@gmail.com> on 2014/01/10 20:04:44 UTC

Options for calling a sparql endpoint in jena

Hi All

Happy New Year.

I've previously used the following code with success to call a sparql
endpoint.
final com.hp.hpl.jena.query.QueryExecution qexec =
com.hp.hpl.jena.query.QueryExecutionFactory.sparqlService(serviceUri,query)
;
        final com.hp.hpl.jena.query.ResultSet tempresults  =
qexec.execSelect() ;

This works well and has allowed me seperate the endpoint url from the query.

I would now like to handle queries which define the service clause in them
and without having to set the service uri specifically.
e.g
select * where
{
      SERVICE <sparqlepURL> {
        .....
       }
}

I can't find an exact code example but I did find the documentation about
using the Syntax.syntaxARQ.
But it didn't say how to use it.

So I tried the following
final com.hp.hpl.jena.query.QueryExecution qexec =
com.hp.hpl.jena.query.QueryExecutionFactory.create(query,com.hp.hpl.jena.query.Syntax.syntaxARQ)
;
    final com.hp.hpl.jena.query.ResultSet results  = qexec.execSelect() ;

This throws the error

com.hp.hpl.jena.query.QueryExecException: No dataset description for query
    at
com.hp.hpl.jena.sparql.engine.QueryExecutionBase.prepareDataset(QueryExecutionBase.java:604)
    at
com.hp.hpl.jena.sparql.engine.QueryExecutionBase.getPlan(QueryExecutionBase.java:547)
................


I'm a little confused as to how this make it work.
There is no dataset to search here as it is an endpoint.

If someone could suggest how to do this it would be appreciated

Sorry for the dumb question.

Phil

Re: Options for calling a sparql endpoint in jena

Posted by Phil Ashworth <pa...@gmail.com>.
Greatly appreciated.
Thanks
On 11 Jan 2014 10:25, "Andy Seaborne" <an...@apache.org> wrote:

> On 10/01/14 19:46, Phil Ashworth wrote:
>
>> Thanks Andy
>> One quick question:
>> Should I stop using the QueryExecutionFactory.sparqlService
>> method completely or are are there circumstances where it is good to
>> use it?
>>
>
> If you are just putting a SERVICE inside a WHERE clause of SELECT * , with
> no other pattern (local or other SERVICE) then it is two routes to much the
> same thing.
>
> If the top-level (local) query has ORDER BY, LIMIT etc then it makes a
> difference - using QueryExecutionFactory.sparqlService sends it all to
> the far end and result stream back.  Otherwise the ORDER BY, LIMIT is done
> locally which can be less efficient.
>
> And personally I'd use QueryExecutionFactory.sparqlService so the service
> URI is not in the query.
>
> If you want to abstract away from local vs remote, you may find this
> experimental module useful:
>
> https://svn.apache.org/repos/asf/jena/Experimental/jena-client/
>
> and there is also:
>
> https://github.com/AKSW/jena-sparql-api
>
>         Andy
>
>
>> Many thanks again.
>>
>> Phil
>>
>>
>> On Fri, Jan 10, 2014 at 7:29 PM, Andy Seaborne <an...@apache.org> wrote:
>>
>>  On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com>
>>>
>>>> wrote:
>>>>
>>>>  I can't find an exact code example but I did find the documentation
>>>>> about
>>>>> using the Syntax.syntaxARQ.
>>>>>
>>>>>
>>>>  Out of date documentation - it's part of standard SPARQL 1.1 these
>>> days.
>>>
>>>          Andy
>>>
>>>
>>>
>>
>

Re: Options for calling a sparql endpoint in jena

Posted by Andy Seaborne <an...@apache.org>.
On 10/01/14 19:46, Phil Ashworth wrote:
> Thanks Andy
> One quick question:
> Should I stop using the QueryExecutionFactory.sparqlService
> method completely or are are there circumstances where it is good to
> use it?

If you are just putting a SERVICE inside a WHERE clause of SELECT * , 
with no other pattern (local or other SERVICE) then it is two routes to 
much the same thing.

If the top-level (local) query has ORDER BY, LIMIT etc then it makes a 
difference - using QueryExecutionFactory.sparqlService sends it all to 
the far end and result stream back.  Otherwise the ORDER BY, LIMIT is 
done locally which can be less efficient.

And personally I'd use QueryExecutionFactory.sparqlService so the 
service URI is not in the query.

If you want to abstract away from local vs remote, you may find this 
experimental module useful:

https://svn.apache.org/repos/asf/jena/Experimental/jena-client/

and there is also:

https://github.com/AKSW/jena-sparql-api

	Andy

>
> Many thanks again.
>
> Phil
>
>
> On Fri, Jan 10, 2014 at 7:29 PM, Andy Seaborne <an...@apache.org> wrote:
>
>> On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com>
>>> wrote:
>>>
>>>> I can't find an exact code example but I did find the documentation about
>>>> using the Syntax.syntaxARQ.
>>>>
>>>
>> Out of date documentation - it's part of standard SPARQL 1.1 these days.
>>
>>          Andy
>>
>>
>


Re: Options for calling a sparql endpoint in jena

Posted by Phil Ashworth <pa...@gmail.com>.
Thanks Andy
One quick question:
Should I stop using the *sparqlService
<http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/QueryExecutionFactory.html#sparqlService%28java.lang.String,%20com.hp.hpl.jena.query.Query%29>*
(String<http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true>
service,
Query<http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/Query.html>
 query)method completely or are are there circumstances where it is good to
use it?

Many thanks again.

Phil


On Fri, Jan 10, 2014 at 7:29 PM, Andy Seaborne <an...@apache.org> wrote:

> On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com>
>> wrote:
>>
>>> I can't find an exact code example but I did find the documentation about
>>> using the Syntax.syntaxARQ.
>>>
>>
> Out of date documentation - it's part of standard SPARQL 1.1 these days.
>
>         Andy
>
>

Re: Options for calling a sparql endpoint in jena

Posted by Andy Seaborne <an...@apache.org>.
> On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com> wrote:
>> I can't find an exact code example but I did find the documentation about
>> using the Syntax.syntaxARQ.

Out of date documentation - it's part of standard SPARQL 1.1 these days.

	Andy


Re: Options for calling a sparql endpoint in jena

Posted by Phil Ashworth <pa...@gmail.com>.
Thanks Willie and Andy.

Works a treat now.

Phil.


On Fri, Jan 10, 2014 at 7:13 PM, Willie Milnor <mi...@gmail.com> wrote:

> You can just execute the query against the default model:
>
> Model model = ModelFactory.createDefaultModel();
> QueryExecution qexec = QueryExecutionFactory.create(query, model);
>
>
>
>
>
>
> On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com>
> wrote:
>
> > Hi All
> >
> > Happy New Year.
> >
> > I've previously used the following code with success to call a sparql
> > endpoint.
> > final com.hp.hpl.jena.query.QueryExecution qexec =
> >
> com.hp.hpl.jena.query.QueryExecutionFactory.sparqlService(serviceUri,query)
> > ;
> >         final com.hp.hpl.jena.query.ResultSet tempresults  =
> > qexec.execSelect() ;
> >
> > This works well and has allowed me seperate the endpoint url from the
> > query.
> >
> > I would now like to handle queries which define the service clause in
> them
> > and without having to set the service uri specifically.
> > e.g
> > select * where
> > {
> >       SERVICE <sparqlepURL> {
> >         .....
> >        }
> > }
> >
> > I can't find an exact code example but I did find the documentation about
> > using the Syntax.syntaxARQ.
> > But it didn't say how to use it.
> >
> > So I tried the following
> > final com.hp.hpl.jena.query.QueryExecution qexec =
> >
> >
> com.hp.hpl.jena.query.QueryExecutionFactory.create(query,com.hp.hpl.jena.query.Syntax.syntaxARQ)
> > ;
> >     final com.hp.hpl.jena.query.ResultSet results  = qexec.execSelect() ;
> >
> > This throws the error
> >
> > com.hp.hpl.jena.query.QueryExecException: No dataset description for
> query
> >     at
> >
> >
> com.hp.hpl.jena.sparql.engine.QueryExecutionBase.prepareDataset(QueryExecutionBase.java:604)
> >     at
> >
> >
> com.hp.hpl.jena.sparql.engine.QueryExecutionBase.getPlan(QueryExecutionBase.java:547)
> > ................
> >
> >
> > I'm a little confused as to how this make it work.
> > There is no dataset to search here as it is an endpoint.
> >
> > If someone could suggest how to do this it would be appreciated
> >
> > Sorry for the dumb question.
> >
> > Phil
> >
>
>
>
> --
> Cheers,
> Willie
>

Re: Options for calling a sparql endpoint in jena

Posted by Willie Milnor <mi...@gmail.com>.
You can just execute the query against the default model:

Model model = ModelFactory.createDefaultModel();
QueryExecution qexec = QueryExecutionFactory.create(query, model);






On Fri, Jan 10, 2014 at 2:04 PM, Phil Ashworth <pa...@gmail.com> wrote:

> Hi All
>
> Happy New Year.
>
> I've previously used the following code with success to call a sparql
> endpoint.
> final com.hp.hpl.jena.query.QueryExecution qexec =
> com.hp.hpl.jena.query.QueryExecutionFactory.sparqlService(serviceUri,query)
> ;
>         final com.hp.hpl.jena.query.ResultSet tempresults  =
> qexec.execSelect() ;
>
> This works well and has allowed me seperate the endpoint url from the
> query.
>
> I would now like to handle queries which define the service clause in them
> and without having to set the service uri specifically.
> e.g
> select * where
> {
>       SERVICE <sparqlepURL> {
>         .....
>        }
> }
>
> I can't find an exact code example but I did find the documentation about
> using the Syntax.syntaxARQ.
> But it didn't say how to use it.
>
> So I tried the following
> final com.hp.hpl.jena.query.QueryExecution qexec =
>
> com.hp.hpl.jena.query.QueryExecutionFactory.create(query,com.hp.hpl.jena.query.Syntax.syntaxARQ)
> ;
>     final com.hp.hpl.jena.query.ResultSet results  = qexec.execSelect() ;
>
> This throws the error
>
> com.hp.hpl.jena.query.QueryExecException: No dataset description for query
>     at
>
> com.hp.hpl.jena.sparql.engine.QueryExecutionBase.prepareDataset(QueryExecutionBase.java:604)
>     at
>
> com.hp.hpl.jena.sparql.engine.QueryExecutionBase.getPlan(QueryExecutionBase.java:547)
> ................
>
>
> I'm a little confused as to how this make it work.
> There is no dataset to search here as it is an endpoint.
>
> If someone could suggest how to do this it would be appreciated
>
> Sorry for the dumb question.
>
> Phil
>



-- 
Cheers,
Willie