sparql-examples

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

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

examples011b

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 dcterms: <http://purl.org/dc/terms/>
                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 ?sourceNameURI ?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)
				  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)
                    	}
			BIND(REPLACE(STR(?source_trySpName), "%20", " ") AS ?sourceNameX) 		#remove percent-encoding for trySpName
			BIND(IRI(?sourceNameX) AS ?sourceNameURI)
		}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v11("?sourceNameURI"):::projected 
  v10("?sourceNameX")
  v2("?source_trySpName")
  v4("?source_wd"):::projected 
  v5("?tryData")
  v6("?tryDataLab"):::projected 
  v7("?tryDataVal"):::projected 
  v3("?tryObId")
  v1("?trySpObs")
  v8("?unit"):::projected 
  v9("?unitComment"):::projected 
  c7(["emi:Trait"]):::iri 
  c13(["wd:Q719675"]):::iri 
  v1 --"sosa:isSampleOf"-->  v2
  v1 --"sosa:isFeatureOfInterestOf"-->  v3
  v2 --"emi:inTaxon"-->  v4
  v3 --"sosa:hasResult"-->  v5
  v5 --"rdfs:label"-->  v6
  v5 --"a"-->  c7
  v5 --"rdf:value"-->  v7
  v5 --https://qudt.org/2.1/schema/qudt#hasUnit-->  v8
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v5 -."rdfs:comment".->  v9
  end
  subgraph s1["https://qlever.cs.uni-freiburg.de/api/wikidata"]
    style s1 stroke-width:4px;
    v4 --"wdt:P141"-->  c13
  end
  bind0[/"replace(str(?source_trySpName),'%20',' ')"/]
  v2 --o bind0
  bind0 --as--o v10
  bind1[/"?sourceNameX"/]
  v10 --o bind1
  bind1 --as--o v11