Re: Union in Construct

On 17/06/2010 10:33, Buikstra, A.P.F. wrote:
> Hi guys,
>
> I’m using a construct query to extract a specific portion of RDF from
> LDSR. I’m creating these queries automatically, by the following
> transformation:
>
> Select ?a
>
> Where { ?a ?b ?c }
>
> ->
>
> Construct {?a ?b ?c}
>
> Where {?a ?b ?c}
>
> There are a few trivialities, such as Filters which have to be removed,
> but this turned out not to be an issue. The problem is when Union comes
> into the were, the idea no longer works:
>
> Construct { {?a ?b ?c} UNION {?a ?d ?c}}
>
> Where { {?a ?b ?c} UNION {?a ?d ?c}}
>
> Would give an error.
>
> My question is, can I just do:
>
> Construct { ?a ?b ?c .
>
> ?a ?d ?c}
>
> Where { {?a ?b ?c} UNION {?a ?d ?c}}
>
> It seems to work okay, but it doesn’t feel completely right. It comes
> down to whether the engine would try to construct both -?a ?b ?c- and
> -?a ?d ?c- given the data, or either. Is there a better way to tackle my
> problem?
>
> All help appreciated!
>
> Arjon Buikstra
>
> (Working with Larkc at the VU and MPIB)


The "CONSTRUCT { ?a ?b ?c . ?a ?d ?c}" works in this case because there 
is a variable in one side and not the other.  That means either ?a ?b ?c 
or ?a ?d ?c in the CONSTRUCT has an unbound variable and so the triple 
generation is for this triple (not the other one) is skipped.

This does not generalise (as you found with FILTER) but you can do some 
things with multiple constructs for each branch of the union and if the 
union is nested you need be able to rewrite into a disjunctive normal form.

	Andy

Received on Thursday, 17 June 2010 15:36:50 UTC