Because multiple forms of birds may appear in one photo,
each photo may be added under multiple names. In that
.addArchImage() method is called
once for each name.
Hence, this method operates on not just a catalog entry
ArchImage object from the
archindex.py module), but also on a
BirdId object (from the
abbr.py module) that represents the kind of
# - - - T a x o n P h o t o S e t . a d d A r c h I m a g e def addArchImage(self, birdId, archImage): '''Add one photo to the report under a given birdId '''
Adding a new photo to the structure always starts at the
root node, by calling its
method. In general, this operation is recursive. It may
involve the addition of multiple new taxa to the tree,
starting at the top and terminating at the taxon to which
the photo is referred.
Depending on whether the given
referred to self's taxon or not, there are two cases.
Basis case: if the
birdId is referred
to self's taxon, no new child nodes need to be added
under this one. First, make sure that self has a
FormPhotoSet for this bird name, then
add the photo to that
Recursive case: if the
referred to a descendant of self, first insure that
nodes are added to self's subtree down to the
referred taxon's node, then add the photo to that
The first order of business is to separate the two
taxon attribute of a
BirdId object is the taxon to which that form is
referred. The comparison function (
.__cmp__()) in the
compares instances according to their
txKey attribute, so we can use the
ordinary Python “
comparison to see if they are the same taxon.
For the internal methods that handle the two cases, see
Section 11.3, “
TaxonPhotoSet._addReferred(): Basis case” and Section 11.4, “
#-- 1 # [ if self.taxon is the same as birdId.taxon -> # self.nReferred +:= 1 # self._formMap := self._formMap with archImage added # under the name from birdId # else -> # self._childMap := self._childMap with new descendant # nodes added as necessary down to birdId.taxon, # and archImage added under the name from birdId to # the node for birdId.taxon ] if self.taxon == birdId.taxon: #-- 1.1 self._addReferred(birdId, archImage) self.nReferred += 1 else: #-- 1.2 self._addContained(birdId, archImage)
The final step is bookkeeping: counting the number of photos in this subtree.
#-- 2 self.nContained += 1