Old Release

This documentation relates to an old version of VIVO, version 1.9.x. Looking for another version? See all documentation.

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

Compare with Current View Page History

« Previous Version 11 Next »

Overview

SPARQL is a query language for RDF-based systems such as Vitro and VIVO.  Using SPARQL one can extract any information from VIVO or Vitro, producing reports, or providing data for other software such as visualizations or user interfaces.

Running SPARQL queries

To run a SPARQL query, navigate to Site Admin > Sparql query.  You will see a page similar to the one below.  Note that the text is in various colors.  VIVO uses the YASQE editor for SPARQL.  You can read more about its features at their web site. See http://yasqe.yasgui.org/  At the top of the Query window are SPARQL prefix declarations for VIVO.  These provides abbreviations for various URLs you use in your SPARQL queries.  For more on SPARQL, see Learning SPARQL.  http://learningsparql.com   Below the prefix declarations is the actual SPARQL query.  

The query in the figure above asks for a sorted list of the entities in VIVO that have type Relationship.  RS_TEXT has been selected as an output format.  This will display in a browser window.  Note that you can select CSV, or TSV.  These will download to your computer.  You may also select RS_XML and RS_JSON – these will also display in your browser window.

Running the above Query in OpenVIVO generates over 10,000 rows of output.  The beginning of the output in JSON format is shown below:

First few lines of JSON output for preceding query
{
  "head": {
    "vars": [ "s" , "p" , "o" ]
  } ,
  "results": {
    "bindings": [
      {
        "s": { "type": "uri" , "value": "http://openvivo.org/a/doi10.4225/03/58ca600d726bd-authorship1" }
      } ,
      {
        "s": { "type": "uri" , "value": "http://openvivo.org/a/doi10.4225/03/58ca600d726bd-authorship2" }
      } ,
      {
        "s": { "type": "uri" , "value": "http://openvivo.org/a/doi10.6084/m9.figshare.2002020-authorship1" }
      } ,
      {
        "s": { "type": "uri" , "value": "http://openvivo.org/a/doi10.6084/m9.figshare.2002200-authorship1" }
      } ,
      {
        "s": { "type": "uri" , "value": "http://openvivo.org/a/doi10.6084/m9.figshare.2002200-authorship2" }
      } ,


Using SPARQL for reporting

SPRQL can be used to extract data from VIVO for reporting.  Using the TSV (tab separated values) output format, the results of a SPARQL query can be downloaded from VIVO and uploaded to a spreadsheet, reporting or presentation tool.

The query below makes a contact list for all people in particular academic unit.

#
# Find all the people with a position in the CTSI or any CTSI sub-unit,
# and list them alphabetically with phone, email, gatorlink, eracommons if any
#
SELECT ?person (MIN(DISTINCT ?xname) AS ?name) 
    (MIN(DISTINCT ?xphone) AS ?phone)
    (MIN(DISTINCT ?xemail) AS ?email)
    (MIN(DISTINCT ?xgatorlink) AS ?gatorlink)
    (MIN(DISTINCT ?xeracommons) AS ?eracommons)
WHERE {
  {?pos vivo:relates <http://vivo.ufl.edu/individual/n8763427> . ?pos a vivo:Position .}
  UNION
  {<http://vivo.ufl.edu/individual/n8763427> obo:BFO_0000051 ?sub .
   ?pos vivo:relates ?sub . ?pos a vivo:Position .}
  ?pos vivo:dateTimeInterval ?dt .
  OPTIONAL {?dt vivo:end ?end . }
  FILTER (!BOUND(?end))  # current positions do not have end dates
  ?pos vivo:relates ?person . ?person a foaf:Person .
  ?person rdfs:label ?xname .
  ?person a ufVivo:UFCurrentEntity .
  ?person obo:ARG_2000028 ?vcard .
  OPTIONAL { ?vcard vcard:hasEmail ?email_thing . ?email_thing vcard:email  ?xemail .}
  OPTIONAL { ?vcard vcard:hasTelephone ?tel_thing . ?tel_thing vcard:telephone ?xphone .}
  OPTIONAL { ?person ufVivo:gatorlink ?xgatorlink .}
  OPTIONAL { ?person vivo:eRACommonsId ?xeracommons .}
}
GROUP BY ?person
ORDER BY ?name

For additional examples, some much simpler than the example above, see Mike Conlon's web site http://mconlon17.github.io/sparql 

Using SPARQL to manage data

ASK Queries

Vitro SPARQL supports ASK queries which return either true (there are triples that satisfy the pattern), or false (there are no triples that satisfy the pattern).  The query below will return true in most VIVOs and false in a new VIVO.

ASK Query
ASK { ?s a vivo:Relationship . }


Additional SPARQL Resources

  • No labels