Next / Previous / Contents / Shipman's homepage

24. class AbTab: The symbol table for codes

An instance of this class contains the entire symbol table, a container for AbSym instances, each representing one bird code. Here is the class interface.

nomcompile3
# - - - - -   c l a s s   A b T a b

class AbTab(object):
    '''Represents a symbol table for bird codes.

      Exports:
        AbTab():
          [ return a new, empty symbol table ]
        .addAbbr ( code ):
          [ code is a string containing a bird code ->
              if code.strip().upper() is in self ->
                return the associated AbSym instance
              else ->
                self  :=  self with a new, unbound AbSym
                    instance added for code.strip().upper()
                return that new AbSym instance ]
        .__getitem__ ( code ):
          [ code is a string ->
              if code is in self ->
                return the AbSym instance for code
              else -> raise KeyError ]
        .__iter__(self):
          [ generate the AbSym objects in self in ascending
            order by code ]
        .writeXML ( parent ):
          [ parent  :=  parent with an rnc.ABBR_SET_N element added
                representing codes in self linked to specific
                taxa, and an rnc.COLLISION_SET_N element added
                representing collision codes in self ]

Here are the internal structures of the class. The codes are uppercased and stripped of leading and trailing blanks to provide a case-insensitive match.

nomcompile3
      State/Invariants:
        .__abbrMap:
          [ a dictionary whose keys are the stripped, uppercased
            bird codes in self, and each related value is the
            AbSym instance for that code ]
    '''