Re: negation as failure

[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?

SELECT * WHERE {
   ?a <r> ?b .
   ?b <s> ?c .
   OPTIONAL { ?a <s> ?c2 . FILTER (?c = ?c2) }
   FILTER(!bound(?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.

Lee

> Thanks,
>
> Matthew

Received on Monday, 2 August 2010 18:03:22 UTC