Last active
February 7, 2018 09:30
-
-
Save lawlesst/4556582 to your computer and use it in GitHub Desktop.
Jython script to connect to VIVO via SDB and export a model.
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
""" | |
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. | |
e.g. jython -J-Xmx2048m export_vivo.py | |
""" | |
from org.vivoweb.harvester.util.repo import SDBJenaConnect | |
jc = SDBJenaConnect( | |
'jdbc:mysql://localhost/vivo', | |
'vivo', | |
'pass', | |
'MySQL', | |
#class | |
'com.mysql.jdbc.Driver', | |
#layout | |
'layout2', | |
#modelname | |
'http://vivo.school.edu/modelname' | |
) | |
#Echo the model name. | |
print jc.getModelName() | |
output_file = "export.rdf" | |
#Change this to exportRdfToFile(output_file, 'N3') to get a different serialization. | |
jc.exportRdfToFile(output_file) | |
jc.close() |
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
""" | |
Jython script to connect to VIVO via SDB and export named graphs. | |
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 names to specify the VIVO models you would like to export. | |
- change the DIR name to the location where you want to save the RDF. | |
- for larger models you will want to increase the memory available to Java. | |
e.g. jython -J-Xmx2048m export_vivo_models.py | |
e.g. jython -J-Xmx4096m export_vivo_models.py | |
""" | |
import os | |
from org.vivoweb.harvester.util.repo import SDBJenaConnect | |
DB_HOST = 'localhost' | |
DB = 'vivo' | |
DB_USER = 'user' | |
DB_PASS = 'pass' | |
#Directory for saving data | |
DIR = '/tmp/vivo' | |
def scrub_uri(name): | |
#Clean up a HTTP URI so it can be used as a file name. | |
return name.lstrip('http://').replace('/', '-') | |
#Add your list of models here. | |
models = [ | |
"http://vitro.mannlib.cornell.edu/default/vitro-kb-2", | |
"http://vitro.mannlib.cornell.edu/default/vitro-kb-inf", | |
"http://localhost/data/mynamedgraph", | |
] | |
print '-----Dumping---' | |
for model_name in models: | |
#Echo the model name. | |
jc = SDBJenaConnect( | |
'jdbc:mysql://{0}/{1}?useUnicode=yes&characterEncoding=utf8'.format(DB_HOST, DB), | |
DB_USER, | |
DB_PASS, | |
'MySQL', | |
#class | |
'com.mysql.jdbc.Driver', | |
#layout | |
'layout2', | |
#modelname | |
model_name | |
) | |
#Print model name for debugging | |
print jc.getModelName() | |
#File name for export | |
fname = os.path.join(DIR, '%s.n3' % scrub_uri(model_name)) | |
jc.exportRdfToFile(fname, 'N3') | |
jc.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment