# - - - u p d a t e C o m p o u n d A b b r s def updateCompoundAbbrs(c, txny): '''Replace codes in a compound form with modern equivalents. [ (c is a pycbc.Census instance with c.rel!=abbrMod.REL_SIMPLE) and (txny is an xnomo3.Txny instance) -> if c contains any outdate codes with modern equivalents in txny -> return a new pycbc.Census instance representing c but with either or both codes replaced by modern equivalents else -> return c ''' #-- 1 # [ if c.form has a modern equivalent in txny -> # newForm := that code in standard form # else -> # newForm := None ] newForm = fixOldAbbr(c.form, txny) #-- 2 # [ if c.alt_form has a modern equivalent in txny -> # newAltForm := that code in standard form # else -> # newAltForm := None ] newAltForm = fixOldAbbr(c.alt_form, txny)
At this point, if both lookups resulted in
None, we don't need to build a new
Census instance; we can just return the old one.
Otherwise we check each of the two values and, if either
None, we reinstate the original
#-- 3 # [ if (newForm is None) and (newAltForm is None) -> # return c # else if newForm is None -> # newForm := c.form # else -> # newAltForm := c.alt_form ] if (newForm is None) and (newAltForm is None): return c elif newForm is None: newForm = c.form else: newAltForm = c.alt_form #-- 4 # [ return a new pycbc.Census instance representing c, except with # c.form replaced by newForm and c.alt_form by newAltForm ] return lib.pycbc.CBCData.Census(c.lat, c.lon, c.year_no, c.year_key, c.seq_no, newForm, c.rel, newAltForm, c.age, c.sex, c.plus, c.q, c.census)