W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > January to March 2010

Re: Examples of MINUS and NOT EXISTS

From: Ivan Herman <ivan@w3.org>
Date: Wed, 31 Mar 2010 10:26:14 +0200
Cc: SPARQL Working Group <public-rdf-dawg@w3.org>
Message-Id: <3AA59252-D650-44FB-9047-E0EE913FB956@w3.org>
To: Andy Seaborne <andy.seaborne@talis.com>
Interesting. In my completely uninformed and intuitive expectation, NOT EXISTS 'feel' right for all three cases you quote. I am not sure how I would explain the one row in Query 2, for example.

Ivan

On Mar 30, 2010, at 14:46 , Andy Seaborne wrote:

> kasei gave an example of a query that was different under MINUS and NOT EXISTS.  I've used it to generate a number of cases to show here they are the same wand where different.  It reinforces Lee's characterization of the graph-centric and table-centric (resource-centic?) styles.
> 
> 
> http://www.w3.org/2009/sparql/docs/features/#Negation_description
> mentions testing whether a triples do or not do occur in the graph.
> 
> Query 2/3 is interesting: testing for the (non)existence of a specific triple:
> 
> The data is a single triple graph in all cases:
> 
> # Data -------
> @prefix : <http://example/> .
> 
> :a :b :c .
> # Data -------
> 
> 
> Query 2:
> { ?s ?p ?o NOT EXISTS { :a :b :c } } ==> no rows
> { ?s ?p ?o MINUS { :a :b :c } } ==> one row
> 
> Query 3:
> { ?s ?p ?o NOT EXISTS { :x :y :z } } ==> one row
> { ?s ?p ?o MINUS { :x :y :z } } ==> one row
> 
> This one is also a place where they differ:
> 
> Query 5:
> { ?s ?p ?o NOT EXISTS { ?x ?y ?z } } ==> no rows
> { ?s ?p ?o MINUS { ?x ?y ?z } } ==> one rows
> 
> These examples are mechanically produced with a simple implementation of each operation directly from the spec.  So, bugs not withstanding, we can analyse other examples systematically.
> 
> 	Andy
> 
> 
> 
> # -------- Query 1 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { ?s ?p ?o }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 1 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { ?s ?p ?o }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 2 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { :a :b :c }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 2 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { :a :b :c }
>  8   }
> # Results ----------------------------------
> ----------------
> | s  | p  | o  |
> ================
> | :a | :b | :c |
> ----------------
> 
> # -------- Query 3 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { :x :y :z }
>  8   }
> # Results ----------------------------------
> ----------------
> | s  | p  | o  |
> ================
> | :a | :b | :c |
> ----------------
> 
> # -------- Query 3 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { :x :y :z }
>  8   }
> # Results ----------------------------------
> ----------------
> | s  | p  | o  |
> ================
> | :a | :b | :c |
> ----------------
> 
> # -------- Query 4 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { ?s :b :c }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 4 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { ?s :b :c }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 5 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { ?x ?y ?z }
>  8   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 5 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { ?x ?y ?z }
>  8   }
> # Results ----------------------------------
> ----------------
> | s  | p  | o  |
> ================
> | :a | :b | :c |
> ----------------
> 
> # -------- Query 6 : NOT EXIST
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     NOT EXISTS
>  7       { ?s :b :c
>  8         FILTER ( ?s = :a )
>  9       }
> 10   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> # -------- Query 6 : MINUS
> # Query ------------------------------------
>  1 PREFIX  :     <http://example/>
>  2
>  3 SELECT  *
>  4 WHERE
>  5   { ?s ?p ?o
>  6     MINUS
>  7       { ?s :b :c
>  8         FILTER ( ?s = :a )
>  9       }
> 10   }
> # Results ----------------------------------
> -------------
> | s | p | o |
> =============
> -------------
> 
> 


----
Ivan Herman, W3C Semantic Web Activity Lead
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
PGP Key: http://www.ivan-herman.net/pgpkey.html
FOAF: http://www.ivan-herman.net/foaf.rdf







Received on Wednesday, 31 March 2010 08:24:51 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:42 GMT