Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisismattmiller/7cee9c6eb5db008720839f390ba5fad6 to your computer and use it in GitHub Desktop.
Save thisismattmiller/7cee9c6eb5db008720839f390ba5fad6 to your computer and use it in GitHub Desktop.
import csv
from rdflib import Graph, URIRef, Literal
#ask the CSV file to be opened
csv_file = csv.reader(open("Art Donahue data set - Sheet1.csv"), delimiter=",")
#skip the header
next(csv_file, None)
#make a new graph
store = Graph()
#loop over each line and read each field
for a_row in csv_file:
box = a_row[0]
format = a_row[1]
label = a_row[2]
date = a_row[3]
notes = a_row[4]
collection = a_row[5]
accession = a_row[6]
location = a_row[7]
added_uri = a_row[8]
print (box,format,label,date,notes,collection,accession,location,added_uri)
#add in the box number
subject = URIRef("http://example.org/accession/"+accession)
predicate = URIRef("http://purl.org/dc/terms/identifier")
object = Literal(box)
#add it to the graph
store.add((subject, predicate, object))
#write it out to a file after the loop
store.serialize("art_donahue.nt", format="nt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment