Created
April 25, 2016 22:25
-
-
Save thisismattmiller/7cee9c6eb5db008720839f390ba5fad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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