Positions in Organizations
Count the types of positions in each organization
Positions relate a person to an organization. Each position has a type – faculty, staff, etc. We would like to know how many positions of each type are in each organization, and which organizations have the most faculty, librarians, etc. The query below is a start. We could embellish the query with additional selections having to do with date ranges, positions per person, and so on.
The query selects positions and identifies their "most specific type" – this is a Vitro concept in which the various types associated with an entity are reduced to a single type for display purposes. The position must relate to an organization. In this query we show the uri of the organizaton and the position type in the results.
Code Block | ||||
---|---|---|---|---|
| ||||
SELECT ?org ?pos_type (COUNT(DISTINCT ?pos) AS ?pos_count)
WHERE {
?pos a vivo:Position .
?pos vitro:mostSpecificType ?pos_type .
?pos vivo:relates ?org .
?org a foaf:Organization .
}
GROUP BY ?pos_type ?org
ORDER BY ?pos_type DESC(?pos_count) ?org |
Individual Persons
Retrieve the positions for a single person
The query begins by finding the person of interest – here the person is identified by the value of a label. This may not return a single person. But for this example, let's assume it does. We could construct a query which selected the person based on their primary email or their ORCiD, or some other identifier. The query then gets all the relatedBy assertions for this person. VIVO uses relatedBy in many settings. The query then limits the results to insure that the relatedBy assertions relate a foaf:Person to a vivo:Position. The query then gets the labels for each position.
Note: The use of SELECT * returns all variables used in the query.
Code Block | ||||
---|---|---|---|---|
| ||||
SELECT *
WHERE {
?person rdfs:label 'Conlon, Michael' .
?person vivo:relatedBy ?position .
?person a foaf:Person .
?position a vivo:Position .
|
SPARQL: Tools, Tips, Sample queries
This page is just starting out and we hope can become a resource for useful snippets of information shared among members of the community.
Note that we have a Tools page in Sourceforge that lists more substantial contributions and extensions to VIVO.
Useful SPARQL queries
A little old but useful: SPARQL Queries for Data Management
finding instances having only a single rdf:type assertion
- This example query looks for individuals that have
- ONLY a vivoc:AcademicDegreeGrantingAgent type assertion
- Tested by substituting vivo:Address and looking at 1 of the results
Panel |
---|
CONSTRUCT { |
Publications
Code Block |
---|
SELECT ?doi ?infoResource_label ?pmid $type ?journal ?issn ?pubVenue ?issue ?startPage ?endPage ?volume ?dateTime
WHERE{
?infoResource vivo:hasPublicationVenue ?pubVenue .
?pubVenue rdf:type bibo:Journal .
?infoResource rdf:type $anyType .
?infoResource bibo:doi ?doi .
?infoResource bibo:pmid ?pmid .
?infoResource bibo:pageStart ?startPage .
?infoResource bibo:pageEnd ?endPage .
?pubVenue bibo:issn ?issn .
OPTIONAL { ?pubVenue bibo:volume ?volume } .
OPTIONAL { ?pubVenue vivo:DateTimeValue ?dateTime } .
OPTIONAL { ?pubVenue bibo:issue ?issue } .
?pubVenue rdfs:label ?journal .
?anyType rdfs:label ?type .
?infoResource rdfs:label $infoResource_label .
} |
Authors
...
?position rdfs:label ?position_label .
} |
...
Find Authors with less than 5 publications
Useful for finding good test cases, for example. This is a Vivo 1.5 example, but could be updated pretty easily.
Code Block |
---|
SELECT ?person
WHERE
{
?person vivo:authorInAuthorship ?authorship.
}
GROUP BY ?person
HAVING (COUNT(?authorship) < 5)
LIMIT 1 |
SPARQL Queries for Publications and Authors
Resolution:
SPARQL Example: Positions (RUN the exmaple here: http://senrabc.github.io/vivoSparqlExamples/)
Person and Positions Diagram (VIVO 1.4 Position diagram)
SPARQL Query to Retrieve the Position for a single Person
Live Results: (Note: You can click on the link below to run this query in realtime at http://sparql.vivo.ufl.edu. Be patient, it make take a few minutes to return.)
SPARQL QUERY
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX core: <http://vivoweb.org/ontology/core#>
PREFIX ands: <http://purl.org/ands/ontologies/vivo/>
SELECT * WHERE
{
?URI core:primaryEmail 'cpb@ufl.edu'.
?URI core:personInPosition ?positionURI.
?positionURI rdfs:label ?Postionlabel
}
Live Results in JSON:
JSON Result{
"head": {
"vars": [ "URI" , "positionURI" , "Postionlabel" ]
} ,
"results": {
"bindings": [
{
"URI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n64866" } ,
"positionURI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n136666" } ,
"Postionlabel": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "Assistant Director and Senior Architect" }
} ,
{
"URI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n64866" } ,
"positionURI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n31884" } ,
"Postionlabel": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "Associate Director" }
} ,
{
"URI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n64866" } ,
"positionURI": { "type": "uri" , "value": "http://vivo.ufl.edu/individual/n908759050" } ,
"Postionlabel": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "Associate Director, Software Engineering" }
}
]
}
}
Javascript Example to run query and get back JSON
Get the code herehttps://github.com/senrabc/vivoSparqlExamples/blob/master/SPARQLExamplePositions.html
Set it run here:
http://senrabc.github.io/vivoSparqlExamples/
References
Live Google Doc: https://docs.google.com/document/d/1FlGWCG0nqQ4TAVZmnKXiVMZnGxpygdcoxRcZsxw4UG0/edit#heading=h.jx71i6lwn9um
Static Document: SPARQLExamplePositions.pdf