Deprecated. This material represents early efforts and may be of interest to historians. It doe not describe current VIVO efforts.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Remote applications can perform SPARQL Update calls to add RDF to VIVO, or to remove existing RDF. Since VIVO 1.6.

 

Purpose

Permits external applications to add or remove specific triples from the VIVO data model. These changes use the standard data channels in VIVO, so the search index will be updated as appropriate, and the reasoner will add or remove inferences as needed.

Use Cases

Harvester

Previous implementations of the Harvester and similar tools have written directly to the VIVO triple-store, bypassing the usual data channels in VIVO. After ingesting, it was necessary to rebuild the search index, and to run the reasoner to add or remove inferences. Since the search index and the reasoner were not aware of the exact changes, the entire data model was re-indexed and re-inferenced.

When the Harvester and other tools have been modified to use the SPARQL Update API, VIVO will ensure that the search index and inferences are kept in synchronization with the data.

Other ingest tools

This API permits ingest tools such as Karma to programmatically insert data into VIVO without requiring knowledge of VIVOs internal data structures.

VIVO "face" applications

Linked Open Data requests have permitted people to write Drupal applications (for example) that display data from VIVO. This API will permit such applications to accept user edits, and apply them back to VIVO.

Specification

URL

[vivo]/api/sparqlUpdate

Examples:

http://vivo.cornell.edu/api/sparqlUpdate
http://localhost:8080/vivo/api/sparqlUpdate

HTTP Method

The API supports only HTTP POST calls. GET, HEAD, and other methods are not supported, and will return a response code of 400 Bad Request.

Parameters

namevalue
emailthe email address of a VIVO adminstrator account
passwordthe password of the VIVO administrator account
updateA SPARQL Update request

The syntax for a SPARQL Update request is described on the World Wide Web Consortium site at http://www.w3.org/TR/2013/REC-sparql11-update-20130321/

Limitation

The API requires that you specify a GRAPH in your SPARQL update request. Insertions or deletions to the default graph are not supported.

Response Codes

CodeReason
200 OKSPARQL Update was successful.
400 Bad RequestIncorrect HTTP method; only POST is accepted.
HTTP request did not include an update parameter.
SPARQL Update request did not specify a GRAPH on which to operate.
SPARQL Update request was syntactically incorrect.
403 ForbiddenHTTP request did not include an email parameter.
HTTP request did not include a password parameter.
The combination of email and password is not valid.
The selected VIVO account is not authorized to use the SPARQL Update API.
500 Internal Server ErrorVIVO could not execute the request; internal code threw an exception.

Examples

This example, written in Python, shows some INSERT and DELETE operations using the API. (Thanks to Ted Lawless of Brown University)

"""
Examples of using the Vitro SPARQL update in development.
https://jira.duraspace.org/browse/VIVO-101
 
http://www.w3.org/Submission/SPARQL-Update/
"""
 
from SPARQLWrapper import SPARQLWrapper
 
import time
 
email = 'email@school.edu'
password = 'password'
endpoint = 'http://localhost:8080/vitro/sparql/'
 
 
def do_update(query):
    params = {
        'email': email,
        'password': password,
        'update': query
    }
    sparql = SPARQLWrapper(endpoint)
    sparql.customParameters = params
    sparql.method = 'GET'
    results = sparql.query()
    #print out the query url
    print results.response.geturl()
 
 
#insert some data.
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA INTO <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "New Title" . }
"""
do_update(q)
 
#for testing purposes only - delay to check data in web app
time.sleep(5)
 
#modify it
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
DELETE DATA FROM <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "New Title" . }
INSERT DATA INTO <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "Second Title" . }
"""
do_update(q)
 
time.sleep(5)
 
#delete it
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
DELETE DATA FROM <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "Second Title" . }
"""
do_update(q)

 

Enabling the API

Security

Authentication

 

  • No labels