Thanks Ian.
Feel free to give me any feedback on the code. I am still learning about the Tree syntax and the new TaxonomicSpecies entities. I used Graphs as they are so easy to create with rules and rules are also easy to manipulate. The nested structure in trees adds a layer of complexity. On the other hand, once I have a tree, they are very comfortable to analyze.
My use case for the ResourceFunction is:
- Use one known species and retrieve its taxonomy, visualized as a tree. If the Entity is a species-taxon: Ability to move up the taxa by a set number of levels. If the Entity is at a higher taxon: Ability to move down the taxa, where the entity's taxon is the root.
- Compare the taxonomy of two or more different species by exploiting the TaxonomicSequence.
For use case 2 I assumed every TaxonomicSequence is complete and consistent. It's not always the case. I was unable to create a RulesTree from the start as it turned out: is wasn't a tree. The issue can be shown in my "berrries" example. A graph showed me why: some vertices had an InDegree > 1, and this is simple to identify and correct in a graph.
In use case 1, the same issue may exist, and I did not have a proper solution for NestTree when I created the function. For example NestGraph Entity["TaxonomicSpecies", "Lonicera::3gqqp"] resulted in a graph that was not a tree. However, I believe NestTree may offer a solution after all as this works just fine
children[ent : Entity["TaxonomicSpecies", _]] :=
Replace[ent[
EntityProperty["TaxonomicSpecies",
"ChildTaxa"]], _Missing -> {}];
children[_] = {};
NestTree[children, Entity["TaxonomicSpecies", "Lonicera::3gqqp"], 2,
TreeLayout -> Left, TreeElementLabelFunction -> All -> CommonName,
MaxDisplayedChildren -> Infinity]
I will rewrite some of the code of TaxonomyTree in future also with new insights I have on the taxonomic structure in the entity framework.