Next / Previous / Contents / Shipman's homepage

22.3. SpTail.__checkEng(): Check the English name

nomcompile3
# - - -   S p T a i l . _ _ c h e c k E n g

    def __checkEng ( self, scan, rawEng ):
        '''Check, store, and canonically abbreviate the English name.

          [ (scan is a Scan instance) and
            (rawEng is a string) ->
              if rawEng is a valid English name ->
                self.eng  :=  rawEng
                self.canonical  :=  abbrMod.abbreviate ( eng-normalize (
                                    rawEng ) )
              else ->
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

For the function that validates English names, see Section 30, “validateEng(): Validate an English name”.

nomcompile3
        #-- 1 --
        # [ if rawEng is a valid English name ->
        #     I
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        validateEng ( scan, rawEng )

We also produce a normalized version (e.g., "Black Duck" instead of "Duck, Black"), which will be used to form the canonical abbreviation. For the functions that normalize and abbreviate English names, see the specification for the abbr.py module.

nomcompile3
        #-- 2 --
        # [ self.eng  :=  rawEng
        #   normEng  :=  rawEng, normalized ]
        self.eng = rawEng
        normEng = abbrMod.engDeComma ( rawEng )

The abbrMod.abbreviate() function uppercases the code, but short codes are returned with trailing spaces, which we must strip here.

nomcompile3
        #-- 3 --
        # [ self.canonical  :=  the canonical bird code derived
        #                       from rawEng ]
        self.canonical = abbrMod.abbreviate(normEng).strip()