@prefix ex: <https://kg.earthmetabolome.org/metrin/api/.well-known/examples/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spex:<https://purl.expasy.org/sparql-examples/ontology#> .

ex:012 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "List traits of all species which have an IUCN status (wdt:P141) of near threatened (wd:Q719675)."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX emi: <https://w3id.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/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.dev/api/wikidata> {
        	?source_wd wdt:P141 wd:Q719675 . #filter wikidata-ids for trySpName, which have IUCN status (wdt:P141) as near threatened (wd:Q719675)
        }
}""" ;
    schema:target <https://kg.earthmetabolome.org/metrin/api/> ;
    spex:federatesWith <https://qlever.dev/api/wikidata> .
