W3C home > Mailing lists > Public > public-sparql-dev@w3.org > July to September 2010

Re: negation as failure

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Mon, 02 Aug 2010 14:02:44 -0400
Message-ID: <4C570844.8060306@thefigtrees.net>
To: Matthew Pocock <matthew.pocock@ncl.ac.uk>
CC: public-owl-dev@w3.org, "public-sparql-dev@w3.org" <public-sparql-dev@w3.org>
[copying public-sparql-dev@w3.org which is probably a good list for this]

On 8/2/2010 12:43 PM, Matthew Pocock wrote:
> Hi,
> Sorry in advance if this is not the right forum for this question. I
> didn't know where else to send it.
> I am trying to write a sparql query (sparql 1.0) that pulls back things
> where a triple is *not* asserted between two resources. So far, I've not
> been able to achieve this. I've seen the OPTIONAL/FILTER/!BOUND pattern
> <http://www.w3.org/TR/rdf-sparql-query/#func-bound> but I can only make
> this work for asserting that a resource does not exist, not for
> asserting that a triple is unsaid. The pattern I'm trying to encode is:
> select * where {
>    ?a <r> ?b .
>    ?b <s> ?c .
>    filter(unsaid { ?a <s> ?c })
> }
> where unsaid is true if the child expression doesn't match the graph.
> However, in sparql 1.0 there is no 'unsaid' function. I've tried a whole
> heap of optional/filter/!bound variations but simply can not get this
> expressed. I feel that this must be either a well-known unexpressible,
> or have a well-known kludge.

Does this do what you want?

   ?a <r> ?b .
   ?b <s> ?c .
   OPTIONAL { ?a <s> ?c2 . FILTER (?c = ?c2) }

The trick (kludge, if you want) is to introduce a new variable in the 
OPTIONAL, then assert that the variable is really identical to the 
existing variable, but then use the new variable for the !bound test 
outside of the OPTIONAL.


> Thanks,
> Matthew
Received on Monday, 2 August 2010 18:03:21 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:15:50 UTC