Koetai SPARQL examples

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

View the Project on GitHub Koetai/sparql-examples

taxa_on_wikidata_that_lack_a_gbif_id_property

rq turtle/ttl

This query matches taxa on Wikidata that lack a property linking to GBIF

Use at

PREFIX species: <https://www.gbif.org/species/>
PREFIX skos:    <http://www.w3.org/2004/02/skos/core#>
PREFIX gbif:    <https://rs.gbif.org/terms/>
PREFIX rank:    <https://rs.gbif.org/terms/rank/>
PREFIX status:  <https://rs.gbif.org/terms/status/>
PREFIX wdt:     <http://www.wikidata.org/prop/direct/>

SELECT ?wdItem ?pref ?sp ?key WHERE {
  ?sp skos:broader+ species:797 ;          # GBIF: within Lepidoptera
      gbif:rank rank:species ;
      gbif:taxonomicStatus status:accepted ;
      skos:prefLabel ?pref .               # ← the prefLabel exists on the GBIF side
  BIND(REPLACE(STR(?sp), "^.*/species/", "") AS ?key)
  SERVICE <https://qlever.dev/api/wikidata> {
    ?wdItem wdt:P225 ?pref .                # a Wikidata taxon with that same name...
    FILTER NOT EXISTS { ?wdItem wdt:P846 [] }   # ...but no GBIF ID
  }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?key"):::projected 
  v2("?pref"):::projected 
  v1("?sp"):::projected 
  v4("?wdItem"):::projected 
  a1((" "))
  c6([https://rs.gbif.org/terms/status/accepted]):::iri 
  c4([https://rs.gbif.org/terms/rank/species]):::iri 
  c2([https://www.gbif.org/species/797]):::iri 
  v1 --"skos:broader"-->  c2
  v1 --https://rs.gbif.org/terms/rank-->  c4
  v1 --https://rs.gbif.org/terms/taxonomicStatus-->  c6
  v1 --"skos:prefLabel"-->  v2
  bind0[/"replace(str(?sp),'^.*/species/','')"/]
  v1 --o bind0
  bind0 --as--o v3
  subgraph s1["https://qlever.dev/api/wikidata"]
    style s1 stroke-width:4px;
    f1[["not  "]]
    subgraph f1e0["Exists Clause"]
      e0v1 --"wdt:P846"-->  e0a1
      e0v1("?wdItem"):::projected 
      e0a1((" ")):::projected 
    end
    f1--EXISTS--> f1e0
    f1 --> v4
    f1 --> c9
    f1 --> a1
    v4 --"wdt:P846"-->  a1
    v4 --"wdt:P225"-->  v2
  end