W3C home > Mailing lists > Public > public-sparql-dev@w3.org > January to March 2008

Re: Is there a SPARQL way to...

From: Axel Polleres <axel.polleres@deri.org>
Date: Fri, 01 Feb 2008 21:32:57 +0000
Message-ID: <47A39009.9030003@deri.org>
To: Leigh Dodds <leigh@ldodds.com>
CC: Max Voelkel <voelkel@fzi.de>, public-sparql-dev@w3.org

Leigh Dodds wrote:
>> This should work:
>>
>> SELECT ?x {
>>    ?x a ex:A .
>>    OPTIONAL {
>>      ?x a ?type .
>>      FILTER(?type != ex:A)
>>    }
>>    FILTER(!bound(?type))
>> }
>>
>> The OPTIONAL here tries to find a different type for the same resource
>> (?x). If it succeeds then ?type is bound to a second class, so we filter
>> out that case at the top-level.
> 
> And it does. I just ran it twinkle and it produces the expected
> single result.
> 
> Nice work. I spent a long time scratching my head with that one.
> Didn't occur to me to split the FILTERs into the separate OPTIONAL
> patterns.
> 
> Fun!

I'm happy to see again that the widely hated (by some semantic Web 
purists at least) negation as failure proofs useful here!

SPARQL spec, section 11.4.1:

"One may test that a graph pattern is not expressed by specifying an 
OPTIONAL graph pattern that introduces a variable and testing to see 
that the variable is not bound. This is called Negation as Failure in 
logic programming."

  ;-) still a pitty that there is no more convenient way to express set 
difference in SPARQL, but at least it is possible and we see here that 
people really use this feature.

Axel



-- 
Dr. Axel Polleres
email: axel@polleres.net  url: http://www.polleres.net/

rdf:Resource owl:differentFrom xsd:anyURI .
Received on Friday, 1 February 2008 21:33:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 1 February 2008 21:33:12 GMT