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: &lt;http://purl.org/ontology/po/&gt; 
PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt; 
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: &lt;http://purl.org/ontology/po/&gt; 
PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt;
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: &lt;http://xmlns.com/foaf/0.1/&gt; 
CONSTRUCT {?genre ?p ?o} 
WHERE 
{?genre foaf:homepage &lt;http://www.bbc.co.uk/programmes/genres/childrens&gt;;?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: &lt;http://purl.org/ontology/po/&gt; 
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt; 
CONSTRUCT {?episode po:genre ?genre} 
WHERE 
{?genre foaf:homepage &lt;http://www.bbc.co.uk/programmes/genres/childrens&gt;. ?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: &lt;http://purl.org/ontology/po/&gt; 
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt; 
CONSTRUCT {?episode po:genre ?genre1; po:genre ?genre2} 
WHERE 
{
	?genre1 foaf:homepage &lt;http://www.bbc.co.uk/programmes/genres/childrens&gt;. 
	?genre2 foaf:homepage &lt;http://www.bbc.co.uk/programmes/genres/factual&gt;. 
	?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: &lt;http://purl.org/ontology/po/&gt;
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: &lt;http://purl.org/ontology/po/&gt; 
CONSTRUCT {?episode po:format &lt;http://dbtune.org/bbc/programmes/resource/format/18&gt;} 
WHERE 
{?episode po:version ?version. ?version po:format &lt;http://dbtune.org/bbc/programmes/resource/format/18&gt;}
</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: &lt;http://purl.org/ontology/po/&gt;
PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX tl: &lt;http://purl.org/NET/c4dm/timeline.owl#&gt;
PREFIX event: &lt;http://purl.org/NET/c4dm/event.owl#&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
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 &gt; "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: &lt;http://purl.org/ontology/po/&gt;
PREFIX event: &lt;http://purl.org/NET/c4dm/event.owl#&gt;
DESCRIBE ?bct
WHERE
{
&lt;http://dbtune.org/bbc/programmes/resource/brand/906&gt; 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: &lt;http://www.holygoat.co.uk/owl/redwood/0.1/tags/&gt; 
PREFIX po: &lt;http://purl.org/ontology/po/&gt; 
SELECT ?recommended 
WHERE {
&lt;http://dbtune.org/bbc/programmes/resource/episode/40657&gt; 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: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX tags: &lt;http://www.holygoat.co.uk/owl/redwood/0.1/tags/&gt; 
PREFIX po: &lt;http://purl.org/ontology/po/&gt;
SELECT ?recprog ?title
WHERE {
&lt;http://dbtune.org/bbc/programmes/resource/episode/40657&gt; 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: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX po: &lt;http://purl.org/ontology/po/&gt;
PREFIX tl: &lt;http://purl.org/NET/c4dm/timeline.owl#&gt;
PREFIX event: &lt;http://purl.org/NET/c4dm/event.owl#&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
SELECT ?ep ?title ?start
WHERE {
&lt;http://dbtune.org/bbc/programmes/resource/episode/40657&gt; 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 &gt; "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: &lt;http://purl.org/ontology/po/&gt;
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>