Koetai SPARQL examples

Community-curated SPARQL example queries for multiple life-science endpoints.

View the Project on GitHub Koetai/sparql-examples

occurrences_in_the_guyana_shield

rq turtle/ttl

Most observations are country bound, yet regions exist that cross borders and sometimes only partly covers a country. The guyana shield is such a region. It covers 6 countries, of which 3 partly and 3 completely. These query combines the two sections

Use at

PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dwc:    <http://rs.tdwg.org/dwc/terms/>
PREFIX dwciri: <http://rs.tdwg.org/dwc/iri/>
PREFIX wdt:    <http://www.wikidata.org/prop/direct/>
PREFIX gbif:   <https://rs.gbif.org/terms/>

SELECT ?occ ?species (REPLACE(STR(?rank), "^.*/", "") AS ?rankLabel) ?geometry WHERE {
  ?occ dwciri:toTaxon ?t ;
       dwc:decimalLatitude  ?lat ;
       dwc:decimalLongitude ?lon ;
       dwc:countryCode ?cc ;
       wdt:P625 ?geometry .
  ?t rdfs:label ?species ;
     gbif:rank ?rank ;
     gbif:taxonomicStatus ?status .
  FILTER(?cc IN ("GY","SR","GF","VE","CO","BR"))
  FILTER(?lat >= -2 && ?lat <= 9 && ?lon >= -73 && ?lon <= -50)
  FILTER(STRENDS(LCASE(STR(?rank)),   "/species"))
  FILTER(STRENDS(LCASE(STR(?status)), "/accepted"))   # accepted taxa only
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?cc")
  v8("?geometry"):::projected 
  v3("?lat")
  v4("?lon")
  v6("?occ"):::projected 
  v2("?rank"):::projected 
  v10("?rankLabel")
  v9("?species"):::projected 
  v1("?status")
  v7("?t")
  f0[["ends-with(lower-case(str(?status)),'/accepted')"]]
  f0 --> v1
  f1[["ends-with(lower-case(str(?rank)),'/species')"]]
  f1 --> v2
  f2[["?lat >= '-2^^xsd:integer'?lat <= '9^^xsd:integer'?lon >= '-73^^xsd:integer'?lon <= '-50^^xsd:integer'"]]
  f2 --> v3
  f2 --> v4
  list0c6(["BR"]):::literal 
  list0c1(["GY"]):::literal 
  list0c5(["CO"]):::literal 
  list0c2(["SR"]):::literal 
  list0c3(["GF"]):::literal 
  list0c4(["VE"]):::literal 
  list0c1 --o f3
  list0c2 --o f3
  list0c3 --o f3
  list0c4 --o f3
  list0c5 --o f3
  list0c6 --o f3
  f3[[" in "]]
  f3 --> v5
  v6 --http://rs.tdwg.org/dwc/iri/toTaxon-->  v7
  v6 --http://rs.tdwg.org/dwc/terms/decimalLatitude-->  v3
  v6 --http://rs.tdwg.org/dwc/terms/decimalLongitude-->  v4
  v6 --http://rs.tdwg.org/dwc/terms/countryCode-->  v5
  v6 --"wdt:P625"-->  v8
  v7 --"rdfs:label"-->  v9
  v7 --https://rs.gbif.org/terms/rank-->  v2
  v7 --https://rs.gbif.org/terms/taxonomicStatus-->  v1
  bind4[/"replace(str(?rank),'^.*/','')"/]
  v2 --o bind4
  bind4 --as--o v10