Re: soliciting your favorite (public) SPARQL queries!

Tackling the question from the more theoretical side,
I like non-monotonic SPARQL queries like the ones modeling set difference.

E.g.
"Give me all persons *without* an email address" in a certain FOAF graph.


i) It is already folklore, that you can do that with using the !bound() 
filter outside an optional, i.e.

SELECT ?X
FROM G
WHERE { ?X a foaf:Person
         OPTIONAL { ?X foaf:mbox ?M}
         FILTER (! bound(?X) ) }


ii) What some people might find surprising is that I can achieve the 
same result without using a FILTER, more generally that I can express

SELECT ?X
FROM G
FROM NAMED <boundchecker.rdf>
WHERE
   {
     { ?X a foaf:Person OPTIONAL{ ?X foaf:mbox ?M} }
     GRAPH <boundchecker.rdf>{ ?M :is :unbound }
   }

where <boundchecker.rdf> is the graph containing the single triple

    _:b :is :unbound.

Maybe requires some thinking, but is a nice example :-)

(Short explanation: the blanknode in Graph <boundchecker.rdf> only 
matches to unbound variables from the optional patttern. Note that 
non-well-designed OPTIONAL patterns are not commutative, see [1].
Actually, [1] "kind of" conjectured that non-well-designed patterns are 
useless, but - as this query shows - they aren't really entirely useless.)

Axel

1. http://iswc2006.semanticweb.org/items/Arenas2006bv.pdf


p.s.: Since I didn't see a similar one before, I claim copyright for 
that one, basically, it is very easily generalizable to model arbitrary 
queries  SELECT ... P WITHOUT P'
  ;-)


Lee Feigenbaum wrote:
> Hi everyone,
> 
> I'm putting together a "SPARQL by Example" tutorial, which is, as the 
> name suggests, a step-by-step introduction to SPARQL taught almost 
> entirely through complete, runnable SPARQL queries.
> 
> So far, I've gathered a great deal of example queries myself, but I know 
> that many subscribers to these lists probably have favorite queries of 
> their own that you might be willing to share with me.
> 
> I'm looking for:
> 
> 1) SPARQL queries
> 2) ...that can be run by anyone (no private data sets)
> 3a)...either by running the query against a public SPARQL endpoint
> 3b)...or by using a public SPARQL endpoint that will fetch 
> HTTP-accessible RDF data (e.g. sparql.org or demo.openlinksw.com)
> 4) ...that answers a real* question
> 5) ...and that is fun!**
> 
> * real is in the eye of the beholder, I imagine, but I'm not looking for 
>  "finds the predicates that relate ex:s and ex:o in this sample RDF graph"
> 
> ** fun is also in the eye of the beholder. fun can be a query on fun 
> data; a clever query that may illustrate a particular SPARQL construct 
> ("trick"); a query that integrates interesting information; a query with 
> surprising results; etc.
> 
> thanks to anyone who is able to contribute!
> Lee
> 
> PS I plan to make the tutorial slides available online under an 
> appropriate CC license once they are completed.


-- 
Dr. Axel Polleres, Digital Enterprise Research Institute (DERI)
email: axel.polleres@deri.org  url: http://www.polleres.net/

Everything is possible:
rdfs:subClassOf rdfs:subPropertyOf rdfs:Resource.
rdfs:subClassOf rdfs:subPropertyOf rdfs:subPropertyOf.
rdf:type rdfs:subPropertyOf rdfs:subClassOf.
rdfs:subClassOf rdf:type owl:SymmetricProperty.

Received on Thursday, 21 August 2008 15:52:06 UTC