Store a species name, optionally qualified with an authority.
When comparing two names, the authority of each will be simplified to try to overcome differences in format and punctuation. For example:
a = Name("Lablab purpureus", "(L.) Sweet")
b = Name("Lablab purpureus","Sweet.")
c = Name("Lablab purpureus", "Sweet. ex. MadeUp.")
a == b
a == c
b == c # All True
Bases: taxonome.taxa.collection.TaxaResource
This allows storing a collection of taxa, along with synonymy and easy lookup by name, whether or not the name is qualified with an authority.
Looking up synonyms that have been added returns the taxon, but looping through it will ignore synonyms.
There is currently no option to delete a taxon. Instead, build a new TaxonSet with only the taxa you want to keep.
Usage example:
mygenus = TaxonSet()
Lp = Taxon("Lablab purpureus", "(L.) Sweet")
Lp.othernames.add(Name("Dolichos lablab", "L."))
Lp.othernames.add(Name("Vigna aristata", "Piper"))
mygenus.add(Lp)
# Unqualified name:
"Lablab purpureus" in mygenus # -> True
"Dolichos lablab" in mygenus # -> True
"Lablab vulgaris" in mygenus # -> False
mygenus.resolve("Lablab purpureus") # -> List of possible Taxon() objects
mygenus.resolve("Dolichos lablab") # (will usually only have one item)
mygenus.select("Lablab purpureus") # -> Picks the best match (may ask the
# user to select from alternatives)
# Qualified name:
Name("Lablab purpureus", "(L.) Sweet") in mygenus # -> True
Name("Lablab purpureus", "Sweet") in mygenus # -> True
mygenus.select(Name("Dolichos lablab", "L.")) # Returns a Taxon() object
A base class for classes holding indexed collections of taxa.
Not designed to be instantiated.
May be defined by subclass. Called with a Name object known to be an accepted name in this resource. Should return the corresponding taxon.
Must be defined by subclass. The name given may be a string or a Name object.
Return a list of 3-tuples, (name, accepted_name, id), where the id can be passed to get_by_id() to retrieve the associated taxon.
Select a taxon by name. If there is more than one match, an interactive prompt will ask the user to choose.
Match one set of taxa against another by name.
A TaxonSet, containing copies of the input taxa, with the .name attribute replaced with the name of the corresponding taxon from target_ts, .othernames cleared, and .info combined with taxa mapping to the same name.
Taxa which fail to match send a ‘no match’ event to the tracker.
Combine several taxa datasets into one.
Each should be a sequence of 2-tuples, (name, taxonset). The name will be used as the key in the taxa’s info. All taxa from any target dataset are included in the output, whereas information from background datasets is only copied to taxa in target datasets. There must be at least one target dataset, and at least one other (either target or background).
Target datasets may be any iterable collection of taxa. Background datasets should be TaxonSets or similar.
A function to combine the information dicts for a taxon. It takes three parameters: the taxon object, the information dict to be added, and the name of a dataset.
The default will nest information under the names of the datasets. The add_info_flat() function will make a flat dictionary.
Returns: A TaxonSet.