query-dc259ee25aedf61ca8b80ab716659454
– perhaps this could be improved in the future.)GROUP BY. The labeling part may be useful in other biology queries as well. (But note that it produces a lot of intermediate results which are then squashed using the outer on Mastodon and on TwitterOriginally posted
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#defaultView:ImageGrid
SELECT ?flower (SAMPLE(?flowerLabel) AS ?flowerLabel) ?image WHERE {
{
SELECT ?flower (SAMPLE(?image) AS ?image) WHERE {
?flower wdt:P2827 ?color;
wdt:P18 ?image.
}
GROUP BY ?flower
HAVING(COUNT(DISTINCT ?color) > 1)
}
OPTIONAL { ?flower wdt:P1843 ?taxonCommonName. FILTER(LANGMATCHES(LANG(?taxonCommonName), "[AUTO_LANGUAGE]")) }
OPTIONAL { ?flower wdt:P1843 ?taxonCommonNameEn. FILTER(LANGMATCHES(LANG(?taxonCommonNameEn), "en")) }
OPTIONAL { ?flower wdt:P1843 ?taxonCommonNameAny. }
OPTIONAL { ?flower rdfs:label ?label. FILTER(LANGMATCHES(LANG(?label), "[AUTO_LANGUAGE]")) }
OPTIONAL { ?flower rdfs:label ?labelEn. FILTER(LANGMATCHES(LANG(?labelEn), "en")) }
OPTIONAL { ?flower rdfs:label ?labelAny. }
BIND(COALESCE(?taxonCommonName, ?label, ?taxonCommonNameEn, ?labelEn, ?taxonCommonNameAny, ?labelAny) AS ?flowerLabel)
}
GROUP BY ?flower ?image
ORDER BY MD5(CONCAT(STR(?flower), STR(NOW()))) # shuffle
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?_anon_42b5416610844a34809f33a099ae9de1153328")
v6("?color")
v1("?flower"):::projected
v12("?flowerLabel"):::projected
v9("?image"):::projected
v3("?label")
v10("?labelAny")
v2("?labelEn")
v5("?taxonCommonName")
v9("?taxonCommonNameAny")
v4("?taxonCommonNameEn")
a1((" "))
f0[[" > '1^^xsd:integer'"]]
f0 --> a1
v1 --"wdt:P2827"--> v6
v1 --"wdt:P18"--> v9
bind3[/"count(?color)"/]
v6 --o bind3
bind3 --as--o v8
bind4[/"sample(?image)"/]
v9 --o bind4
bind4 --as--o v9
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P1843".-> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P1843".-> v4
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P1843".-> v9
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v1 -."rdfs:label".-> v3
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v1 -."rdfs:label".-> v2
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v1 -."rdfs:label".-> v10
end
bind5[/"?taxonCommonName?label?taxonCommonNameEn?labelEn?taxonCommonNameAny?labelAny"/]
v5 --o bind5
v3 --o bind5
v4 --o bind5
v2 --o bind5
v9 --o bind5
v10 --o bind5
bind5 --as--o v12
bind7[/"sample(?flowerLabel)"/]
v12 --o bind7
bind7 --as--o v12