0

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.

V310RG
  • 11
  • 2
  • 1
    are you really looking for the "flower" represented by Q506? I mean, did you check its description? Or are you looking for flowering plants represented by Q886167? Q506 is just a part of Q886167, mostly the colorful upper part. – UninformedUser Mar 25 '23 at 06:38
  • also, you can use SPARQL property paths, i.e. `?flower wdt:P31/wdt:P279* wd:Q506 .` which gets "all instances of subclasses of X" – UninformedUser Mar 25 '23 at 06:39
  • Also, how many flower entities do you expect in Wikidata? I can find Rosa or Tulip, but for example not even Daisy Star or Violet - ok, I don't know that many flower names, but I'm wondering how many and in which form occur in Wikidata at all? – UninformedUser Mar 25 '23 at 06:44
  • Yes, unfortunately I’m trying to find the flowers, not flowering plants. Even with `?flower wdt:P31/wdt:P279* wd:Q506 .` I’m still getting only 22 results. I even tried with `wd: Q886167` just for the sake of it, and I got 5 results. There is definitely missing something. – V310RG Mar 25 '23 at 11:42
  • @V310RG I think what you're missing is a botanical definition of "species of flower". Before understanding _how_ to search, it would be important to know _what_ to search for. – logi-kal Mar 25 '23 at 18:29
  • @logi-kal I specified what I wanted quite clearly. I provided the link to this WikiMedia page: https://commons.wikimedia.org/wiki/Flowers. In this page flowers are categorized by “species”. This is the “species of flowers” I was referring to. And I used the expression “species of flowers” exactly because it’s the expression used in WikiMedia/Wikidata, since I’m trying to search them in Wikidata. – V310RG Mar 25 '23 at 20:12
  • However the expression “species of flowers” might be ambiguous here, since flowers are just a part of flowering plants, while these seem to be flowering plants. This is why I tried to search for flowering plants too. Unfortunately I didn’t get what I wanted. But if for Wikidata flowers are just flowering plants, assume that I wanted to search flowering plants. Hopefully I clarified my objective now. – V310RG Mar 25 '23 at 20:13
  • If what you find in https://commons.wikimedia.org/wiki/Flowers#Flowers_by_species is an exhaustive list of species, then just use that set of species. Otherwise, if that list contains only _some_ of the species that you're interested on, then it doesn't help in uniquely defining what you're looking for. – logi-kal Mar 25 '23 at 22:26
  • "I used the expression “species of flowers” exactly because it’s the expression used in WikiMedia/Wikidata": actually [I can't find anywhere](https://www.wikidata.org/w/index.php?search=%22species+of+flowers%22&title=Special:Search&profile=advanced&fulltext=1&ns0=1&ns120=1) the expression "species of flowers" on Wikidata. – logi-kal Mar 25 '23 at 22:27
  • @logi-kal The expression “species of flowers” is the expression I used to illustrate my problem. You asked me what kind of “species” of flowers I was searching. So I specified that my meaning of “species” what the same meaning used in this page: commons.wikimedia.org/wiki/Flowers. In this page the word “species” is used in the expression “flowers by species”. And in fact the expression “flowers by species” can be found on Wikidata too: https://www.wikidata.org/wiki/Q109122718. Hopefully I clarified what I meant with “species of flowers” now. – V310RG Mar 25 '23 at 23:39

1 Answers1

1

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". }
} 
Ainali
  • 1,613
  • 13
  • 23