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")
According to the Moving Image Archive website, the current total number of records associated to the subject Agriculture is 410.
The command line grep
can be used to identify text in the dataset. It provides several parameters to configure the instruction such as -n4
that retrieves 4 lines per occurrence.
For example, grep
can be used in order to identify the number of videos related to a subject (e.g., Agriculture). However, note that the word may appear in several fields, not only in 653 MARC field.
We can retrieve the number of occurrences using the command line wc -l
print('##### check Agriculture subject:')
# Query the data in g using SPARQL
q = """
SELECT ?subject (COUNT(?s) as ?count)
WHERE { ?s dc:subject ?subject . FILTER regex(str(?subject),"Agriculture")}
GROUP BY ?subject
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"]))
##### check Agriculture subject: Agriculture 379
print('##### total number of items containing a property dc:subject with the text Gaelic:')
# Query the data in g using SPARQL
q = """
SELECT (COUNT(?subject) as ?total)
WHERE { ?s dc:subject ?subject . FILTER regex(?subject, "Gaelic")}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(str(r["total"]))
##### total number of items containing a property dc:subject with the text Gaelic: 1943
# 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) > 100)
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"]))
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
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT (count(distinct ?s) as ?total)
WHERE {?s schema:author <https://example.org/organization/ifascotland>}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["total"])
37
# Query the data in g using SPARQL
q = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {?s schema:author <https://example.org/organization/ifascotland> . ?s schema:name ?name}
"""
# Apply the query to the graph and iterate through results
for r in g.query(q):
print(r["name"])
WHY SCOTLAND, WHY EAST KILBRIDE AMAZING MOMENTS OF THE GREAT TRACTION ENGINES, the DRAM LIKE THIS, a COUNTY ON THE MOVE LIVINGSTON - A TOWN FOR THE LOTHIANS MACKINTOSH DUNA BULL, the LIVING IN SCOTLAND / SMITHS IN SCOTLAND, the KIND OF SEEING: The Colour of Scotland, a SONGS OF SCOTLAND SEA CITY - GREENOCK ONE DAY IN IRVINE IN GREAT WATERS LOCH LOMOND WATER OF LIFE, the WATER, WATER EVERYWHERE ERSKINE BRIDGE, the LINE TO SKYE, the CONSEQUENCES SETTLED OUT OF COURT: Children's Hearings in Scotland LOOK TO THE SEA: The Marine Laboratory Aberdeen, Its Work and Its People EDINBURGH ON PARADE GARDENS BY THE SEA COME AWAY IN WALKABOUT EDINBURGH GRAND MATCH, the STONE IN THE HEATHER, a SPIRIT OF SCOTLAND, the KH-4 LINE FOR ALL SEASONS, a DISAPPEARING ISLAND, the GET THERE SAFELY FALLS THE SHADOW DIAMONDS WERE FOREVER: A Celebration of Glasgow Steam ACRE OF SUNDAYS, an CHAIRS SHELL SHOCK