Re: Simple example of need for negation operator

Bob MacGregor wrote:
> Once upon a time, there was speculation that the the combination of 
> SPARQL's OPTIONAL and UNBOUND
> operators are adequate to emulate a negation-as-failure operator.  
> Previously, we produced examples
> that contradicted that claim.   Here is another such example, which is 
> relatively simple, of a query that
> (I believe) one cannot express in SPARQL.  It comes out of a real 
> application we are implementing for a client, i.e.,
> its a use case. 
> 
> The application involves attaching tags to resources that specify the 
> time of first use.  In other words,
> until the time specified has passed, the resource should not be 
> retrievable.  In the application, updates
> are distributed across triple stores, and the tags serve to insure that 
> newly updated resources will be visible
> at the same time across the distributed stores.  It can happen that a 
> resource is tagged more
> than once (since it may be updated more than once).  Below is a query 
> that retrieves only Articles
> such that none of their time tags has a newer time than the present 
> (phrased in a SPARQL-like
> syntax):
> 
> SELECT ?a
> FROM model
> WHERE
>      (?a rdf:type ft:Article) AND
>      UNSAID ((?a ex:timetag ?time) AND
>                    (?time > $NOW))
> 
> This query can also be phrased without difficulty in SQL.  If anyone 
> knows how to
> express this in SPARQL, I'd like to see the solution.

Hi Bob,

In SPARQL, this query is (unedited, untested):

SELECT ?a
FROM :model
WHERE {
   ?a rdf:type ft:article ; ex:timetag ?maxtime .
   OPTIONAL { ?a ex:timetag ?othertime . FILTER(?othertime > ?maxtime) }
   FILTER (!bound(?othertime) && ?maxtime > '...now...')
}

Negation / universal quantification is not pretty in SPARQL, but it can 
usually be done.

I'm CC'ing public-sparql-dev@w3.org, which is a more appropriate list 
for 'how-to' questions about SPARQL.

thanks,
Lee

Received on Tuesday, 11 December 2007 05:40:25 UTC