List Info

Thread: Re: Simple example of need for negation operator




Re: Simple example of need for negation operator
country flaguser name
United States
2007-12-10 23:40:11
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-devw3.org, which is a more
appropriate list 
for 'how-to' questions about SPARQL.

thanks,
Lee


Re: Simple example of need for negation operator
user name
2007-12-11 01:09:30
Hi Lee,

OK, we'll try sparql dev, as long as this is a how to, rather than a "can't be
done".  But it looks to me like
your query returns no bindings if an article does not have a timetag.  I
say this because of the {?a ex:timetag ?maxtime} clause
that comes before the OPTIONAL.  But in that case, it should return
the article.  Can you fix this, or is it not expressible after all?

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...')
}

Original target:

SELECT ?a
FROM model
WHERE
     (?a rdf:type ft:Article) AND
   ;  UNSAID ((?a ex:timetag ?time) AND
   ;           ;     (?time > $NOW)) 

=====================================
Robert MacGregor
Chief Scientist
Siderean Software, Inc.
bob.macgregorgmail.com">bob.macgregorgmail.com
Mobile: 310-469-2810
=====================================
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )