Skip to content

Instantly share code, notes, and snippets.

View northernjamie's full-sized avatar

Jamie Whyte northernjamie

  • Propolis Open Data Factory
  • Manchester, UK
View GitHub Profile
@northernjamie
northernjamie / SCOTSTAT_Google_Chart_Demo_Full_Code.html
Last active June 9, 2019 20:23
All code needed to generate a basic webpage and google chart using a SPARQL query from scot.stat.gov
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script type="text/javascript">
//Set the url of the SPARQL endpoint
var url = 'http://statistics.gov.scot/sparql.json';
@northernjamie
northernjamie / ODC_JS_Google_Chart_demo_rough_sleep_2.js
Last active December 7, 2017 09:52
Javascript for making simple 2 series google chart from Open Data Communities data using the SPARQL API
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script type="text/javascript">
//Set the url of the SPARQL endpoint
var url = 'http://opendatacommunities.org/sparql.json';
var odc_query_compare = 'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?periodlabel ?countb ?countm WHERE { ?obsm <http://purl.org/linked-data/cube#dataSet> <http://opendatacommunities.org/data/homelessness/rough-sleeping/count> ; <http://opendatacommunities.org/def/ontology/geography/refArea> <http://opendatacommunities.org/id/geography/administration/md/E08000003> ; <http://opendatacommunities.org/def/ontology/time/refPeriod> ?perioduri ; <http://opendatacommunities.org/def/ontology/homelessness/roughSleepingObs> ?countm . <http://opendatacommunities.org/id/geography/administration/md/E08000003> rdfs:label ?aream . ?obsb <http://purl.org/linked-data/cube#dataSet> <http://opendatacommunities.or
@northernjamie
northernjamie / ODC_JS_Google_Chart_demo_rough_sleep_1.js
Last active December 5, 2017 11:36
Javascript for making simple 1 series google chart from Open Data Communities data using the SPARQL API
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script type="text/javascript">
//Set the url of the SPARQL endpoint
var url = 'http://opendatacommunities.org/sparql.json';
// SPARQL query
var odc_query = 'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?periodlabel ?count WHERE { ?obs <http://purl.org/linked-data/cube#dataSet> <http://opendatacommunities.org/data/homelessness/rough-sleeping/count> . ?obs <http://opendatacommunities.org/def/ontology/geography/refArea> <http://opendatacommunities.org/id/geography/administration/ctry/E92000001> . ?obs <http://opendatacommunities.org/def/ontology/time/refPeriod> ?perioduri . ?obs <http://opendatacommunities.org/def/ontology/homelessness/roughSleepingObs> ?count . ?perioduri rdfs:label ?periodlabel .} ORDER BY ?periodlabel';
@northernjamie
northernjamie / ODC_SPARQL_GChart_Demo.SPARQL
Last active January 29, 2018 14:58
ODC Query to power google chart - rough sleeper counts in Manchester and Brighton over time
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?periodlabel ?valueb ?valuem
WHERE {
#First block.
#Constrain triples to the rough sleeping count dataset
?obsm <http://purl.org/linked-data/cube#dataSet> <http://opendatacommunities.org/data/homelessness/rough-sleeping/count> ;
#Constrain to Manchester
<http://opendatacommunities.org/def/ontology/geography/refArea> <http://opendatacommunities.org/id/geography/administration/md/E08000003> ;
@northernjamie
northernjamie / ODC_SPARQL_Get_Latest_Obs.SPARQL
Created November 14, 2017 16:34
OpenDataCommunities SPARQL query to get the latest observation for each area from a dataset. Uses subquery, aggregation and regex filter
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?value ?areaname ?latestyear
WHERE { ?s ?p <http://opendatacommunities.org/data/homelessness/rough-sleeping/count>;
{ SELECT ?areacode (max (?year) as ?latestyear)
WHERE {
?s ?p <http://opendatacommunities.org/data/homelessness/rough-sleeping/count> ;
<http://opendatacommunities.org/def/ontology/time/refPeriod>/rdfs:label ?year ;
<http://opendatacommunities.org/def/ontology/geography/refArea> ?areacode .
}
GROUP BY ?areacode
@northernjamie
northernjamie / ODC_DQ_Check_NextUpdate.SPARQL
Created October 31, 2017 10:29
Data quality check on Open Data Communities to check for datasets with no Next Update Date
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX pmd: <http://publishmydata.com/def/dataset#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?DatasetName ?URL WHERE {
?URL ?p pmd:Dataset .
?URL rdfs:label ?DatasetName .
OPTIONAL { ?URL pmd:nextUpdateDue ?update }
FILTER(!BOUND(?update))
@northernjamie
northernjamie / ODC_DQ_Check_Email.SPARQL
Last active October 31, 2017 10:28
Data quality check on Open Data Communities to check if non-deprecated datasets should have a contact email address
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX pmd: <http://publishmydata.com/def/dataset#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?Datasetname ?URL WHERE {
?URL ?p pmd:Dataset .
?URL rdfs:label ?Datasetname .
OPTIONAL { ?URL pmd:contactEmail ?email }
FILTER(!BOUND(?email))
@northernjamie
northernjamie / ODC_DQ_Check_Licence.SPARQL
Created October 31, 2017 10:13
Check for data quality issues on Open Data Communities. Datasets without a licence, excluding deprecated datasets
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX pmd: <http://publishmydata.com/def/dataset#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?name ?s WHERE {
?s ?p pmd:Dataset .
?s rdfs:label ?name .
OPTIONAL { ?s dcterms:license ?license }
FILTER(!BOUND(?license))
@northernjamie
northernjamie / ODC_DQ_Check_Licence.SPARQL
Created October 31, 2017 10:13
Check for data quality issues on Open Data Communities. Datasets without a licence, excluding deprecated datasets
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX pmd: <http://publishmydata.com/def/dataset#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?name ?s WHERE {
?s ?p pmd:Dataset .
?s rdfs:label ?name .
OPTIONAL { ?s dcterms:license ?license }
FILTER(!BOUND(?license))
@northernjamie
northernjamie / NHS_trusts_with_sample_indicator_lat_long.sparql
Created August 15, 2017 15:50
NHS Debug list trusts with an example indicator value for testing dataviz
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?orgname ?orgnacs ?lat ?long ?value
WHERE {
?org rdf:type ?orgtype .
?org rdfs:label ?orgname .
?org <http://opendata.nhs.uk/def/nacsCode> ?orgnacs .
?orgtype rdfs:label ?orgtypelabel .