SPARQL: { a UNION b } vs. vice versa

	Somehow, I would expect the two SPARQL queries below, with the
	only difference being the order of UNION patterns interchanged,
	to produce identical results irrespective of the graph being
	queried.

	However, as shown below, Rasqal's (Redland's) roqet(1) behaves
	differently when given these queries.

	The question is: what I did wrong?

	(NB: one of the UNION patterns never matches in this case, as
	the graph has no <http://example.com/> nodes.)

$ cat < +1286108641.sparql 

PREFIX mdp:  <uuid:699b3cf4-ce42-11df-b0c7-00195b7187be#>
PREFIX mdpc: <uuid:3749931e-ce46-11df-89dc-00195b7187be#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

CONSTRUCT {
    ?re mdpc:refinementTemplate ?t
} WHERE {
    {
        {
            ?re mdpc:refinementTemplate ?t
        } UNION {
            <http://example.com/> <http://example.com/#re> ?re .
            <http://example.com/> <http://example.com/#t>  ?t  .
        }
    }
    FILTER (bound (?re) && bound (?t))
}

$ cat < +1286108715.sparql 

PREFIX mdp:  <uuid:699b3cf4-ce42-11df-b0c7-00195b7187be#>
PREFIX mdpc: <uuid:3749931e-ce46-11df-89dc-00195b7187be#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

CONSTRUCT {
    ?re mdpc:refinementTemplate ?t
} WHERE {
    {
        {
            <http://example.com/> <http://example.com/#re> ?re .
            <http://example.com/> <http://example.com/#t>  ?t  .
        } UNION {
            ?re mdpc:refinementTemplate ?t
        }
    }
    FILTER (bound (?re) && bound (?t))
}

$ roqet -r turtle -D +1286107714.ttl +1286108641.sparql 
roqet: Querying from file +1286108641.sparql
roqet: Query has a graph result:
roqet: Total 10 triples
@base <file:///var/home/ivan/devel/d5p-modis/doc/examples/+1286108641.sparql> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix mdp: <uuid:699b3cf4-ce42-11df-b0c7-00195b7187be#> .
@prefix mdpc: <uuid:3749931e-ce46-11df-89dc-00195b7187be#> .

[]
    mdpc:refinementTemplate _:r10_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r1_graphid0_r1286092747r28491r11 .

[]
    mdpc:refinementTemplate _:r2_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r3_graphid0_r1286092747r28491r11 .

[]
    mdpc:refinementTemplate _:r4_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r5_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r6_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r7_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r8_graphid0_r1286092747r28491r16 .

[]
    mdpc:refinementTemplate _:r9_graphid0_r1286092747r28491r16 .

$ roqet -r turtle -D +1286107714.ttl +1286108715.sparql 
roqet: Querying from file +1286108715.sparql
roqet: Query has a graph result:
roqet: Total 0 triples
@base <file:///var/home/ivan/devel/d5p-modis/doc/examples/+1286108715.sparql> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix mdp: <uuid:699b3cf4-ce42-11df-b0c7-00195b7187be#> .
@prefix mdpc: <uuid:3749931e-ce46-11df-89dc-00195b7187be#> .

$ 

-- 
FSF associate member #7257

Received on Monday, 4 October 2010 06:48:17 UTC