Each Rank instance represents one
taxonomic rank (e.g., order, family, species) used in the
classification.
Since users do not need to call this constructor
directly, it functions only during the translation of XML
nodes. Accordingly, the constructor takes two arguments:
a pointer back to the containing Hier instance, and the node describing
the rank.
# - - - - - c l a s s R a n k - - - - -
class Rank:
"""Represents one taxonomic rank.
Exports:
Rank ( hier, rankNode ):
[ (hier is the containing Hier instance) and
(rankNode is a RANK_N node) ->
return a new Rank instance in hier representing
rankNode ]
.code: [ self's rank code ]
.depth: [ self's depth, 0 for the root ]
.keyLen: [ length of self's portion of the taxonomic key ]
.name: [ English name of the rank ]
.isOptional:
[ if this rank can be omitted -> 1
else -> 0 ]
"""
Here is the trivial constructor.
# - - - R a n k . _ _ i n i t _ _ - - -
def __init__ ( self, hier, rankNode ):
"""Constructor for a Rank instance.
"""
#-- 1 --
self.hier = hier
#-- 2 --
# [ self.code := the CODE_A attribute of rankNode
# self.depth := the DEPTH_A attribute of rankNode as int
# self.keyLen := the DIGITS_A attribute of rankNode
# self.name := the text content of rankNode
# self.isOptional := true iff rankNode has an
# OPTIONAL_A attribute ]
self.code = rankNode.attrib[rnc.CODE_A]
self.depth = int ( rankNode.attrib[rnc.DEPTH_A] )
self.keyLen = int ( rankNode.attrib[rnc.DIGITS_A] )
self.name = rankNode.text.strip()
self.isOptional = int ( rankNode.attrib.get(
rnc.OPTIONAL_A, 0) )