Quick look at a test endpoint...
#Utility routines
from SPARQLWrapper import SPARQLWrapper, JSON
#Add some helper functions
def runQuery(endpoint,prefix,q):
''' Run a SPARQL query with a declared prefix over a specified endpoint '''
sparql = SPARQLWrapper(endpoint)
sparql.setQuery(prefix+q)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
import pandas as pd
pd.options.display.max_colwidth=150
def dict2df(results):
''' Hack a function to flatten the SPARQL query results and return the column values '''
data=[]
for result in results["results"]["bindings"]:
tmp={}
for el in result:
tmp[el]=result[el]['value']
data.append(tmp)
df = pd.DataFrame(data)
return df
def dfResults(endpoint,prefix,q):
''' Generate a data frame containing the results of running
a SPARQL query with a declared prefix over a specified endpoint '''
return dict2df( runQuery( endpoint, prefix, q ) )
def printQuery(results,limit=''):
''' Print the results from the SPARQL query '''
resdata=results["results"]["bindings"]
if limit!='': resdata=results["results"]["bindings"][:limit]
for result in resdata:
for ans in result:
print('{0}: {1}'.format(ans,result[ans]['value']))
print()
def printRunQuery(endpoint,prefix,q,limit=''):
''' Print the results from the SPARQL query '''
results=runQuery(endpoint,prefix,q)
printQuery(results,limit)
ENDPOINT='http://ons-pilot.publishmydata.com/sparql'
#Prefix from the example
PREFIX='''
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/concept#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
'''
Go fish...
q='''
SELECT * {
?a ?b ?c
} LIMIT 20
'''
df=dfResults(endpoint,prefix,q)
df
a | b | c | |
---|---|---|---|
0 | http://statistics.data.gov.uk/data/employment | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#DataSet |
1 | http://statistics.data.gov.uk/data/employment | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://publishmydata.com/def/dataset#Dataset |
2 | http://statistics.data.gov.uk/data/employment | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://publishmydata.com/def/dataset#LinkedDataset |
3 | http://statistics.data.gov.uk/data/employment | http://purl.org/linked-data/cube#structure | http://statistics.data.gov.uk/data/structure/employment |
4 | http://statistics.data.gov.uk/data/employment | http://publishmydata.com/def/dataset#graph | http://statistics.data.gov.uk/graph/employment |
5 | http://statistics.data.gov.uk/data/employment | http://www.w3.org/2000/01/rdf-schema#label | Employment |
6 | http://statistics.data.gov.uk/data/employment | http://purl.org/dc/terms/title | Employment |
7 | http://statistics.data.gov.uk/data/employment | http://purl.org/dc/terms/modified | 2016-04-19T02:00:00+02:00 |
8 | http://www.w3.org/1999/02/22-rdf-syntax-ns# | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Ontology |
9 | http://www.w3.org/1999/02/22-rdf-syntax-ns# | http://purl.org/dc/elements/1.1/title | The RDF Concepts Vocabulary (RDF) |
10 | http://www.w3.org/1999/02/22-rdf-syntax-ns# | http://purl.org/dc/elements/1.1/description | This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts. |
11 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/1999/02/22-rdf-syntax-ns#Property |
12 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#label | type |
13 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#isDefinedBy | http://www.w3.org/1999/02/22-rdf-syntax-ns# |
14 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#range | http://www.w3.org/2000/01/rdf-schema#Class |
15 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#comment | The subject is an instance of a class. |
16 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#domain | http://www.w3.org/2000/01/rdf-schema#Resource |
17 | http://purl.org/linked-data/cube#DataSet | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Class |
18 | http://purl.org/linked-data/cube#DataSet | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Class |
19 | http://purl.org/linked-data/cube#DataSet | http://www.w3.org/2000/01/rdf-schema#label | Data set |
Hmm... Looks the data could be partitioned into spearate graphs (maybe this is a thing publishmydata does?)
Graphs can make it easier to to frame specific topical "graph related" queries, perhaps?
See if there are any specific graphs:
q='''
SELECT * {
?a <http://publishmydata.com/def/dataset#graph> ?c
} LIMIT 50
'''
df=dfResults(endpoint,prefix,q)
df
a | c | |
---|---|---|
0 | http://statistics.data.gov.uk/data/employment | http://statistics.data.gov.uk/graph/employment |
1 | http://statistics.data.gov.uk/data/annual-survey-of-hours-and-earnings-hours | http://statistics.data.gov.uk/graph/annual-survey-of-hours-and-earnings-hours |
2 | http://statistics.data.gov.uk/data/annual-survey-of-hours-and-earnings-pay | http://statistics.data.gov.uk/graph/annual-survey-of-hours-and-earnings-pay |
To make life easier, we can can (sic) different queries into a particular graph...
#Set up a way of querying the employment graph
q_employment= '''
SELECT {s}
WHERE {{
{t}
GRAPH <http://statistics.data.gov.uk/graph/employment> {{
{q}
}}
}} LIMIT {n}
'''
def sqe(endpoint=ENDPOINT,prefix=PREFIX,s='*',t='',q='?a ?b ?c',n=100):
return dfResults(endpoint,prefix,q_employment.format(s=s,t=t,q=q,n=n))
sqe()[:20]
a | b | c | |
---|---|---|---|
0 | http://statistics.data.gov.uk/data/structure/employment | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#DataStructureDefinition |
1 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/area |
2 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/period |
3 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/measure-type |
4 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/labour-force |
5 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/count |
6 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/unit |
7 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#ComponentSpecification |
8 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#dimension | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
9 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#codeList | http://statistics.data.gov.uk/def/code-list/employment/area |
10 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#order | 1 |
11 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2004/02/skos/core#Collection |
12 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/ |
13 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/K02000001 |
14 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000001 |
15 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000002 |
16 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000003 |
17 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000004 |
18 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000005 |
19 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000006 |
Fish a bit more...
sqe(s='DISTINCT ?a',n=20)
a | |
---|---|
0 | http://statistics.data.gov.uk/data/structure/employment |
1 | http://statistics.data.gov.uk/def/component-specification/employment/area |
2 | http://statistics.data.gov.uk/def/code-list/employment/area |
3 | http://statistics.data.gov.uk/def/component-specification/employment/period |
4 | http://statistics.data.gov.uk/def/code-list/employment/period |
5 | http://statistics.data.gov.uk/def/component-specification/employment/measure-type |
6 | http://statistics.data.gov.uk/def/code-list/employment/measure-type |
7 | http://statistics.data.gov.uk/def/component-specification/employment/labour-force |
8 | http://statistics.data.gov.uk/def/code-list/employment/labour-force |
9 | http://statistics.data.gov.uk/def/component-specification/employment/count |
10 | http://statistics.data.gov.uk/def/component-specification/employment/unit |
11 | http://statistics.data.gov.uk/def/code-list/employment/unit |
12 | http://statistics.data.gov.uk/data/employment/year/2014/geography/K02000001/labour-force/employment/employees/count |
13 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employment/employees/count |
14 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000002/labour-force/employment/employees/count |
15 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000003/labour-force/employment/employees/count |
16 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000004/labour-force/employment/employees/count |
17 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000005/labour-force/employment/employees/count |
18 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000006/labour-force/employment/employees/count |
19 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000007/labour-force/employment/employees/count |
So there are lots of areas in there. Let's pick one and see what's around it...
q='''
<http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employment/employees/count> ?b ?c.
'''
sqe(q=q)
b | c | |
---|---|---|
0 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#Observation |
1 | http://purl.org/linked-data/sdmx/2009/dimension#refArea | http://statistics.data.gov.uk/id/statistical-geography/E33000001 |
2 | http://purl.org/linked-data/sdmx/2009/dimension#refPeriod | http://reference.data.gov.uk/id/year/2014 |
3 | http://purl.org/linked-data/cube#measureType | http://statistics.data.gov.uk/def/measure-properties/count |
4 | http://statistics.data.gov.uk/def/dimension/labourForce | http://statistics.data.gov.uk/def/concept/labour-force/employment |
5 | http://statistics.data.gov.uk/def/measure-properties/count | 757 |
6 | http://purl.org/linked-data/sdmx/2009/attribute#unitMeasure | http://statistics.data.gov.uk/def/concept/measurement-unit/employees |
7 | http://purl.org/linked-data/cube#dataSet | http://statistics.data.gov.uk/data/employment |
How about a different expression, taking the object value for the same area and seeing what related subjects we can find? If there are matches, we can start to get a feel for the graph stucture...
q='''
?a ?b <http://statistics.data.gov.uk/id/statistical-geography/E33000001>
'''
sqe(s='DISTINCT ?a ?b',q=q)
a | b | |
---|---|---|
0 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member |
1 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employment/employees/count | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
2 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employees/employees/count | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
So we can get from an area identifier to a count identifier.
q='''
?a <http://purl.org/linked-data/sdmx/2009/dimension#refArea> <http://statistics.data.gov.uk/id/statistical-geography/E33000001>.
'''
sqe(q=q)
a | |
---|---|
0 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employment/employees/count |
1 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employees/employees/count |
Where do we go from there?
q='''
<http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employees/employees/count> ?b ?c.
'''
sqe(q=q)
b | c | |
---|---|---|
0 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#Observation |
1 | http://purl.org/linked-data/sdmx/2009/dimension#refArea | http://statistics.data.gov.uk/id/statistical-geography/E33000001 |
2 | http://purl.org/linked-data/sdmx/2009/dimension#refPeriod | http://reference.data.gov.uk/id/year/2014 |
3 | http://purl.org/linked-data/cube#measureType | http://statistics.data.gov.uk/def/measure-properties/count |
4 | http://statistics.data.gov.uk/def/dimension/labourForce | http://statistics.data.gov.uk/def/concept/labour-force/employees |
5 | http://statistics.data.gov.uk/def/measure-properties/count | 757 |
6 | http://purl.org/linked-data/sdmx/2009/attribute#unitMeasure | http://statistics.data.gov.uk/def/concept/measurement-unit/employees |
7 | http://purl.org/linked-data/cube#dataSet | http://statistics.data.gov.uk/data/employment |
[Could be useful adding something alond the lines of the following to the default prefix list? (Is there a standard abbreviation?)
PREFIX sdmxd: http://purl.org/linked-data/sdmx/2009/dimension#
]
Okay - so what sort of report might we be able to generate from a count identifier?
l='<http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employees/employees/count>'
q='''
{l} <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?area.
{l} <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> ?period.
{l} <http://statistics.data.gov.uk/def/measure-properties/count> ?count.
'''.format(l=l)
sqe(q=q)
area | count | period | |
---|---|---|---|
0 | http://statistics.data.gov.uk/id/statistical-geography/E33000001 | 757 | http://reference.data.gov.uk/id/year/2014 |
Are there any labels for things like the reference year, or geography?
q='''
SELECT * {
{<http://reference.data.gov.uk/id/year/2014> ?b ?c.}
UNION
{<http://statistics.data.gov.uk/id/statistical-geography/E33000001> ?q ?r.}
} LIMIT 10
'''
dfResults(endpoint,prefix,q)
b | c | q | r | |
---|---|---|---|---|
0 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://reference.data.gov.uk/def/intervals/Interval | NaN | NaN |
1 | http://www.w3.org/2000/01/rdf-schema#label | 2014 | NaN | NaN |
2 | NaN | NaN | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://statistics.data.gov.uk/def/statistical-geography |
3 | NaN | NaN | http://www.w3.org/2000/01/rdf-schema#label | E33000001 |
4 | NaN | NaN | http://statistics.data.gov.uk/def/statistical-entity#code | http://statistics.data.gov.uk/id/statistical-entity/E33 |
So we can tidy up the report a bit more:
q='''
{l} <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?_area.
{l} <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> ?_period.
{l} <http://statistics.data.gov.uk/def/measure-properties/count> ?count.
{l} <http://purl.org/linked-data/sdmx/2009/attribute#unitMeasure> ?_typ.
'''.format(l=l)
t='''
?_area rdfs:label ?area.
?_period rdfs:label ?period.
?_typ rdfs:label ?typ.
'''.format(l=l)
sqe(s='?area ?period ?count ?typ',q=q,t=t)
area | count | period | typ | |
---|---|---|---|---|
0 | E33000001 | 757 | 2014 | Employees |
So presumably that then generalises further? With a bit more jiggery pokery we can get to:
code='E33000012'
q='''
?l <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?_area.
?1 <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> ?_period.
?l <http://statistics.data.gov.uk/def/measure-properties/count> ?count.
?1 <http://purl.org/linked-data/sdmx/2009/attribute#unitMeasure> ?_typ.
'''
t='''
?_area rdfs:label '{}'.
?_area rdfs:label ?area.
?_period rdfs:label ?period.
?_typ rdfs:label ?typ.
?l <http://statistics.data.gov.uk/def/dimension/labourForce> ?dim.
?dim rdfs:label ?d.
'''.format(code)
sqe(s='DISTINCT ?area ?period ?count ?typ ?d',q=q,t=t)
area | count | d | period | typ | |
---|---|---|---|---|---|
0 | E33000012 | 131 | Employment | 2014 | Employees |
1 | E33000012 | 118 | Employees | 2014 | Employees |
How about one of the other graphs?
#Set up a way of querying the pay graph
q_pay= '''
SELECT {s}
WHERE {{
{t}
GRAPH <http://statistics.data.gov.uk/data/annual-survey-of-hours-and-earnings-pay> {{
{q}
}}
}} LIMIT {n}
'''
def sqp(endpoint=ENDPOINT,prefix=PREFIX,s='*',t='',q='?a ?b ?c',n=50):
return dfResults(endpoint,prefix,q_employment.format(s=s,t=t,q=q,n=n))
sqp(n=15)
a | b | c | |
---|---|---|---|
0 | http://statistics.data.gov.uk/data/structure/employment | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#DataStructureDefinition |
1 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/area |
2 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/period |
3 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/measure-type |
4 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/labour-force |
5 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/count |
6 | http://statistics.data.gov.uk/data/structure/employment | http://purl.org/linked-data/cube#component | http://statistics.data.gov.uk/def/component-specification/employment/unit |
7 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://purl.org/linked-data/cube#ComponentSpecification |
8 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#dimension | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
9 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#codeList | http://statistics.data.gov.uk/def/code-list/employment/area |
10 | http://statistics.data.gov.uk/def/component-specification/employment/area | http://purl.org/linked-data/cube#order | 1 |
11 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2004/02/skos/core#Collection |
12 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/ |
13 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/K02000001 |
14 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member | http://statistics.data.gov.uk/id/statistical-geography/E33000001 |
q='''
?a ?b <http://statistics.data.gov.uk/id/statistical-geography/E33000001>
'''
sqp(s='DISTINCT ?a ?b',q=q)
a | b | |
---|---|---|
0 | http://statistics.data.gov.uk/def/code-list/employment/area | http://www.w3.org/2004/02/skos/core#member |
1 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employment/employees/count | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
2 | http://statistics.data.gov.uk/data/employment/year/2014/geography/E33000001/labour-force/employees/employees/count | http://purl.org/linked-data/sdmx/2009/dimension#refArea |
Okay - not sure I understand that; looks like the same stuff as from the other graph?
Quitting for now...
PS I don't recognise the statistical geography codes - are they made up?
Old ONS endpoint at http://statistics.data.gov.uk/sparql
doesn't seem to exist any more, and whilst OS endpoint is still there:
endpoint_os='http://data.ordnancesurvey.co.uk/datasets/boundary-line/apis/sparql'
p='''
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX admingeo: <http://statistics.data.gov.uk/def/administrative-geography/>
PREFIX ossr: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
'''
q='''
SELECT ?districtname
WHERE {
?district rdfs:label ?districtname.
?district <http://www.w3.org/2002/07/owl#sameAs> <http://statistics.data.gov.uk/id/statistical-geography/E04001302> .
}
'''
runQuery(endpoint_os,p,q)
{'head': {'vars': ['districtname']}, 'results': {'bindings': [{'districtname': {'type': 'literal', 'value': 'Chillerton and Gatcombe'}}]}}
it doesn't work with the codes in the demo db?
q='''
SELECT ?districtname
WHERE {
?district rdfs:label ?districtname.
?district <http://www.w3.org/2002/07/owl#sameAs> <http://statistics.data.gov.uk/id/statistical-geography/E33000001> .
}
'''
runQuery(endpoint_os,p,q)
{'head': {'vars': ['districtname']}, 'results': {'bindings': []}}
If it did, we could compound the queries using s/thing like the following to pull back info about the area from the Ordnance Surevy endpoint:
q='''
?a ?b <http://statistics.data.gov.uk/id/statistical-geography/E33000001>.
SERVICE <http://data.ordnancesurvey.co.uk/datasets/boundary-line/apis/sparql> {
?district rdfs:label ?districtname.
?district <http://www.w3.org/2002/07/owl#sameAs> <http://statistics.data.gov.uk/id/statistical-geography/E33000001> .
}
'''
sqp(s='DISTINCT *',q=q)