Next / Previous / Contents / Shipman's homepage

6.21. Txny.__readAbbrs()

This method handles building the .__abbrMap dictionary from the ABBR_SET_N node.

xnomo3.py
# - - -   T x n y . _ _ r e a d A b b r s   - - -

    def __readAbbrs ( self, abbrSetNode ):
        """Read the ABBR_SET_N subtree and build self.__abbrMap.

          [ abbrSetNode is a ABBR_SET_N node ->
              self.__abbrMap  :=  a dictionary whose keys are the
                  valid bird codes in self, with the corresponding
                  values the Taxon instance for each code
              self.__abbrEng  :=  as invariant, from that subtree ]
        """
        #-- 1 --
        # [ self.__abbrMap  :=  a new, empty dictionary
        #   self.__abbrEng  :=  a new, empty dictionary
        #   abbrNodeList    :=  list of the ABBR_N children of
        #                       abbrSetNode ]
        self.__abbrMap = {}
        self.__abbrEng = {}
        abbrNodeList = abbrSetNode.findall(rnc.ABBR_N)

For the logic that standardizes a bird code, see Section 11.6, “fixAbbr(): Standardize a bird code”. For the logic that normalizes an English name, see Section 11.5, “engDeComma(): Normalize an English name”.

xnomo3.py
        #-- 2 --
        # [ 
        for  abbrNode in abbrNodeList:
            #-- 2 body --
            # [ abbrNode is a ABBR_N Element whose SCI_A attribute
            #   is a scientific name defined in self.__sciMap ->
            #     self.__abbrMap  +:=  an entry mapping the standardized
            #         CODE_A attribute of abbrNode |-> the Taxon
            #         in self with that scientific name
            #     self.__abbrEng  +:=  an entry mapping the standardized
            #         CODE_A attribute of abbrNode |-> the text content
            #         of abbrNode ]

            #-- 2.1 --
            # [ abbr  :=  abbrNode's rnc.CODE_A attribute value,
            #             standardized
            #   sci  :=  abbrNode's rnc.SCI_A attribute value
            #   rawEng  :=  abbrNode's text content ]
            abbr = abbrMod.fixAbbr(abbrNode.attrib[rnc.CODE_A])
            sci = abbrNode.attrib[rnc.SCI_A]
            rawEng = abbrNode.text.strip()

            #-- 2.2 --
            # [ sci is a key in self.__sciMap ->
            #     taxon  :=  the related Taxon instance ]
            taxon = self.__sciMap[sci]

            #-- 2.3 --
            # [ abbrNode's 
            self.__abbrEng[abbr] = rawEng
            self.__abbrMap[abbr] = taxon