You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Bart van Leeuwen <ba...@netage.nl> on 2016/09/14 13:08:47 UTC
Programatically adding filters to sparql query
Hi,
I'm looking for some documentation on adding additional filters to a
parsed sparql query
I can do:
Query q = new Query('select ?s ?p ?o where { ?s a sem:Event . ?s ?p ?o
}');
now I'd like to use the Query object Q to extend this query with a FIlter
clause.
any documentation pointers are appreciated.
Met Vriendelijke Groet / With Kind Regards
Bart van Leeuwen
##############################################################
# twitter: @semanticfire
# netage.nl
# http://netage.nl
# Esdoornstraat 3
# 3461ER Linschoten
# tel. +31(0)6-53182997
##############################################################
Re: Programatically adding filters to sparql query
Posted by Andy Seaborne <an...@apache.org>.
If you want plain java, the query builder module may help but IIRC it is
centred around buildign a query from scratch not modifying one.
That leaves 3 choices:
1/ Syntax tree manipulation
query.getQueryPattern
The topmost element of the WHERE clause wil be an ElementGroup. Create
an ElementFilter and add it to the group.
2/ Convert to the algebra, and walk down through the project and add a
OpFilter around the BGP. Call OpToQuery to get a query back. This is
more work for the simpel case but for more complicated changes, the
algebra can be easier to work with.
3/ Put in a FILTER(true) or FILTER("Spot this string") to start with as
a marker to be changed and use
org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps
to rewrite it to the thing you want.
Note that syntaxtransform apply to the whole abstract syntax tree so be
careful not to rewrite other things on more complicated queries.
If it is this simple case shown, (1) is easiest. It depends on how
complicated it will get later.
And
On 14/09/16 15:09, Bart van Leeuwen wrote:
> I would prefer plain Jena
>
> Met Vriendelijke Groet / With Kind Regards
> Bart van Leeuwen
>
> ##############################################################
> # twitter: @semanticfire
> # netage.nl
> # http://netage.nl
> # Esdoornstraat 3
> # 3461ER Linschoten
> # tel. +31(0)6-53182997
> ##############################################################
>
>
>
> From: Martynas Juseviius <ma...@graphity.org>
> To: users@jena.apache.org
> Date: 14-09-2016 15:20
> Subject: Re: Programatically adding filters to sparql query
>
>
>
> Are you able to use SPIN or does it have to be plain Jena?
>
> On Wed, 14 Sep 2016 at 16:08, Bart van Leeuwen
> <ba...@netage.nl>
> wrote:
>
>> Hi,
>>
>> I'm looking for some documentation on adding additional filters to a
>> parsed sparql query
>>
>> I can do:
>>
>> Query q = new Query('select ?s ?p ?o where { ?s a sem:Event . ?s ?p ?o
>> }');
>>
>> now I'd like to use the Query object Q to extend this query with a
> FIlter
>> clause.
>>
>> any documentation pointers are appreciated.
>>
>> Met Vriendelijke Groet / With Kind Regards
>> Bart van Leeuwen
>>
>> ##############################################################
>> # twitter: @semanticfire
>> # netage.nl
>> # http://netage.nl
>> # Esdoornstraat 3
>> # 3461ER Linschoten
>> # tel. +31(0)6-53182997
>> ##############################################################
>
>
>
Re: Programatically adding filters to sparql query
Posted by Bart van Leeuwen <ba...@netage.nl>.
I would prefer plain Jena
Met Vriendelijke Groet / With Kind Regards
Bart van Leeuwen
##############################################################
# twitter: @semanticfire
# netage.nl
# http://netage.nl
# Esdoornstraat 3
# 3461ER Linschoten
# tel. +31(0)6-53182997
##############################################################
From: Martynas Jusevičius <ma...@graphity.org>
To: users@jena.apache.org
Date: 14-09-2016 15:20
Subject: Re: Programatically adding filters to sparql query
Are you able to use SPIN or does it have to be plain Jena?
On Wed, 14 Sep 2016 at 16:08, Bart van Leeuwen
<ba...@netage.nl>
wrote:
> Hi,
>
> I'm looking for some documentation on adding additional filters to a
> parsed sparql query
>
> I can do:
>
> Query q = new Query('select ?s ?p ?o where { ?s a sem:Event . ?s ?p ?o
> }');
>
> now I'd like to use the Query object Q to extend this query with a
FIlter
> clause.
>
> any documentation pointers are appreciated.
>
> Met Vriendelijke Groet / With Kind Regards
> Bart van Leeuwen
>
> ##############################################################
> # twitter: @semanticfire
> # netage.nl
> # http://netage.nl
> # Esdoornstraat 3
> # 3461ER Linschoten
> # tel. +31(0)6-53182997
> ##############################################################
Re: Programatically adding filters to sparql query
Posted by Martynas Jusevičius <ma...@graphity.org>.
Are you able to use SPIN or does it have to be plain Jena?
On Wed, 14 Sep 2016 at 16:08, Bart van Leeuwen <ba...@netage.nl>
wrote:
> Hi,
>
> I'm looking for some documentation on adding additional filters to a
> parsed sparql query
>
> I can do:
>
> Query q = new Query('select ?s ?p ?o where { ?s a sem:Event . ?s ?p ?o
> }');
>
> now I'd like to use the Query object Q to extend this query with a FIlter
> clause.
>
> any documentation pointers are appreciated.
>
> Met Vriendelijke Groet / With Kind Regards
> Bart van Leeuwen
>
> ##############################################################
> # twitter: @semanticfire
> # netage.nl
> # http://netage.nl
> # Esdoornstraat 3
> # 3461ER Linschoten
> # tel. +31(0)6-53182997
> ##############################################################