I’m trying to write a query that retrieves all the species of flowers in Wikidata.
As far as I understood, flowers are represented by class Q506: https://www.wikidata.org/wiki/Q506. Therefore I tried to retrieve all the instances of this class. I used this query:
SELECT DISTINCT ?flower ?flowerLabel
WHERE
{
?flower wdt:P31 wd:Q506 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
However this query returns only 19 objects. This number is nowhere near the number of flowers I expected.
Then I tried searching for the subclasses of class Q506. I used this query:
SELECT DISTINCT ?flower ?flowerLabel
WHERE {
?flower wdt:P279 wd:Q506.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
I got only 26 results. And again this is not what I expected.
I also tried some other approaches. For example I tried to start from the class of Angiosperms (Q25314) and go back to the species of flowers using a series of parent taxon properties (P171). However I didn’t get all the results I needed since some popular flowers were still missing.
I’m sure there is a way to get the information I need since there are WikiMedia pages that contain exactly what I want. For example there is this Category page of flowers: https://commons.wikimedia.org/wiki/Category:Flowers. And there is also a page with Commons media, which is what I ultimately want to reproduce: https://commons.wikimedia.org/wiki/Flowers.
I’m trying to write the query for Wikidata, but for me it would be fine to use other databases, like DBpedia for example.
I think the tricky part here is that there is not really a scientific definition of what is a flower so the way it has been added in Wikidata is sporadic.
Your notion of using Angiosperms is probably better and if we select species (Q7432) and traverse parent taxons (through P171*
) we can get them all. But it runs into the trouble that there are too many and that the query times out. However, with a limit and putting the label service outside that subquery, we do get some results:
SELECT ?flower ?flowerLabel ?image WITH {
SELECT ?flower WHERE {
?flower wdt:P105 wd:Q7432 ;
wdt:P171* wd:Q25314 .
} LIMIT 1000
} AS %f
WHERE {
INCLUDE %f
OPTIONAL { ?flower wdt:P18 ?image }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}