Skip to content

Instantly share code, notes, and snippets.

@northernjamie
Created January 4, 2017 11:52
Show Gist options
  • Save northernjamie/fd28909458cd7d2d500e8f7575ee018b to your computer and use it in GitHub Desktop.
Save northernjamie/fd28909458cd7d2d500e8f7575ee018b to your computer and use it in GitHub Desktop.
Big UNION SPARQL to combine different indicators at Local Authority level to create a correlation matrix in R
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/concept#>
PREFIX data: <http://statistics.gov.scot/data/>
PREFIX sdmxd: <http://purl.org/linked-data/sdmx/2009/dimension#>
PREFIX mp: <http://statistics.gov.scot/def/measure-properties/>
PREFIX stat: <http://statistics.data.gov.uk/def/statistical-entity#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?areaname ?indicatorlabel ?yearname ?value
WHERE {
{?indicator qb:dataSet data:earnings-paygap ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2010> .
data:earnings-paygap rdfs:label ?indicatorlabel}
UNION
{?indicator qb:dataSet data:drug-related-discharge ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2015-2016> .
data:drug-related-discharge rdfs:label ?indicatorlabel}
UNION
{?indicator qb:dataSet data:age-at-first-birth ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/gregorian-interval/2005-01-01T00:00:00/P2Y> ;
<http://statistics.gov.scot/def/dimension/age> <http://statistics.gov.scot/def/concept/age/19-and-under> .
data:age-at-first-birth rdfs:label ?indicatorlabel}
UNION
{?indicator qb:dataSet data:dtp-pol-hib-uptake-by-24-months ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2015> ;
<http://statistics.gov.scot/def/dimension/indicator(dtpPolHibUptake)> <http://statistics.gov.scot/def/concept/indicator-dtp-pol-hib-uptake/percentage-vaccinated-against-dtp/pol/hib-by-24-months> .
data:dtp-pol-hib-uptake-by-24-months rdfs:label ?indicatorlabel}
UNION
{?indicator qb:dataSet data:crime-clear-up-rates;
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2012> ;
<http://statistics.gov.scot/def/dimension/crimeOrOffence> <http://statistics.gov.scot/def/concept/crime-or-offence/all-crime> .
data:crime-clear-up-rates rdfs:label ?indicatorlabel}
UNION
{?indicator qb:dataSet data:alcohol-related-discharge ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2015-2016> .
data:alcohol-related-discharge rdfs:label ?indicatorlabel} .
?indicator sdmxd:refArea ?area ;
sdmxd:refPeriod ?year ;
mp:ratio ?value .
?year rdfs:label ?yearname .
?area stat:code <http://statistics.gov.scot/id/statistical-entity/S12> ;
rdfs:label ?areaname ;
skos:notation ?areacode
}
ORDER BY ?areaname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment