A set of SPARQL examples that are used in different SIB resources
Retrieve data of 4 traits in leaf economics spectrum.
PREFIX emi: <https://purl.org/emi#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX qudt: <https://qudt.org/2.1/schema/qudt#>
SELECT DISTINCT ?source_wdx ?sourceName ?traitCategory ?traitLabel ?tryDataVal ?unit ?unitComment WHERE
{
# trait data
# trait/non-trait data for trySpName (scientific name of plant species as listed in trydb)
?trySpObs sosa:isSampleOf ?trySpName ;
rdfs:label ?sourceName ;
sosa:isFeatureOfInterestOf ?tryObId .
?tryObId sosa:hasResult ?tryData .
?trySpName emi:inTaxon ?source_wdx . # wikidata-ids wdx for trySpName
?tryData rdfs:label ?traitLabel ;
rdf:type emi:Trait ; #retrieve data which is labelled as 'Trait' and its values
rdf:value ?tryDataVal ;
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
# retrieve trait labels
BIND (IF(REGEX(STR(?traitLabel),"SLA","i"),"Specific leaf area",IF(REGEX(STR(?traitLabel),"leaf dry matter content","i"),"Leaf dry matter content",IF(REGEX(STR(?traitLabel),"leaf nitrogen content","i"),"Leaf nitrogen content",IF(REGEX(STR(?traitLabel),"leaf phosphorus content","i"),"Leaf phosphorus content","Other")))) AS ?traitCategory)
# filter to LES categories only
FILTER (?traitCategory != "Other")
}
# group results and retain only the ones from organisms with all four traits available
GROUP BY ?source_wdx ?sourceName ?traitCategory ?traitLabel ?tryDataVal ?unit ?unitComment
HAVING (COUNT(?traitCategory) = 4)
# order by organism and trait names
ORDER BY ?source_wdx ?traitCategory
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v12("?_anon_39b94405334d4c98a94d4349b2e252701105")
v5("?sourceName"):::projected
v1("?source_wdx"):::projected
v12("?traitCategory"):::projected
v8("?traitLabel"):::projected
v7("?tryData")
v9("?tryDataVal"):::projected
v6("?tryObId")
v4("?trySpName")
v3("?trySpObs")
v10("?unit"):::projected
v11("?unitComment"):::projected
a1((" "))
c9(["emi:Trait"]):::iri
f0[[" = '4^^xsd:integer'"]]
f0 --> a1
f1[["?traitCategory != 'Other'"]]
f1 --> v12
v3 --"sosa:isSampleOf"--> v4
v3 --"rdfs:label"--> v5
v3 --"sosa:isFeatureOfInterestOf"--> v6
v6 --"sosa:hasResult"--> v7
v4 --"emi:inTaxon"--> v1
v7 --"rdfs:label"--> v8
v7 --"a"--> c9
v7 --"rdf:value"--> v9
v7 --https://qudt.org/2.1/schema/qudt#hasUnit--> v10
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."rdfs:comment".-> v11
end
bind2[/"if(regex(str(?traitLabel),'SLA','i'),'Specific leaf area',if(regex(str(?traitLabel),'leaf dry matter content','i'),'Leaf dry matter content',if(regex(str(?traitLabel),'leaf nitrogen content','i'),'Leaf nitrogen content',if(regex(str(?traitLabel),'leaf phosphorus content','i'),'Leaf phosphorus content','Other'))))"/]
v8 --o bind2
bind2 --as--o v12
bind4[/"count(?traitCategory)"/]
v12 --o bind4
bind4 --as--o v12