You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "jdejong.lcsd" <jd...@protonmail.com.INVALID> on 2021/06/21 13:48:26 UTC

Federated queries with Jena-extras query builder

Hi all,

I’m using the Jena query builder from the Jena-extras and I was wondering if there was a way to add a SERVICE clause to a SelectBuilder object.

I’ve also tried adding the SERVICE clause to a Query object after calling builder.build(), but it seems like it’s only possible through the ARQ API using body.addElement(new ElementService("http://any.domain/sparql", elementBlock)). The problem is that you can’t get the elementBlock from a Query object or SelectBuilder object.

My code right now looks like this:

SelectBuilder builder =

new

SelectBuilder()

.addPrefix(

"rdf"

,

"
http://www.w3.org/1999/02/22-rdf-syntax-ns#
"

)

.addPrefix(

"dbo"

,

"
http://dbpedia.org/ontology/
"

)

.addVar(

"?uri"

)

.addWhere(

"?uri"

,

"rdf:type"

,

"dbo:Company"

)

.setLimit(

100

)

;

Query query = builder.build()

;

System.

out

.println(query)

;

Is there a way to add a SERVICE clause using the query builder or are there known workarounds without resorting to the verbose ARQ API, or should I try and extend the SelectBuilder API myself?

Re: Federated queries with Jena-extras query builder

Posted by Andy Seaborne <an...@apache.org>.

On 21/06/2021 14:48, jdejong.lcsd wrote:
> Hi all,
> 
> I’m using the Jena query builder from the Jena-extras and I was wondering if there was a way to add a SERVICE clause to a SelectBuilder object.
> 
> I’ve also tried adding the SERVICE clause to a Query object after calling builder.build(), but it seems like it’s only possible through the ARQ API using body.addElement(new ElementService("http://any.domain/sparql", elementBlock)). The problem is that you can’t get the elementBlock from a Query object or SelectBuilder object.

Query.getQueryPattern() -> Element

> 
> My code right now looks like this:
> 
> SelectBuilder builder =
> 
> new
> 
> SelectBuilder()
> 
> .addPrefix(
> 
> "rdf"
> 
> ,
> 
> "
> http://www.w3.org/1999/02/22-rdf-syntax-ns#
> "
> 
> )
> 
> .addPrefix(
> 
> "dbo"
> 
> ,
> 
> "
> http://dbpedia.org/ontology/
> "
> 
> )
> 
> .addVar(
> 
> "?uri"
> 
> )
> 
> .addWhere(
> 
> "?uri"
> 
> ,
> 
> "rdf:type"
> 
> ,
> 
> "dbo:Company"
> 
> )
> 
> .setLimit(
> 
> 100
> 
> )
> 
> ;
> 
> Query query = builder.build()
> 
> ;
> 
> System.
> 
> out
> 
> .println(query)
> 
> ;
> 
> Is there a way to add a SERVICE clause using the query builder or are there known workarounds without resorting to the verbose ARQ API, or should I try and extend the SelectBuilder API myself?
>