A set of SPARQL examples that are used in different SIB resources
List interactions of all species which have an IUCN status (wdt:P141) of near threatened (wd:Q719675).
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#>
SELECT DISTINCT ?wdx_Source ?sourceNameURI ?intxnLabel ?intxnType ?wdx_Target ?targetNameURI WHERE {
{ SELECT DISTINCT ?wdx_Target ?targetName ?sourceName ?wdx_Source ?intxnType WHERE { #first select the source-target interaction-pairs
?intxn emi:hasSource ?source ;
emi:hasTarget ?target ;
emi:isClassifiedWith ?intxnType . #unidirectional interaction, e.g.: source-X hosts target target-Y
?intxnType rdfs:label ?intxnLabel .
?source emi:inTaxon ?wdx_Source ; #retrieve wikidata-id for source
sosa:isSampleOf ?sourceName . #scientific name of source as given in GloBI
?target emi:inTaxon ?wdx_Target ; #retrieve wikidata-id for target
sosa:isSampleOf ?targetName . #scientific name of target as given in GloBI
}}
SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
{
?wdx_Source wdt:P141 wd:Q719675 ; #filter source wikidata ids, which have IUCN status (wdt:P141) as near threatened (wd:Q719675) and which is a plant
wdt:P171* wd:Q879246 .
} UNION
{
?wdx_Target wdt:P141 wd:Q719675 ; #filter target wikidata ids, which have IUCN status (wdt:P141) as near threatened (wd:Q719675) and which is a plant
wdt:P171* wd:Q879246 .
}
}
BIND(REPLACE(STR(?sourceName), "%20", " ") AS ?sourceNameX) #remove percent-encoding for scientific names of source-X
BIND(IRI(?sourceNameX) AS ?sourceNameURI)
BIND(REPLACE(STR(?targetName), "%20", " ") AS ?targetNameX) #remove percent-encoding for scientific names of target-Y
BIND(IRI(?targetNameX) AS ?targetNameURI)
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?intxn")
v5("?intxnLabel"):::projected
v4("?intxnType"):::projected
v2("?source")
v7("?sourceName")
v11("?sourceNameURI"):::projected
v10("?sourceNameX")
v3("?target")
v9("?targetName")
v13("?targetNameURI"):::projected
v12("?targetNameX")
v6("?wdx_Source"):::projected
v8("?wdx_Target"):::projected
c11(["wd:Q879246"]):::iri
c9(["wd:Q719675"]):::iri
v1 --"emi:hasSource"--> v2
v1 --"emi:hasTarget"--> v3
v1 --"emi:isClassifiedWith"--> v4
v4 --"rdfs:label"--> v5
v2 --"emi:inTaxon"--> v6
v2 --"sosa:isSampleOf"--> v7
v3 --"emi:inTaxon"--> v8
v3 --"sosa:isSampleOf"--> v9
subgraph s1["https://qlever.cs.uni-freiburg.de/api/wikidata"]
style s1 stroke-width:4px;
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v8 --"wdt:P141"--> c9
v8 --"wdt:P171"--> c11
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v6 --"wdt:P141"--> c9
v6 --"wdt:P171"--> c11
end
union0r <== or ==> union0l
end
end
bind0[/"replace(str(?sourceName),'%20',' ')"/]
v7 --o bind0
bind0 --as--o v10
bind1[/"?sourceNameX"/]
v10 --o bind1
bind1 --as--o v11
bind2[/"replace(str(?targetName),'%20',' ')"/]
v9 --o bind2
bind2 --as--o v12
bind3[/"?targetNameX"/]
v12 --o bind3
bind3 --as--o v13