# - - - s u b s p L u m p e r
def subspLumper(c, txny):
'''Implement subspecies lumping as a census-filter.
[ (c is a pycbc.Census instance) and
(txny is a taxonomy as an xnomo3.Txny instance) ->
if the form in c is not in txny ->
raise ScriptError
else if the form in c is a subspecies in txny ->
return a pycbc.Census instance representing the values from
(c) but with the form replaced by the code for the
containing species in txny
else -> return c ]
'''
The first level of analysis is to distinguish between
composite forms (where the rel code is
nonblank) and simple forms.
For a simple form, all we care about is whether the form attribute has rank deeper than species rank.
This is handled by the Section 10.20, “hist.cgi: lumpSimpleForm”.
For composite forms, subspecies lumping applies only when
both form and alt_form have
rank deeper than subspecies rank and
both are descendants of the same species. The logic for
this case is in Section 10.19, “hist.cgi: lumpCompoundForm”.
Because MySQL deblanks the census.rel field,
we must use a test that works for either one space or
an empty string.
#-- 1
# [ if c is a composite form ->
# if c.form and c.alt_form are defined in txny ->
# if c.form and c.alt_form are subspecies of
# the same species ->
# newForm := abbr for that species
# else -> return c
# else -> raise ScriptError
# else if c.form is defined in txny ->
# if c.form is a subspecies ->
# newForm := abbr for the species containing c.form
# else -> return census
# else -> raise Value Error ]
if c.rel.strip() != '':
#-- 1.1
# [ if c.form and c.alt_form are defined in txny ->
# if c.form and c.alt_form are subspecies of
# the same species ->
# newForm := code for that species
# else ->
# newForm := None
# else -> raise ScriptError ]
newForm = lumpCompoundForm(c, txny)
else:
#-- 1.2
# [ if c.form is defined in txny ->
# if c.form is a subspecies ->
# newForm := code for the containing species
# else ->
# newForm := None
# else -> raise ScriptError ]
newForm = lumpSimpleForm(c, txny)
If newForm is None at this
point, we know that no lumping occurred, so we can return our
argument unchanged.
When subspecies lumping has taken place, the result is always
a simple form, and newForm is the code for that
form.
#-- 2
if newForm is None:
return c
else:
return lib.pycbc.CBCData.Census(c.lat, c.lon,
c.year_no, c.year_key, c.seq_no,
newForm, abbrMod.REL_SIMPLE, abbrMod.BLANK_ABBR,
c.age, c.sex, c.plus, c.q, c.census)