Skip to content

Instantly share code, notes, and snippets.

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 / 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
@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 / 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 / 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 / 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 / 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_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 / sparql_unique_uri.py
Created September 21, 2012 20:09
Helper to create a random identifier for a resource via Sparql.
from SPARQLWrapper import SPARQLWrapper, JSON, N3
exists = """
SELECT *
WHERE {
OPTIONAL{<%(next_uri)s> ?p ?o}.
OPTIONAL{?s2 ?p2 <%(next_uri)s>}.
}
"""
@lawlesst
lawlesst / load_graph.py
Created September 10, 2012 20:35
Load an external graph to a Jena SDB model.
#! /usr/bin/env jython
"""
Load a graph into a given SDB model.
"""
import glob
import sys
import os
import optparse