A set of SPARQL examples
Which taxa have children (or themselves) with known chemicals, genes, and proteins?
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX hint: <http://www.bigdata.com/queryHints#>
#title: Which taxa have children (or themselves) with known chemicals, genes, and proteins?
SELECT ?taxon (COUNT(DISTINCT ?g) AS ?genome) (COUNT(DISTINCT ?m) AS ?metabolome) (COUNT(DISTINCT ?p) AS ?proteome) WHERE {
{
SELECT ?taxon ?thing WHERE {
VALUES ?taxon {
wd:Q31856
}
?taxon ^(wdt:P171*)/^wdt:P703 ?thing.
hint:Prior hint:rangeSafe true.
}
}
{
SELECT * WHERE {
VALUES ?chemical {
wd:Q113145171
wd:Q59199015
}
VALUES ?gene {
wd:Q7187
}
VALUES ?protein {
wd:Q8054
}
{
?thing wdt:P31 ?chemical.
hint:Prior hint:rangeSafe true.
BIND(?thing AS ?m)
}
UNION
{
?thing wdt:P31 ?protein.
hint:Prior hint:rangeSafe true.
BIND(?thing AS ?p)
}
UNION
{
?thing wdt:P31 ?gene.
hint:Prior hint:rangeSafe true.
BIND(?thing AS ?g)
}
}
}
}
GROUP BY ?taxon
HAVING (((?genome > 0 ) && (?metabolome > 0 )) && (?proteome > 0 ))
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?chemical")
v11("?g"):::projected
v7("?gene")
v12("?genome")
v9("?m"):::projected
v12("?metabolome")
v10("?p"):::projected
v8("?protein")
v12("?proteome")
v4("?taxon"):::projected
v5("?thing")
a1((" "))
c4([http://www.bigdata.com/queryHints#Prior]):::iri
c6(["true^^xsd:boolean"]):::literal
f0[["?genome > '0^^xsd:integer'?metabolome > '0^^xsd:integer'?proteome > '0^^xsd:integer'"]]
f0 --> v12
f0 --> v12
f0 --> v12
bind1[/VALUES ?taxon/]
bind1-->v4
bind10(["wd:Q31856"])
bind10 --> bind1
a1 --"wdt:P171"--> v4
v5 --"wdt:P703"--> a1
c4 --http://www.bigdata.com/queryHints#rangeSafe--> c6
bind2[/VALUES ?chemical/]
bind2-->v6
bind20(["wd:Q113145171"])
bind20 --> bind2
bind21(["wd:Q59199015"])
bind21 --> bind2
bind3[/VALUES ?gene/]
bind3-->v7
bind30(["wd:Q7187"])
bind30 --> bind3
bind4[/VALUES ?protein/]
bind4-->v8
bind40(["wd:Q8054"])
bind40 --> bind4
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v5 --"wdt:P31"--> v7
c4 --http://www.bigdata.com/queryHints#rangeSafe--> c6
bind5[/"?thing"/]
v5 --o bind5
bind5 --as--o v11
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v5 --"wdt:P31"--> v8
c4 --http://www.bigdata.com/queryHints#rangeSafe--> c6
bind6[/"?thing"/]
v5 --o bind6
bind6 --as--o v10
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v5 --"wdt:P31"--> v6
c4 --http://www.bigdata.com/queryHints#rangeSafe--> c6
bind7[/"?thing"/]
v5 --o bind7
bind7 --as--o v9
end
union0r <== or ==> union0l
end
bind11[/"count(?g)"/]
v11 --o bind11
bind11 --as--o v12
bind12[/"count(?m)"/]
v9 --o bind12
bind12 --as--o v12
bind13[/"count(?p)"/]
v10 --o bind13
bind13 --as--o v12