sparql-examples

A set of SPARQL examples that are used in different SIB resources

View the Project on GitHub sib-swiss/sparql-examples

examples012

rq turtle/ttl

List interactions and traits of all species which have an IUCN status (wdt:P141) of near threatened (wd:Q719675).

Use at

PREFIX emi: <https://purl.org/emi#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX qudt: <https://qudt.org/2.1/schema/qudt#>		
SELECT DISTINCT ?source_wd ?sourceName ?tryDataLab ?tryDataVal ?unit ?unitComment WHERE {
	?trySpObs sosa:isSampleOf ?source_trySpName ; #retrieve trait/non-trait data from trydb for trySpName (scientific name of plant species as listed in trydb)
		rdfs:label ?sourceName ;
		sosa:isFeatureOfInterestOf ?tryObId .
	?source_trySpName emi:inTaxon ?source_wd . #retrieve wikidata-id for trySpName		
	?tryObId sosa:hasResult ?tryData .
	?tryData rdfs:label ?tryDataLab ;			
		rdf:type emi:Trait ; #filter data which is labelled as 'Trait'
		rdf:value ?tryDataVal ;	#retrieve values for Trait data
		qudt:hasUnit ?unit . #retrieve units for Trait data
	OPTIONAL {
		?tryData rdfs:comment ?unitComment .
	} #retrieve comments (containing original unprocessed unit information - necessary for understanding some data) for Trait data
	SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
        	?source_wd wdt:P141 wd:Q719675 . #filter wikidata-ids for trySpName, which have IUCN status (wdt:P141) as near threatened (wd:Q719675)
        }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?sourceName"):::projected 
  v2("?source_trySpName")
  v5("?source_wd"):::projected 
  v6("?tryData")
  v7("?tryDataLab"):::projected 
  v8("?tryDataVal"):::projected 
  v4("?tryObId")
  v1("?trySpObs")
  v9("?unit"):::projected 
  v10("?unitComment"):::projected 
  c7(["emi:Trait"]):::iri 
  c13(["wd:Q719675"]):::iri 
  v1 --"sosa:isSampleOf"-->  v2
  v1 --"rdfs:label"-->  v3
  v1 --"sosa:isFeatureOfInterestOf"-->  v4
  v2 --"emi:inTaxon"-->  v5
  v4 --"sosa:hasResult"-->  v6
  v6 --"rdfs:label"-->  v7
  v6 --"a"-->  c7
  v6 --"rdf:value"-->  v8
  v6 --https://qudt.org/2.1/schema/qudt#hasUnit-->  v9
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v6 -."rdfs:comment".->  v10
  end
  subgraph s1["https://qlever.cs.uni-freiburg.de/api/wikidata"]
    style s1 stroke-width:4px;
    v5 --"wdt:P141"-->  c13
  end