Next / Previous / Contents / Shipman's homepage

17.9. Txny.__checkGenus(): Add a new genus?

nomcompile3
# - - -   T x n y . _ _ c h e c k G e n u s

    def __checkGenus ( self, scan, spTail ):
        '''Try to add this genus if it is new.

          [ (scan is a Scan instance) and
            (spTail is an SpTail instance) ->
              if spTail names an existing genus in
              self.taxaTree ->
                I
              else if that genus can be appended to self.taxaTree ->
                self.taxaTree  +:=  that new genus
              else ->
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

If this genus has already been defined, we're done. Otherwise, assemble a RawTaxon instance with the various attributes of the new genus; see Section 23, “class RawTaxon: Temporary container for taxon attributes”.

nomcompile3
        #-- 1 --
        # [ if spTail.genus is a scientific name in self.taxaTree ->
        #     return
        #   else -> I ]
        try:
            oldGenus = self.taxaTree[spTail.genus]
            return
        except KeyError:
            pass

        #-- 2 --
        # [ rawGenus  :=  a new RawTaxon instance with rank code
        #       GENUS_CODE; scientific name (spTail.genus);
        #       English name (spTail.genus) enclosed in underbars;
        #       normal status, and no codes ]
        rawGenus = RawTaxon ( GENUS_CODE, spTail.genus,
            "_%s_" % spTail.genus, STATUS_NORMAL, None, None )

Next, append the new genus taxon, assuming that it is legal. Consider the case where there is nothing in the tree but Class Aves—clearly, we can't add a genus rank here, because there are several required ranks missing between them. See Section 17.7, “Txny.__appendTaxon(): Try to append this taxon to the tree”.

nomcompile3
        #-- 3 --
        # [ if rawGenus can be appended to self.taxaTree ->
        #     self.taxaTree  +:=  a new Taxon made from rawGenus
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        self.__appendTaxon ( scan, rawGenus )