SPARQL examples for /programmes

Introduction

This document gives a mapping from BBC /programmes URLs to corresponding SPARQL queries on the /programmes SPARQL end-point.

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 http://dbtune.org/bbc/programmes/snorql/

Queries related to genres (/programmes/genres):

Lists all items in the po:Genre scheme:

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}

Results available by getting this URI.


Describes all items in the po:Genre scheme:

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}

Results available by getting this URI.


Describes the genre identified by http://www.bbc.co.uk/programmes/genres/childrens:

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}

Results available by getting this URI.


Lists all episodes associated to a particular genre, identified by http://www.bbc.co.uk/programmes/genres/childrens

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}

Results available by getting this URI.


Lists all episodes associated to two genres:

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
}

Results available by getting this URI.


Queries related to formats (/programmes/formats):

Lists all formats

PREFIX po: <http://purl.org/ontology/po/>
DESCRIBE po:format

Results available by getting this URI


Lists all episodes in a particular format

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

Results available by getting this URI.


Broadcast time queries

Every title of every episode broadcasted after the 22nd of November 2007, 12:35:

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)
}

Note that results are truncated due to a LIMIT parameter on the server. The query first retrieves all broadcasts (this is limited to the first 2000 results) and then the results are truncated according to the FILTER condition


Every broadcast time of episodes of a particular brand (here, How I Met Your Mother)

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

Results available by getting this URI.

Recommendation queries

From a seed episode, http://dbtune.org/bbc/programmes/resource/episode/1001, give me all relevant episodes (shared tags)

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
}

Results available by getting this URI.

Same things, but with the /programmes homepage, and the name of the tag being shared:

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
}

Results available by getting this URI.


Give me episodes from the same genre as a particular one, with a broadcast time after the 22nd of November, 2007

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)
}

Results available by getting this URI.


Pairs of different brands starring a similar actor (using DBPedia)

select ?brand1 ?brand2 ?person 
where {
?brand1 p:starring ?person.
?brand2 p:starring ?person.
FILTER (?brand1 != ?brand2)
}

Other

Mention all locations associated to known services

PREFIX po: <http://purl.org/ontology/po/>
DESCRIBE ?geo 
WHERE 
{
?service a po:Service; po:location ?geo
}

Results available by getting this URI.