Created in October-December 2022 for the National Library of Scotland's Data Foundry by Gustavo Candela, National Librarian’s Research Fellowship in Digital Scholarship 2022-23
This dataset represents the descriptive metadata from the Moving Image Archive catalogue, which is Scotland’s national collection of moving images.
Import the libraries required to enrich the dataset with external repositories
import pandas as pd #for handling csv and csv contents
from rdflib import Graph, Literal, RDF, URIRef, Namespace #basic RDF handling
locationPattern = "https://example.org/location/"
We read the CSV file containing the location, latitud, longitud and the external identifiers for Wikidata and GeoNames.
df=pd.read_csv('../data/output/MovingImageArchiveEnrichment.csv',sep=",",quotechar='"',dtype={'geonames': str})
print(df)
Location lat long wikidata geonames 0 Aberdeen 57.14369 -2.09814 Q36405 2657832 1 Aberdeenshire 57.16667 -2.66667 Q189912 2657830 2 Angus 56.66667 -2.91667 Q202177 2657306 3 Argyllshire 56.25000 -5.25000 Q652539 2657088 4 Ayrshire 55.50000 -4.50000 Q793283 2656700 5 Banff 57.66477 -2.52964 Q54809 2656402 6 Berwickshire 55.75000 -2.50000 Q786649 2655820 7 Borders NaN NaN Q9177476 NaN 8 Bute 55.83333 -5.10000 Q1147435 2654168 9 Caithness 58.41667 -3.50000 Q864668 2654041 10 Clackmannanshire 56.16667 -3.75000 Q207268 2652975 11 Dumfriesshire 55.16667 -3.50000 Q1247384 2650795 12 Dunbartonshire 56.12639 -4.42069 Q17582129 7280022 13 Dundee 56.46913 -2.97489 Q123709 2650752 14 East Lothian 55.91667 -2.75000 Q207257 2650386 15 Edinburgh 55.95206 -3.19648 Q23436 2650225 16 Fife 56.25000 -3.16667 Q201149 2649469 17 Forth River 56.04750 -3.70720 Q2421 2649177 18 Glasgow 55.86515 -4.25763 Q4093 2648579 19 Gorbals, the NaN NaN Q3643362 NaN 20 Highlands, the 57.12000 -4.71000 Q106652 2646943 21 Inner Hebrides 56.50000 -6.00000 Q81052 2646177 22 Invernesshire NaN NaN NaN NaN 23 Kincardineshire 56.91667 -2.50000 Q376914 2645521 24 Kinrosshire NaN NaN NaN NaN 25 Kirkudbrightshire NaN NaN NaN NaN 26 Lanarkshire 55.58333 -3.83333 Q530296 2644975 27 Midlothian 55.82347 -3.09334 Q206934 2642559 28 Morayshire NaN NaN Q1247435 NaN 29 Nairn 57.58094 -3.87973 Q980084 2641910 30 Orkney Islands 59.00000 -3.00000 Q100166 2640923 31 Outer Hebrides 57.75000 -7.00000 Q80967 2640801 32 Peebles- shire NaN NaN NaN NaN 33 Perth 56.39522 -3.43139 Q203000 2640358 34 Renfrewshire 55.83333 -4.50000 Q211091 2639494 35 Ross-shire NaN NaN Q978599 NaN 36 Roxburghshire 55.50000 -2.50000 Q664892 2639033 37 Selkirkshire 55.50000 -3.00000 Q1247396 2638228 38 Shetland Islands 60.33333 -1.33333 Q47134 2638010 39 Stirling 56.11903 -3.93682 Q182923 2636910 40 Stirlingshire NaN NaN Q1229763 NaN 41 Sutherland 58.25000 -4.50000 Q1061313 2636507 42 West Lothian 55.91667 -3.50000 Q204940 2634354 43 Wigtownshire 54.60000 -4.83333 Q550606 2633928
g = Graph()
owl = Namespace('http://www.w3.org/2002/07/owl#')
wgs84_pos = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#")
rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#")
rdf = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
g.bind("owl", owl)
g.bind("wgs84_pos", wgs84_pos)
g.bind("rdfs", rdfs)
g.bind("rdf", rdf)
for index, row in df.iterrows():
location = URIRef(locationPattern + row['Location'].lower().replace(",", "").replace(" ", ""))
## add lat and long
if not pd.isnull(row['lat']):
g.add((location, URIRef(wgs84_pos+'lat'), Literal(str(row["lat"])) ))
if not pd.isnull(row['long']):
g.add((location, URIRef(wgs84_pos+'long'), Literal(str(row["long"]))))
if not pd.isnull(row['wikidata']):
g.add((location, URIRef(owl+'sameAs'), URIRef('https://www.wikidata.org/wiki/' + str(row['wikidata']))))
if not pd.isnull(row['geonames']):
g.add((location, URIRef(owl+'sameAs'), URIRef('https://www.geonames.org/' + str(row['geonames']))))
print(g.serialize())
g.serialize('../rdf/locations.ttl')
@prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> . <https://example.org/location/aberdeen> owl:sameAs <https://www.geonames.org/2657832>, <https://www.wikidata.org/wiki/Q36405> ; wgs84_pos:lat "57.14369" ; wgs84_pos:long "-2.09814" . <https://example.org/location/aberdeenshire> owl:sameAs <https://www.geonames.org/2657830>, <https://www.wikidata.org/wiki/Q189912> ; wgs84_pos:lat "57.16667" ; wgs84_pos:long "-2.66667" . <https://example.org/location/angus> owl:sameAs <https://www.geonames.org/2657306>, <https://www.wikidata.org/wiki/Q202177> ; wgs84_pos:lat "56.66667" ; wgs84_pos:long "-2.91667" . <https://example.org/location/argyllshire> owl:sameAs <https://www.geonames.org/2657088>, <https://www.wikidata.org/wiki/Q652539> ; wgs84_pos:lat "56.25" ; wgs84_pos:long "-5.25" . <https://example.org/location/ayrshire> owl:sameAs <https://www.geonames.org/2656700>, <https://www.wikidata.org/wiki/Q793283> ; wgs84_pos:lat "55.5" ; wgs84_pos:long "-4.5" . <https://example.org/location/banff> owl:sameAs <https://www.geonames.org/2656402>, <https://www.wikidata.org/wiki/Q54809> ; wgs84_pos:lat "57.66477" ; wgs84_pos:long "-2.52964" . <https://example.org/location/berwickshire> owl:sameAs <https://www.geonames.org/2655820>, <https://www.wikidata.org/wiki/Q786649> ; wgs84_pos:lat "55.75" ; wgs84_pos:long "-2.5" . <https://example.org/location/borders> owl:sameAs <https://www.wikidata.org/wiki/Q9177476> . <https://example.org/location/bute> owl:sameAs <https://www.geonames.org/2654168>, <https://www.wikidata.org/wiki/Q1147435> ; wgs84_pos:lat "55.83333" ; wgs84_pos:long "-5.1" . <https://example.org/location/caithness> owl:sameAs <https://www.geonames.org/2654041>, <https://www.wikidata.org/wiki/Q864668> ; wgs84_pos:lat "58.41667" ; wgs84_pos:long "-3.5" . <https://example.org/location/clackmannanshire> owl:sameAs <https://www.geonames.org/2652975>, <https://www.wikidata.org/wiki/Q207268> ; wgs84_pos:lat "56.16667" ; wgs84_pos:long "-3.75" . <https://example.org/location/dumfriesshire> owl:sameAs <https://www.geonames.org/2650795>, <https://www.wikidata.org/wiki/Q1247384> ; wgs84_pos:lat "55.16667" ; wgs84_pos:long "-3.5" . <https://example.org/location/dunbartonshire> owl:sameAs <https://www.geonames.org/7280022>, <https://www.wikidata.org/wiki/Q17582129> ; wgs84_pos:lat "56.12639" ; wgs84_pos:long "-4.42069" . <https://example.org/location/dundee> owl:sameAs <https://www.geonames.org/2650752>, <https://www.wikidata.org/wiki/Q123709> ; wgs84_pos:lat "56.46913" ; wgs84_pos:long "-2.97489" . <https://example.org/location/eastlothian> owl:sameAs <https://www.geonames.org/2650386>, <https://www.wikidata.org/wiki/Q207257> ; wgs84_pos:lat "55.91667" ; wgs84_pos:long "-2.75" . <https://example.org/location/edinburgh> owl:sameAs <https://www.geonames.org/2650225>, <https://www.wikidata.org/wiki/Q23436> ; wgs84_pos:lat "55.95206" ; wgs84_pos:long "-3.19648" . <https://example.org/location/fife> owl:sameAs <https://www.geonames.org/2649469>, <https://www.wikidata.org/wiki/Q201149> ; wgs84_pos:lat "56.25" ; wgs84_pos:long "-3.16667" . <https://example.org/location/forthriver> owl:sameAs <https://www.geonames.org/2649177>, <https://www.wikidata.org/wiki/Q2421> ; wgs84_pos:lat "56.0475" ; wgs84_pos:long "-3.7072" . <https://example.org/location/glasgow> owl:sameAs <https://www.geonames.org/2648579>, <https://www.wikidata.org/wiki/Q4093> ; wgs84_pos:lat "55.86515" ; wgs84_pos:long "-4.25763" . <https://example.org/location/gorbalsthe> owl:sameAs <https://www.wikidata.org/wiki/Q3643362> . <https://example.org/location/highlandsthe> owl:sameAs <https://www.geonames.org/2646943>, <https://www.wikidata.org/wiki/Q106652> ; wgs84_pos:lat "57.12" ; wgs84_pos:long "-4.71" . <https://example.org/location/innerhebrides> owl:sameAs <https://www.geonames.org/2646177>, <https://www.wikidata.org/wiki/Q81052> ; wgs84_pos:lat "56.5" ; wgs84_pos:long "-6.0" . <https://example.org/location/kincardineshire> owl:sameAs <https://www.geonames.org/2645521>, <https://www.wikidata.org/wiki/Q376914> ; wgs84_pos:lat "56.91667" ; wgs84_pos:long "-2.5" . <https://example.org/location/lanarkshire> owl:sameAs <https://www.geonames.org/2644975>, <https://www.wikidata.org/wiki/Q530296> ; wgs84_pos:lat "55.58333" ; wgs84_pos:long "-3.83333" . <https://example.org/location/midlothian> owl:sameAs <https://www.geonames.org/2642559>, <https://www.wikidata.org/wiki/Q206934> ; wgs84_pos:lat "55.82347" ; wgs84_pos:long "-3.09334" . <https://example.org/location/morayshire> owl:sameAs <https://www.wikidata.org/wiki/Q1247435> . <https://example.org/location/nairn> owl:sameAs <https://www.geonames.org/2641910>, <https://www.wikidata.org/wiki/Q980084> ; wgs84_pos:lat "57.58094" ; wgs84_pos:long "-3.87973" . <https://example.org/location/orkneyislands> owl:sameAs <https://www.geonames.org/2640923>, <https://www.wikidata.org/wiki/Q100166> ; wgs84_pos:lat "59.0" ; wgs84_pos:long "-3.0" . <https://example.org/location/outerhebrides> owl:sameAs <https://www.geonames.org/2640801>, <https://www.wikidata.org/wiki/Q80967> ; wgs84_pos:lat "57.75" ; wgs84_pos:long "-7.0" . <https://example.org/location/perth> owl:sameAs <https://www.geonames.org/2640358>, <https://www.wikidata.org/wiki/Q203000> ; wgs84_pos:lat "56.39522" ; wgs84_pos:long "-3.43139" . <https://example.org/location/renfrewshire> owl:sameAs <https://www.geonames.org/2639494>, <https://www.wikidata.org/wiki/Q211091> ; wgs84_pos:lat "55.83333" ; wgs84_pos:long "-4.5" . <https://example.org/location/ross-shire> owl:sameAs <https://www.wikidata.org/wiki/Q978599> . <https://example.org/location/roxburghshire> owl:sameAs <https://www.geonames.org/2639033>, <https://www.wikidata.org/wiki/Q664892> ; wgs84_pos:lat "55.5" ; wgs84_pos:long "-2.5" . <https://example.org/location/selkirkshire> owl:sameAs <https://www.geonames.org/2638228>, <https://www.wikidata.org/wiki/Q1247396> ; wgs84_pos:lat "55.5" ; wgs84_pos:long "-3.0" . <https://example.org/location/shetlandislands> owl:sameAs <https://www.geonames.org/2638010>, <https://www.wikidata.org/wiki/Q47134> ; wgs84_pos:lat "60.33333" ; wgs84_pos:long "-1.33333" . <https://example.org/location/stirling> owl:sameAs <https://www.geonames.org/2636910>, <https://www.wikidata.org/wiki/Q182923> ; wgs84_pos:lat "56.11903" ; wgs84_pos:long "-3.93682" . <https://example.org/location/stirlingshire> owl:sameAs <https://www.wikidata.org/wiki/Q1229763> . <https://example.org/location/sutherland> owl:sameAs <https://www.geonames.org/2636507>, <https://www.wikidata.org/wiki/Q1061313> ; wgs84_pos:lat "58.25" ; wgs84_pos:long "-4.5" . <https://example.org/location/westlothian> owl:sameAs <https://www.geonames.org/2634354>, <https://www.wikidata.org/wiki/Q204940> ; wgs84_pos:lat "55.91667" ; wgs84_pos:long "-3.5" . <https://example.org/location/wigtownshire> owl:sameAs <https://www.geonames.org/2633928>, <https://www.wikidata.org/wiki/Q550606> ; wgs84_pos:lat "54.6" ; wgs84_pos:long "-4.83333" .
<Graph identifier=Nb18ad1a9fef243b28b4ab1d828873808 (<class 'rdflib.graph.Graph'>)>
Let's merge the original RDF dataset with the information that we have created about geographic locations
g = Graph()
g.parse("../rdf/locations.ttl")
g.parse("../rdf/dataset.ttl")
g.serialize('../rdf/datasetEnriched.ttl')
<Graph identifier=N3119c2f780c44c01adbe6581debcedc9 (<class 'rdflib.graph.Graph'>)>