Re: soliciting your favorite (public) SPARQL queries!

Hi Lee !

Here are queries demonstrating the use of SPARQL CONSTRUCT for data 
transformation between heterogeneous vocabularies. The following queries 
allow to transform FOAF resources into vCard ones:

PREFIX vCard: http://www.w3.org/2001/vcard-rdf/3.0#
PREFIX foaf: http://xmlns.com/foaf/0.1/

CONSTRUCT { ?X vCard:FN ?name . }
WHERE { ?X foaf:name ?name . FILTER isLiteral(?name) }

CONSTRUCT {?X vCard:N _:a .
            _:a vCard:Family ?fname .
            _:a vCard:Given ?gname .}
WHERE { ?X foaf:firstName ?gname .
         ?X foaf:surname ?fname . }

CONSTRUCT { ?X vCard:URL ?url . }
WHERE { ?X foaf:workplaceHomepage ?url . FILTER isURI(?url) }

CONSTRUCT { ?X vCard:URL ?url . }
WHERE { ?X foaf:homepage ?url . FILTER isURI(?url) }

CONSTRUCT { ?X vCard:TITLE ?title }
WHERE { ?X foaf:title ?title . FILTER ( isLiteral(?T1) }

CONSTRUCT { ?X vCard:ORG _:a .
             _:a vCard:Orgname ?name .
             _:a vCard:URL ?url . }
WHERE { ?X foaf:currentProject ?Y
         ?Y foaf:name ?name .
 ?Y foaf:homepage ?url . }

CONSTRUCT { ?X vCard:ORG _:a .
             _:a vCard:Orgname ?name .  }
WHERE { ?X foaf:Group ?Y
         ?Y foaf:name ?name . }

One can remark this is only a partial transformation. That's because the 
current SPARQL spec misses some features like aggregates and  individual 
generation. We would like for example to express the following CONSTRUCT 
queries:

CONSTRUCT { ?X vCard:TEL _:a .
             _:a rdf:value fn:substring(?T1,5) .
             _:a a http://www.w3.org/2001/vcard-rdf/3.0#voice }
WHERE { ?X foaf:phone ?T1 .
       FILTER ( isURI(?T1) )

Removing the "tel:" prefix of vCard:TEL, or

CONSTRUCT { ?X vCard:EMAIL _:a .
             _:a rdf:value fn:concat("mailto:",?email) .
             _:a a http://www.w3.org/2001/vcard-rdf/3.0#internet }
WHERE { ?X foaf:mbox ?email . }

adding the mailto: prefix to the vCard:EMAIL.

This is not possible in the current SPARQL spec. Our SPARQL++ [1] 
extension tackle this. Maybe a future recommendation ? ;)

Cheers,
François

[1]http://www.scharffe.fr/pub/sparql++-for-mapping-between-rdf-vocabularies-ODBASE-2007.pdf


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.
> 
> 
> 

Received on Thursday, 21 August 2008 13:23:01 UTC