Last active
August 29, 2015 13:57
-
-
Save lawlesst/9646939 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"metadata": { | |
"name": "faculty-ingest" | |
}, | |
"name": "faculty-ingest", | |
"nbformat": 2, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"source": "#VIVO ingest with Python\n\n\nVIVO 1.6 ontology VCard usage: https://wiki.duraspace.org/display/VIVO/VCard+usage+diagram\n\nSample data:\nhttp://sourceforge.net/projects/vivo/files/Data%20Ingest/\n\n##Read in faculty data from CSV" | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": "##Create simple faculty RDF" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "faculty = \"\"\"person_ID,name,first,last,middle,email,phone,fax,title\n3130,\"Burks, Rosella \",Rosella,Burks,,[email protected],963.555.1253,963.777.4065,Professor\n3297,\"Avila, Damien \",Damien,Avila,,[email protected],963.555.1352,963.777.7914,Professor\n3547,\"Olsen, Robin \",Robin,Olsen,,[email protected],963.555.1378,963.777.9262,Assistant Professor\"\"\"\nimport csv\nfrom StringIO import StringIO\ndata = csv.DictReader(StringIO(faculty))\n\nimport rdflib\nfrom rdflib import Namespace, URIRef, Literal, RDF, RDFS\n#Our data namespace\nD = Namespace('http://vivo.brown.edu/individual/')\nVIVO = Namespace('http://vivoweb.org/ontology/core#')\n#Create an RDFLib Graph\ng = rdflib.Graph()\nfor row in data:\n id = row['person_ID']\n #Make a uri\n uri = D['fac{}'.format(id)]\n #type\n g.add((uri, RDF.type, VIVO.FacultyMember))\n #label\n g.add((uri, RDFS.label, Literal(row['name'])))\n#print as n3\nprint g.serialize(format='n3')\ng.serialize(format='n3', destination='data/fac.n3')", | |
"language": "python", | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n@prefix xml: <http://www.w3.org/XML/1998/namespace> .\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n<http://vivo.brown.edu/individual/fac3130> a <http://vivoweb.org/ontology/core#FacultyMember> ;\n rdfs:label \"Burks, Rosella \" .\n\n<http://vivo.brown.edu/individual/fac3297> a <http://vivoweb.org/ontology/core#FacultyMember> ;\n rdfs:label \"Avila, Damien \" .\n\n<http://vivo.brown.edu/individual/fac3547> a <http://vivoweb.org/ontology/core#FacultyMember> ;\n rdfs:label \"Olsen, Robin \" .\n\n" | |
} | |
], | |
"prompt_number": 26 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": "", | |
"language": "python", | |
"outputs": [] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment