Next / Previous / Contents / Shipman's homepage

4.10. Txny.__readTaxonomy()

This method reads the root taxonomy node and recursively adds its descendants.

txny.py
# - - -   T x n y . _ _ r e a d T a x o n o m y   - - -

    def __readTaxonomy ( self, taxonomyNode ):
        """Build the taxonomy subtree.

          [ taxonomyNode is a TAXONOMY_N Element node ->
              self.root  :=  a Taxon object made from root's TAXONOMY_N
                  subtree, with children representing that subtree
              self.__txKeyMap  :=  as invariant, from that subtree
              self.__sciMap    :=  as invariant, from that subtree ]
        """

First we find the taxon node that roots the classification tree:

txny.py
        #-- 1 --
        # [ rootTaxonNode  :=  the TAXON_N node child of taxonomyNode ]
        rootTaxonNode  =  taxonomyNode.xpath ( rnc.TAXON_N )[0]

Then we recursively transform that node and its descendants into a tree of Taxon objects, storing the new root object in self.root:

txny.py
        #-- 2 --
        # [ self.root  :=  a new Taxon object representing rootTaxonNode
        #       and having descendants made from the descendants of
        #       rootTaxonNode ]
        self.root  =  Taxon ( self, None, rootTaxonNode )

We still need to add entries to our internal maps so we can find taxa by taxonomic key or by scientific name:

txny.py
        #-- 3 --
        # [ self.__txKeyMap  :=  as invariant, from self.root and its
        #       descendants
        #   self.__sciMap    :=  as invariant, from self.root and its
        #       descendants ]
        self.__buildMaps()