Skip to content

Instantly share code, notes, and snippets.

@northernjamie
Last active January 9, 2017 12:03
Show Gist options
  • Save northernjamie/3da843c4dc825c1e858d0dbd0c517870 to your computer and use it in GitHub Desktop.
Save northernjamie/3da843c4dc825c1e858d0dbd0c517870 to your computer and use it in GitHub Desktop.
library(“SPARQL”, lib.loc=”/Library/Frameworks/R.framework/Versions/3.2/Resources/library”)
endpoint <- ‘http://statistics.gov.scot/sparql'
queryalc <- ‘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 ?areacode ?areaname ?nratioalcohol ?yearname
WHERE {
?indicator qb:dataSet data:alcohol-related-discharge ;
sdmxd:refArea ?area ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2012-2013> ;
mp:ratio ?nratioalcohol .
<http://reference.data.gov.uk/id/government-year/2012-2013> rdfs:label ?yearname .
?area stat:code <http://statistics.gov.scot/id/statistical-entity/S12> ;
rdfs:label ?areaname ;
skos:notation ?areacode .
}’
querydrug <- ‘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 ?areacode ?areaname ?nratiodrug ?yearname
WHERE {
?indicator qb:dataSet data:drug-related-discharge ;
sdmxd:refArea ?area ;
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2012-2013> ;
mp:ratio ?nratiodrug .
<http://reference.data.gov.uk/id/government-year/2012-2013> rdfs:label ?yearname .
?area stat:code <http://statistics.gov.scot/id/statistical-entity/S12> ;
rdfs:label ?areaname ;
skos:notation ?areacode .
}’
qdalc <- SPARQL(endpoint, queryalc)
qddrug <- SPARQL(endpoint, querydrug)
dfdrug <- qddrug$results
dfalc <- qdalc$results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment