Skip to content

Instantly share code, notes, and snippets.

@lawlesst
lawlesst / vivo_utils.py
Created September 25, 2012 20:52
Vivo utilities using Jena Java classes via jnius.
from jnius import autoclass
"""
You need to set the Java classpath before running this.
e.g.
export CLASSPATH=".:/work/javalib/*"
"""
DB_URL = "jdbc:mysql://school.edu/vivo";
@lawlesst
lawlesst / vivoharvester.py
Last active October 11, 2015 08:08
Using the Vivo harvester from Python with Pyjnius
"""
Use the Vivo harverster with Python and Jnius.
You need to set the Java classpath before running this.
e.g.
export CLASSPATH=".:/work/javalib/*"
The path you specify needs to contain the Vivo Harvester jar.
https://github.com/vivo-project/VIVO-Harvester
@lawlesst
lawlesst / vivo_dev_call_notes.md
Created October 25, 2012 16:37
Brown Vivo Ingest Process

###Sources

  • Data from faculty CVs prepared by Backstage, a library data vendor.
  • Consists of a MySQL database with several tables representing different sections from faculty CVs. E.g. publications, employment, service to the university.
  • Also pulling data from various campus information systems.

###Toolkit

Python

@lawlesst
lawlesst / rdfalchemy_test_dbpedia2.py
Created November 16, 2012 12:19 — forked from tatiana/rdfalchemy_test_dbpedia2.py
Trying to replace SPARQL query using RDFAlchemy's rdfSubject
"""
See RDFAlchemy-dev list discussion:
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/rdfalchemy-dev/D1AyXQwmOuw
"""
from rdfalchemy import rdfSingle, rdfSubject
from rdfalchemy.sparql import SPARQLGraph
@lawlesst
lawlesst / cleaner.py
Created November 19, 2012 14:29
cleaning invalid characters from xml
def invalid_xml_remove(c):
#http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
illegal_unichrs = [ (0x00, 0x08), (0x0B, 0x1F), (0x7F, 0x84), (0x86, 0x9F),
(0xD800, 0xDFFF), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF),
(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF), (0x3FFFE, 0x3FFFF),
(0x4FFFE, 0x4FFFF), (0x5FFFE, 0x5FFFF), (0x6FFFE, 0x6FFFF),
(0x7FFFE, 0x7FFFF), (0x8FFFE, 0x8FFFF), (0x9FFFE, 0x9FFFF),
(0xAFFFE, 0xAFFFF), (0xBFFFE, 0xBFFFF), (0xCFFFE, 0xCFFFF),
(0xDFFFE, 0xDFFFF), (0xEFFFE, 0xEFFFF), (0xFFFFE, 0xFFFFF),
@lawlesst
lawlesst / graph_images.py
Created November 21, 2012 19:53
Creating the RDF for images in VIVO
"""
Jython image loader.
- requires the VIVO harvester or Jena to be on your CLASSPATH
- requires a get_next_uri utility not included
- requires Jython
- leave a comment or contact lawlesst AT gmail dot com if you have questions.
This will create a file of N3 RDF that can be loaded into a VIVO instance.
After the RDF is added, rsync your local directory of images to the VIVO data directory.
@lawlesst
lawlesst / vivosparql.py
Created December 11, 2012 18:05
Python SPARQLWrapper class that works with VIVO's built-in SPARQL utility
"""
A subclass of SPARQLWrapper that will work with the built-in
SPARQL admin interface that comes with VIVO.
At the moment, will only return RS_JSON for SELECT and
N3 for CONSTRUCT queries.
"""
from pprint import pprint
import urllib
from illiad.account import IlliadSession
#Establish an ILLiad session for a given user.
ill = IlliadSession('https://illiad.school.edu',
'your secret remote auth header',
'libraryusername')
#Log the user in.
ill.login()
#An OpenURL for the item to be requested. In this case an article.
openurl = """
@lawlesst
lawlesst / vivordfalchemy.py
Last active June 29, 2017 19:05
Reading and writing RDF for VIVO using RDFAlchemy.
import csv
from pprint import pprint
import urllib
from rdflib import Namespace
from rdfalchemy import rdfSingle
from rdfalchemy.rdfSubject import rdfSubject
from rdflib import Literal, BNode, Namespace, URIRef
from rdflib import RDF, RDFS, Graph, OWL
@lawlesst
lawlesst / export_vivo.py
Last active February 7, 2018 09:30
Jython script to connect to VIVO via SDB and export a model.
"""
Jython script to connect to VIVO via SDB and export a model.
Requires Jython 2.5 or later. Download from: http://www.jython.org/downloads.html
Assumes the VIVO harvester is on your path.
- change the database connection information to point to your VIVO database.
- change the model name to specify the VIVO model you would like to export.
- change the output_file name to the location where you want to save the RDF.
- for larger models you will want to increase the memory available to Java.