Mercurial > hg > dbtune-site
view onto/doc/sparql_mapping.html @ 19:1e79ce3ff5f5 tip
Simplify and cut some non-working resource paths
author | Chris Cannam |
---|---|
date | Wed, 08 Nov 2017 15:27:23 +0000 |
parents | 1e44d666ced1 |
children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <link rel="meta" type="application/rdf+xml" title="FOAF" href="http://moustaki.org/foaf.rdf#moustaki" /> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Yves Raimond" /> <link href="style.css" rel="stylesheet" type="text/css" /><meta name="robots" content="all" /> <title>/programmes SPARQL examples</title> </head> <body><div class="page"> <h1>SPARQL examples for /programmes</h1> <h2>Introduction</h2> <p>This document gives a mapping from <a href="http://bbc.co.uk/programmes/">BBC /programmes</a> URLs to corresponding SPARQL queries on the <a href=http://dbtune.org/bbc/programmes/">/programmes SPARQL end-point</a>.</p> <p><b>Note: to be tested in a nice environment (and not get raw xml back), these queries can be copy/pasted in the SNORQL service set up at <a href="http://dbtune.org/bbc/programmes/snorql/">http://dbtune.org/bbc/programmes/snorql/</a></b></p> <h3>Queries related to genres (/programmes/genres):</h3> <p><i>Lists</i> all items in the <b>po:Genre</b> scheme:</p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> CONSTRUCT {?genre a skos:Concept} WHERE {?genre skos:inScheme po:Genre} </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20PREFIX%20skos%3A%20%3Chttp%3A//www.w3.org/2004/02/skos/core%23%3E%20construct%20%7B%3Fgenre%20a%20skos%3AConcept%7D%20where%20%7B%3Fgenre%20skos%3AinScheme%20po%3AGenre%7D">getting this URI</a>.</p> <hr/> <p><i>Describes</i> all items in the <b>po:Genre</b> scheme:</p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> CONSTRUCT {?genre ?p ?o} WHERE {?genre skos:inScheme po:Genre;?p ?o} </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20PREFIX%20skos%3A%20%3Chttp%3A//www.w3.org/2004/02/skos/core%23%3E%20construct%20%7B%3Fgenre%20%3Fb%20%3Fc%7D%20where%20%7B%3Fgenre%20skos%3AinScheme%20po%3AGenre%3B%3Fb%20%3Fc%7D">getting this URI</a>.</p> <hr/> <p><i>Describes</i> the genre identified by <i>http://www.bbc.co.uk/programmes/genres/childrens</i>:</p> <pre> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT {?genre ?p ?o} WHERE {?genre foaf:homepage <http://www.bbc.co.uk/programmes/genres/childrens>;?p ?o} </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20foaf%3A%20%3Chttp%3A//xmlns.com/foaf/0.1/%3E%20CONSTRUCT%20%7B%3Fgenre%20%3Fp%20%3Fo%7D%20WHERE%20%7B%3Fgenre%20foaf%3Ahomepage%20%3Chttp%3A//www.bbc.co.uk/programmes/genres/childrens%3E%3B%3Fp%20%3Fo%7D">getting this URI</a>.</p> <hr/> <p><i>Lists</i> all episodes associated to a particular genre, identified by <i>http://www.bbc.co.uk/programmes/genres/childrens</i></p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT {?episode po:genre ?genre} WHERE {?genre foaf:homepage <http://www.bbc.co.uk/programmes/genres/childrens>. ?version po:genre ?genre. ?episode po:version ?version} </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20PREFIX%20foaf%3A%20%3Chttp%3A//xmlns.com/foaf/0.1/%3E%20CONSTRUCT%20%7B%3Fepisode%20po%3Agenre%20%3Fgenre%7D%20WHERE%20%7B%3Fgenre%20foaf%3Ahomepage%20%3Chttp%3A//www.bbc.co.uk/programmes/genres/childrens%3E.%20%3Fversion%20po%3Agenre%20%3Fgenre.%20%3Fepisode%20po%3Aversion%20%3Fversion%7D">getting this URI</a>.</p> <hr/> <p><i>Lists</i> all episodes associated to two genres:</p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT {?episode po:genre ?genre1; po:genre ?genre2} WHERE { ?genre1 foaf:homepage <http://www.bbc.co.uk/programmes/genres/childrens>. ?genre2 foaf:homepage <http://www.bbc.co.uk/programmes/genres/factual>. ?version po:genre ?genre1, ?genre2. ?episode po:version ?version } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20PREFIX%20foaf%3A%20%3Chttp%3A//xmlns.com/foaf/0.1/%3E%20CONSTRUCT%20%7B%3Fepisode%20po%3Agenre%20%3Fgenre1%3B%20po%3Agenre%20%3Fgenre2%7D%20WHERE%20%7B%3Fgenre1%20foaf%3Ahomepage%20%3Chttp%3A//www.bbc.co.uk/programmes/genres/childrens%3E.%20%3Fgenre2%20foaf%3Ahomepage%20%3Chttp%3A//www.bbc.co.uk/programmes/genres/factual%3E.%20%3Fversion%20po%3Agenre%20%3Fgenre1%2C%20%3Fgenre2.%20%3Fepisode%20po%3Aversion%20%3Fversion%7D">getting this URI</a>.</p> <hr/> <h3>Queries related to formats (/programmes/formats):</h3> <p><i>Lists</i> all formats</p> <pre> PREFIX po: <http://purl.org/ontology/po/> DESCRIBE po:format </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20DESCRIBE%20po%3Aformat">getting this URI</a></p> <hr/> <p><i>Lists</i> all episodes in a particular format</p> <pre> PREFIX po: <http://purl.org/ontology/po/> CONSTRUCT {?episode po:format <http://dbtune.org/bbc/programmes/resource/format/18>} WHERE {?episode po:version ?version. ?version po:format <http://dbtune.org/bbc/programmes/resource/format/18>} </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20CONSTRUCT%20%7B%3Fepisode%20po%3Aformat%20%3Chttp%3A//dbtune.org/bbc/programmes/resource/format/18%3E%7D%20WHERE%20%7B%3Fepisode%20po%3Aversion%20%3Fversion.%20%3Fversion%20po%3Aformat%20%3Chttp%3A//dbtune.org/bbc/programmes/resource/format/18%3E%7D">getting this URI</a>.</p> <hr/> <h3>Broadcast time queries</h3> <p>Every title of every episode broadcasted after the 22nd of November 2007, 12:35:</p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#> PREFIX event: <http://purl.org/NET/c4dm/event.owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?title ?start ?end WHERE { ?ep dc:title ?title. ?ep po:version ?v. ?bc po:broadcast_of ?v. ?bc event:time ?t. ?t tl:start ?start. ?t tl:end ?end. FILTER (?start > "2007-10-22T12:35:00Z"^^xsd:dateTime) } </pre> <p><b>Note that results are truncated due to a LIMIT parameter on the server.</b> The query first retrieves all broadcasts (this is limited to the first 2000 results) <b>and then</b> the results are truncated according to the FILTER condition</p> <hr/> <p>Every broadcast time of episodes of a particular brand (here, <i>How I Met Your Mother</i>)</p> <pre> PREFIX po: <http://purl.org/ontology/po/> PREFIX event: <http://purl.org/NET/c4dm/event.owl#> DESCRIBE ?bct WHERE { <http://dbtune.org/bbc/programmes/resource/brand/906> po:episode ?ep. ?ep po:version ?v. ?bc po:broadcast_of ?v. ?bc event:time ?bct. } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20PREFIX%20event%3A%20%3Chttp%3A//purl.org/NET/c4dm/event.owl%23%3E%20DESCRIBE%20%3Fbct%20WHERE%20%7B%3Chttp%3A//dbtune.org/bbc/programmes/resource/brand/906%3E%20po%3Aepisode%20%3Fep.%20%3Fep%20po%3Aversion%20%3Fv.%20%3Fbc%20po%3Abroadcast_of%20%3Fv.%20%3Fbc%20event%3Atime%20%3Fbct.%7D%0A">getting this URI</a>.</p> <h3>Recommendation queries</h3> <p>From a seed episode, <i>http://dbtune.org/bbc/programmes/resource/episode/1001</i>, give me all relevant episodes (shared tags)</p> <pre> PREFIX tags: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/> PREFIX po: <http://purl.org/ontology/po/> SELECT ?recommended WHERE { <http://dbtune.org/bbc/programmes/resource/episode/40657> tags:tag ?seedtagging. ?seedtagging tags:associatedTag ?seedtag. ?recommended tags:tag ?tagging. ?tagging tags:associatedTag ?seedtag } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20tags%3A%20%3Chttp%3A//www.holygoat.co.uk/owl/redwood/0.1/tags/%3E%20PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20SELECT%20%3Frecommended%20WHERE%20%7B%3Chttp%3A//dbtune.org/bbc/programmes/resource/episode/40657%3E%20tags%3Atag%20%3Fseedtagging.%20%3Fseedtagging%20tags%3AassociatedTag%20%3Fseedtag.%20%3Frecommended%20tags%3Atag%20%3Ftagging.%20%3Ftagging%20tags%3AassociatedTag%20%3Fseedtag%7D">getting this URI</a>.</p> <p>Same things, but with the /programmes homepage, and the name of the tag being shared:</p> <pre> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX tags: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/> PREFIX po: <http://purl.org/ontology/po/> SELECT ?recprog ?title WHERE { <http://dbtune.org/bbc/programmes/resource/episode/40657> tags:tag ?seedtagging. ?seedtagging tags:associatedTag ?seedtag. ?seedtag dc:title ?title. ?recommendedep tags:tag ?tagging. ?recommendedep foaf:homepage ?recprog. ?tagging tags:associatedTag ?seedtag } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20foaf%3A%20%3Chttp%3A//xmlns.com/foaf/0.1/%3E%20PREFIX%20dc%3A%20%3Chttp%3A//purl.org/dc/elements/1.1/%3E%20PREFIX%20tags%3A%20%3Chttp%3A//www.holygoat.co.uk/owl/redwood/0.1/tags/%3E%20PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20SELECT%20%3Frecprog%20%3Ftitle%20WHERE%20%7B%3Chttp%3A//dbtune.org/bbc/programmes/resource/episode/40657%3E%20tags%3Atag%20%3Fseedtagging.%20%3Fseedtagging%20tags%3AassociatedTag%20%3Fseedtag.%3Fseedtag%20dc%3Atitle%20%3Ftitle.%3Frecommendedep%20tags%3Atag%20%3Ftagging.%20%3Frecommendedep%20foaf%3Ahomepage%20%3Frecprog.%3Ftagging%20tags%3AassociatedTag%20%3Fseedtag%7D">getting this URI</a>.</p> <hr/> <p>Give me episodes from the same genre as a particular one, with a broadcast time after the 22nd of November, 2007</p> <pre> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX po: <http://purl.org/ontology/po/> PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#> PREFIX event: <http://purl.org/NET/c4dm/event.owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?ep ?title ?start WHERE { <http://dbtune.org/bbc/programmes/resource/episode/40657> po:version ?seedversion. ?seedversion po:genre ?genre. ?version po:genre ?genre. ?recprog po:version ?version. ?recprog dc:title ?title. ?recprog foaf:homepage ?ep. ?bc po:broadcast_of ?version. ?bc event:time ?t. ?t tl:start ?start. FILTER (?start > "2007-11-22T12:00:00Z"^^xsd:dateTime) } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20foaf%3A%20%3Chttp%3A//xmlns.com/foaf/0.1/%3E%0APREFIX%20dc%3A%20%3Chttp%3A//purl.org/dc/elements/1.1/%3E%0APREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%0APREFIX%20tl%3A%20%3Chttp%3A//purl.org/NET/c4dm/timeline.owl%23%3E%0APREFIX%20event%3A%20%3Chttp%3A//purl.org/NET/c4dm/event.owl%23%3E%0APREFIX%20xsd%3A%20%3Chttp%3A//www.w3.org/2001/XMLSchema%23%3E%0ASELECT%20%3Fep%20%3Ftitle%20%3Fstart%0AWHERE%20%7B%0A%3Chttp%3A//dbtune.org/bbc/programmes/resource/episode/40657%3E%20po%3Aversion%20%3Fseedversion.%0A%3Fseedversion%20po%3Agenre%20%3Fgenre.%0A%3Fversion%20po%3Agenre%20%3Fgenre.%0A%3Frecprog%20po%3Aversion%20%3Fversion.%0A%3Frecprog%20dc%3Atitle%20%3Ftitle.%0A%3Frecprog%20foaf%3Ahomepage%20%3Fep.%0A%3Fbc%20po%3Abroadcast_of%20%3Fversion.%0A%3Fbc%20event%3Atime%20%3Ft.%0A%3Ft%20tl%3Astart%20%3Fstart.%0AFILTER%20%28%3Fstart%20%3E%20%222007-11-22T12%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%0A%7D">getting this URI</a>.</p> <hr/> <p>Pairs of different brands starring a similar actor (using DBPedia)</p> <pre> select ?brand1 ?brand2 ?person where { ?brand1 p:starring ?person. ?brand2 p:starring ?person. FILTER (?brand1 != ?brand2) } </pre> <hr/> <h3>Other</h3> <p>Mention all locations associated to known services</p> <pre> PREFIX po: <http://purl.org/ontology/po/> DESCRIBE ?geo WHERE { ?service a po:Service; po:location ?geo } </pre> <p>Results available by <a href="http://dbtune.org/bbc/programmes/sparql?query=PREFIX%20po%3A%20%3Chttp%3A//purl.org/ontology/po/%3E%20DESCRIBE%20%3Fgeo%20WHERE%20%7B%3Fservice%20a%20po%3AService%3Bpo%3Alocation%20%3Fgeo%7D%0A">getting this URI</a>.</p> <hr/> </body> </html>