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 query the RDF dataset
from rdflib import Graph
# Create a Graph
g = Graph().parse("../rdf/datasetEnriched.ttl")
print('##### Number of classes:')
# Query the data in g using SPARQL
q = """
SELECT (count(distinct ?class) as ?classes)
WHERE {
?s a ?class .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["classes"])
##### Number of classes: 7
print('##### Classes:')
# Query the data in g using SPARQL
q = """
SELECT distinct ?class
WHERE {
?s a ?class .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["class"])
##### Classes: https://schema.org/VideoObject http://xmlns.com/foaf/0.1/Person https://schema.org/Person http://www.europeana.eu/schemas/edm/Place https://schema.org/Place http://xmlns.com/foaf/0.1/Organization https://schema.org/Organization
print('##### Number of properties:')
# Query the data in g using SPARQL
q = """
SELECT (count(distinct ?prop) as ?properties)
WHERE {
?s ?prop ?o .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["properties"])
##### Number of properties: 23
print('##### Properties:')
# Query the data in g using SPARQL
q = """
SELECT distinct ?prop
WHERE {
?s ?prop ?o .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["prop"])
##### Properties: https://schema.org/datePublished http://purl.org/dc/elements/1.1/identifier https://schema.org/duration http://purl.org/dc/elements/1.1/date http://purl.org/dc/elements/1.1/title https://schema.org/thumbnail https://schema.org/identifier http://purl.org/dc/elements/1.1/subject http://www.w3.org/1999/02/22-rdf-syntax-ns#type https://schema.org/videoQuality https://schema.org/creditText http://purl.org/dc/terms/spatial https://schema.org/sourceOrganization https://schema.org/name https://schema.org/abstract https://schema.org/author http://www.w3.org/2004/02/skos/core#prefLabel http://www.w3.org/2003/01/geo/wgs84_pos#long http://www.w3.org/2003/01/geo/wgs84_pos#lat http://xmlns.com/foaf/0.1/name http://www.w3.org/2002/07/owl#sameAs https://schema.org/url https://schema.org/logo
print('##### Number of owl:sameAs properties:')
# Query the data in g using SPARQL
q = """
SELECT (count(distinct ?sameAs) as ?total)
WHERE {
?p owl:sameAs ?sameAs .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["total"])
##### Number of owl:sameAs properties: 75
print('##### owl:sameAs properties:')
# Query the data in g using SPARQL
q = """
SELECT distinct ?sameAs
WHERE {
?p owl:sameAs ?sameAs .
}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["sameAs"])
##### owl:sameAs properties: https://www.geonames.org/2641910 https://www.wikidata.org/wiki/Q980084 https://www.geonames.org/2652975 https://www.wikidata.org/wiki/Q207268 https://www.geonames.org/2645521 https://www.wikidata.org/wiki/Q376914 https://www.wikidata.org/wiki/Q3643362 https://www.geonames.org/2633928 https://www.wikidata.org/wiki/Q550606 https://www.geonames.org/2636507 https://www.wikidata.org/wiki/Q1061313 https://www.geonames.org/2638228 https://www.wikidata.org/wiki/Q1247396 https://www.geonames.org/2655820 https://www.wikidata.org/wiki/Q786649 https://www.geonames.org/2657306 https://www.wikidata.org/wiki/Q202177 https://www.geonames.org/2656402 https://www.wikidata.org/wiki/Q54809 https://www.geonames.org/2654041 https://www.wikidata.org/wiki/Q864668 https://www.geonames.org/2639033 https://www.wikidata.org/wiki/Q664892 https://www.geonames.org/2642559 https://www.wikidata.org/wiki/Q206934 https://www.geonames.org/2636910 https://www.wikidata.org/wiki/Q182923 https://www.wikidata.org/wiki/Q978599 https://www.wikidata.org/wiki/Q1247435 https://www.geonames.org/2650386 https://www.wikidata.org/wiki/Q207257 https://www.geonames.org/2654168 https://www.wikidata.org/wiki/Q1147435 https://www.geonames.org/2649177 https://www.wikidata.org/wiki/Q2421 https://www.geonames.org/2638010 https://www.wikidata.org/wiki/Q47134 https://www.wikidata.org/wiki/Q1229763 https://www.wikidata.org/wiki/Q9177476 https://www.geonames.org/2640923 https://www.wikidata.org/wiki/Q100166 https://www.geonames.org/2650795 https://www.wikidata.org/wiki/Q1247384 https://www.geonames.org/2640801 https://www.wikidata.org/wiki/Q80967 https://www.geonames.org/2646177 https://www.wikidata.org/wiki/Q81052 https://www.geonames.org/2634354 https://www.wikidata.org/wiki/Q204940 https://www.geonames.org/2646943 https://www.wikidata.org/wiki/Q106652 https://www.geonames.org/2650752 https://www.wikidata.org/wiki/Q123709 https://www.geonames.org/7280022 https://www.wikidata.org/wiki/Q17582129 https://www.geonames.org/2640358 https://www.wikidata.org/wiki/Q203000 https://www.geonames.org/2657830 https://www.wikidata.org/wiki/Q189912 https://www.geonames.org/2657088 https://www.wikidata.org/wiki/Q652539 https://www.geonames.org/2657832 https://www.wikidata.org/wiki/Q36405 https://www.geonames.org/2649469 https://www.wikidata.org/wiki/Q201149 https://www.geonames.org/2644975 https://www.wikidata.org/wiki/Q530296 https://www.geonames.org/2656700 https://www.wikidata.org/wiki/Q793283 https://www.geonames.org/2639494 https://www.wikidata.org/wiki/Q211091 https://www.geonames.org/2650225 https://www.wikidata.org/wiki/Q23436 https://www.geonames.org/2648579 https://www.wikidata.org/wiki/Q4093
print('##### Number of triples:')
# Query the data in g using SPARQL
q = """
SELECT (COUNT(*) as ?triples)
WHERE { ?s ?p ?o }
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["triples"])
##### Number of triples: 263476
print('##### Number of videos:')
# Query the data in g using SPARQL
q = """
SELECT (COUNT(distinct ?s) as ?videos)
WHERE { ?s a schema:VideoObject}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["videos"])
##### Number of videos: 20608
print('##### Number of authors:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT (COUNT(distinct ?s) as ?authors)
WHERE {?s a foaf:Person}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["authors"])
##### Number of authors: 54
print('##### List of authors:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?name
WHERE {?s a foaf:Person . ?s foaf:name ?name}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["s"]) + " " + r["name"])
##### List of authors: https://example.org/author/bendonwilliamjohnprince BENDON, William John ‘Prince’ https://example.org/author/bennelljj BENNELL, J.J. https://example.org/author/hinkswalter HINKS, Walter https://example.org/author/kisslingwerner KISSLING, Werner https://example.org/author/poolejohnkennethstaffordjks POOLE, John Kenneth Stafford ‘J.K.S.’ https://example.org/author/scottishcinematographbenevolentfund Scottish Cinematograph Benevolent Fund https://example.org/author/greenfamily Green family https://example.org/author/singletongeorge SINGLETON, George https://example.org/author/grayalexanderjoe GRAY, Alexander ‘Joe’ https://example.org/author/loorijjanpaulusjack LOORIJ, Jan Paulus (Jack) https://example.org/author/walkerwilliam WALKER, William https://example.org/author/irvinemalcolm IRVINE, Malcolm https://example.org/author/lowdavid LOW, David https://example.org/author/robellopaul ROBELLO, Paul https://example.org/author/kingalexanderb KING, Alexander B. https://example.org/author/dawncinegroup Dawn Cine Group https://example.org/author/hutchisonisobelwylie HUTCHISON, Isobel Wylie https://example.org/author/gillespiejamesstirling GILLESPIE, James Stirling https://example.org/author/glasgowschoolofartkinecraftsocietygsaks Glasgow School of Art Kinecraft Society (GSAKS) https://example.org/author/birrellharry Birrell, Harry https://example.org/author/kempfamily Kemp family https://example.org/author/macleanwilliamjmac MacLEAN, William J. ‘Mac’ https://example.org/author/hartjames HART, James https://example.org/author/riddell-blackrobert RIDDELL-BLACK, Robert https://example.org/author/scottishmovingpicturenews Scottish Moving Picture News / British Moving Picture News https://example.org/author/gilbertsonjennyisabelneebrown GILBERTSON, Jenny Isabel (nee Brown) https://example.org/author/neelyanne NEELY, Anne https://example.org/author/dalrymplejblake DALRYMPLE, J. Blake https://example.org/author/brombergernest BROMBERG, Ernest https://example.org/author/grigormurray Grigor, Murray https://example.org/author/ogamfilms Ogam Films / Oscar Marzaroli https://example.org/author/dicksonlouis DICKSON, Louis https://example.org/author/mickeldouglas MICKEL, Douglas https://example.org/author/jayronaldl JAY, Ronald L. https://example.org/author/cooperhenry COOPER, Henry https://example.org/author/annandlouise Annand, Louise https://example.org/author/harperalanjames HARPER, Alan James https://example.org/author/taggartnan Taggart, Nan https://example.org/author/glasgowcorporation Glasgow Corporation https://example.org/author/taitmargaret TAIT, Margaret https://example.org/author/nairnjamess NAIRN, James S. https://example.org/author/colonelarthureirvineandrichardirvinecollection Colonel Arthur E Irvine and Richard Irvine Collection https://example.org/author/mcconnelledwardeddie McConnell, Edward ‘Eddie’ https://example.org/author/elderjohnc ELDER, John C https://example.org/author/marshallfrankm MARSHALL, Frank M. https://example.org/author/cocozzaenrico COCOZZA, Enrico https://example.org/author/russellstanleylivingstone RUSSELL, Stanley Livingstone https://example.org/author/group5 Group 5 / Clansman Films https://example.org/author/scottisheducationalfilmassociationsefa Scottish Educational Film Association (SEFA) https://example.org/author/scottishindependencereferendumcollection2014 Scottish Independence Referendum Collection 2014 https://example.org/author/scottishballet Scottish Ballet https://example.org/author/edinburghcineandvideosocietyecvs Edinburgh Cine and Video Society (ECVS) https://example.org/author/grampiantelevision Grampian Television https://example.org/author/scottishscreencollection Scottish Screen Collection
print('##### Number of organizations:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT (COUNT(distinct ?s) as ?orgs)
WHERE {?s a foaf:Organization}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["orgs"])
##### Number of organizations: 10
print('##### Check the properties used to define an organization:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
WHERE {<https://example.org/organization/ifascotland> ?p ?o}
limit 40
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["p"]) + " " + str(r["o"]))
##### Check the properties used to define an organization: http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://xmlns.com/foaf/0.1/Organization http://www.w3.org/1999/02/22-rdf-syntax-ns#type https://schema.org/Organization http://www.w3.org/2004/02/skos/core#prefLabel IFA Scotland http://xmlns.com/foaf/0.1/name IFA Scotland https://schema.org/name IFA Scotland
print('##### List of organizations:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?name
WHERE {?s a foaf:Organization . ?s foaf:name ?name}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["s"]) + " " + r["name"])
##### List of organizations: https://example.org/organization/treefilms Tree Films https://example.org/organization/peliculafilms Pelicula Films https://example.org/organization/elderdalrympleproductions Elder Dalrymple Productions / Elder Films https://example.org/organization/greensfilmservice Green’s Film Service / Green’s Topical Productions https://example.org/organization/ifascotland IFA Scotland https://example.org/organization/scottishfilms Scottish Films / Thames and Clyde Productions https://example.org/organization/scottishamateurfilmfestivalsaff Scottish Amateur Film Festival (SAFF) https://example.org/organization/campbellharperproductions Campbell Harper Productions https://example.org/organization/filmsofscotlandcommittee Films of Scotland Committee https://example.org/organization/templarfilms Templar Films
print('##### Number of subjects:')
# Query the data in g using SPARQL
q = """
SELECT (COUNT(distinct ?subject) as ?subjects)
WHERE { ?s dc:subject ?subject}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["subjects"])
##### Number of subjects: 91
print('##### List of subjects:')
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?subject
WHERE { ?s dc:subject ?subject}
limit 10
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["subject"]) #+ " " + r["name"])
##### List of subjects: Bus Stations and Depots Buses and Coaches, general Celebrations, Traditions and Customs Children and Infants Leisure and Recreation Transport Ceremonies Emotions, Attitudes and Behaviour Local Government Art and Artists, general
print('##### group by subjects:')
# Query the data in g using SPARQL
q = """
SELECT ?subject (COUNT(distinct ?s) as ?count)
WHERE { ?s dc:subject ?subject}
GROUP BY ?subject
HAVING (count(distinct ?s) > 50)
ORDER BY DESC(?count)
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["subject"]) + " " + str(r["count"]))
##### group by subjects: Gaelic 1943 Leisure and Recreation 1145 Transport 732 Employment, Industry and Industrial Relations 730 Sporting Activities 625 Ships and Shipping 567 Education 525 Celebrations, Traditions and Customs 497 Tourism and Travel 459 Media, Communication and the Creative Industries 441 Children and Infants 426 Ceremonies 420 Arts and Crafts 386 Agriculture 379 Construction and Engineering 363 Fish and Fishing 311 Emotions, Attitudes and Behaviour 299 Food and Drink 299 Art and Artists, general 289 Landscapes and Seascapes 284 Environment 274 Water and Waterways 255 Home Life 239 Military, the 236 Animals 234 Politics 228 Power Resources 223 Science and Technology 223 Religion 221 Healthcare 212 War 210 Architecture and Buildings 204 Birds 164 Royalty 157 Housing and Living Conditions 145 Music 135 Fishing Boats 131 Buses and Coaches, general 119 Carriages 106 Ferries 95 Local Government 88 Forth River 85 Crime, Punishment and Law Enforcement 69 Institutional Care 63 British Empire, the 61 Celts and Celtic Culture 61 Paddle Steamers 59
print('##### group by authors:')
# Query the data in g using SPARQL
q = """
SELECT ?author (COUNT(distinct ?s) as ?count)
WHERE { ?s schema:author ?author}
GROUP BY ?author
HAVING (count(distinct ?s) > 20)
ORDER BY DESC(?count)
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["author"]) + " " + str(r["count"]))
##### group by authors: https://example.org/author/scottishscreencollection 699 https://example.org/author/grampiantelevision 499 https://example.org/organization/templarfilms 318 https://example.org/author/edinburghcineandvideosocietyecvs 293 https://example.org/author/scottishballet 171 https://example.org/organization/filmsofscotlandcommittee 166 https://example.org/author/scottishindependencereferendumcollection2014 157 https://example.org/author/scottisheducationalfilmassociationsefa 148 https://example.org/organization/campbellharperproductions 130 https://example.org/organization/scottishamateurfilmfestivalsaff 117 https://example.org/author/group5 85 https://example.org/author/russellstanleylivingstone 63 https://example.org/author/cocozzaenrico 62 https://example.org/author/marshallfrankm 59 https://example.org/author/elderjohnc 58 https://example.org/author/mcconnelledwardeddie 54 https://example.org/author/colonelarthureirvineandrichardirvinecollection 50 https://example.org/author/nairnjamess 49 https://example.org/author/taitmargaret 48 https://example.org/author/glasgowcorporation 46 https://example.org/organization/scottishfilms 45 https://example.org/author/annandlouise 39 https://example.org/author/harperalanjames 39 https://example.org/author/taggartnan 39 https://example.org/author/cooperhenry 38 https://example.org/author/jayronaldl 37 https://example.org/organization/greensfilmservice 37 https://example.org/organization/ifascotland 37 https://example.org/organization/elderdalrympleproductions 36 https://example.org/author/mickeldouglas 35 https://example.org/author/dicksonlouis 32 https://example.org/author/ogamfilms 29 https://example.org/author/brombergernest 28 https://example.org/author/grigormurray 28 https://example.org/organization/peliculafilms 27 https://example.org/author/dalrymplejblake 23
print('##### Number of places:')
# Query the data in g using SPARQL
q = """
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT (COUNT(distinct ?place) as ?places)
WHERE { ?s dcterms:spatial ?place}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["places"])
##### Number of places: 44
print('##### group by place:')
# Query the data in g using SPARQL
q = """
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?place (COUNT(distinct ?s) as ?count)
WHERE { ?s dcterms:spatial ?place}
GROUP BY ?place
HAVING (count(distinct ?s) > 20)
ORDER BY DESC(?count)
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["place"]) + " " + str(r["count"]))
##### group by place: https://example.org/location/glasgow 976 https://example.org/location/edinburgh 686 https://example.org/location/renfrewshire 288 https://example.org/location/ayrshire 288 https://example.org/location/lanarkshire 271 https://example.org/location/fife 254 https://example.org/location/aberdeen 248 https://example.org/location/argyllshire 230 https://example.org/location/aberdeenshire 216 https://example.org/location/perth 201 https://example.org/location/dunbartonshire 194 https://example.org/location/dundee 142 https://example.org/location/highlandsthe 140 https://example.org/location/invernesshire 134 https://example.org/location/westlothian 128 https://example.org/location/innerhebrides 124 https://example.org/location/outerhebrides 119 https://example.org/location/dumfriesshire 118 https://example.org/location/orkneyislands 117 https://example.org/location/borders 108 https://example.org/location/stirlingshire 98 https://example.org/location/shetlandislands 86 https://example.org/location/forthriver 85 https://example.org/location/bute 78 https://example.org/location/eastlothian 73 https://example.org/location/morayshire 68 https://example.org/location/ross-shire 66 https://example.org/location/stirling 62 https://example.org/location/midlothian 61 https://example.org/location/roxburghshire 58 https://example.org/location/caithness 57 https://example.org/location/banff 57 https://example.org/location/angus 55 https://example.org/location/berwickshire 48 https://example.org/location/selkirkshire 41 https://example.org/location/sutherland 35 https://example.org/location/wigtownshire 26 https://example.org/location/peebles-shire 23