def encode(self, word, max_length=-<NUM_LIT:1>):
<EOL>if max_length != -<NUM_LIT:1>:<EOL><INDENT>max_length = max(<NUM_LIT:4>, max_length)<EOL><DEDENT>else:<EOL><INDENT>max_length = <NUM_LIT:64><EOL><DEDENT>ename = '<STR_LIT>'.join(c for c in word.upper() if c.isalnum())<EOL>ename = ename.replace('<STR_LIT>', '<STR_LIT>')<EOL>if not ename:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if ename[<NUM_LIT:0>:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>ename = ename[<NUM_LIT:1>:]<EOL><DEDENT>elif ename[<NUM_LIT:0>] == '<STR_LIT:X>':<EOL><INDENT>ename = '<STR_LIT:S>' + ename[<NUM_LIT:1>:]<EOL><DEDENT>elif ename[<NUM_LIT:0>:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>ename = '<STR_LIT>' + ename[<NUM_LIT:2>:]<EOL><DEDENT>elen = len(ename) - <NUM_LIT:1><EOL>metaph = '<STR_LIT>'<EOL>for i in range(len(ename)):<EOL><INDENT>if len(metaph) >= max_length:<EOL><INDENT>break<EOL><DEDENT>if (<EOL>ename[i] not in {'<STR_LIT>', '<STR_LIT:T>'}<EOL>and i > <NUM_LIT:0><EOL>and ename[i - <NUM_LIT:1>] == ename[i]<EOL>):<EOL><INDENT>continue<EOL><DEDENT>if ename[i] in self._uc_v_set and i == <NUM_LIT:0>:<EOL><INDENT>metaph = ename[i]<EOL><DEDENT>elif ename[i] == '<STR_LIT:B>':<EOL><INDENT>if i != elen or ename[i - <NUM_LIT:1>] != '<STR_LIT:M>':<EOL><INDENT>metaph += ename[i]<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:C>':<EOL><INDENT>if not (<EOL>i > <NUM_LIT:0><EOL>and ename[i - <NUM_LIT:1>] == '<STR_LIT:S>'<EOL>and ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._frontv<EOL>):<EOL><INDENT>if ename[i + <NUM_LIT:1> : i + <NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT:X>'<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._frontv:<EOL><INDENT>metaph += '<STR_LIT:S>'<EOL><DEDENT>elif i > <NUM_LIT:0> and ename[i - <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT:H>':<EOL><INDENT>if (<EOL>i == <NUM_LIT:0><EOL>and i + <NUM_LIT:1> < elen<EOL>and ename[i + <NUM_LIT:2> : i + <NUM_LIT:3>] not in self._uc_v_set<EOL>):<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT:X>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:D>':<EOL><INDENT>if (<EOL>ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT>'<EOL>and ename[i + <NUM_LIT:2> : i + <NUM_LIT:3>] in self._frontv<EOL>):<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT:T>'<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT>':<EOL><INDENT>if ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT:H>' and not (<EOL>i + <NUM_LIT:1> == elen or ename[i + <NUM_LIT:2> : i + <NUM_LIT:3>] not in self._uc_v_set<EOL>):<EOL><INDENT>continue<EOL><DEDENT>elif i > <NUM_LIT:0> and (<EOL>(i + <NUM_LIT:1> == elen and ename[i + <NUM_LIT:1>] == '<STR_LIT:N>')<EOL>or (i + <NUM_LIT:3> == elen and ename[i + <NUM_LIT:1> : i + <NUM_LIT:4>] == '<STR_LIT>')<EOL>):<EOL><INDENT>continue<EOL><DEDENT>elif (<EOL>i - <NUM_LIT:1> > <NUM_LIT:0><EOL>and i + <NUM_LIT:1> <= elen<EOL>and ename[i - <NUM_LIT:1>] == '<STR_LIT:D>'<EOL>and ename[i + <NUM_LIT:1>] in self._frontv<EOL>):<EOL><INDENT>continue<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._frontv:<EOL><INDENT>if i == <NUM_LIT:0> or ename[i - <NUM_LIT:1>] != '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:H>':<EOL><INDENT>if (<EOL>i > <NUM_LIT:0><EOL>and ename[i - <NUM_LIT:1>] in self._uc_v_set<EOL>and ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] not in self._uc_v_set<EOL>):<EOL><INDENT>continue<EOL><DEDENT>elif i > <NUM_LIT:0> and ename[i - <NUM_LIT:1>] in self._varson:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT:H>'<EOL><DEDENT><DEDENT>elif ename[i] in {'<STR_LIT:F>', '<STR_LIT>', '<STR_LIT:L>', '<STR_LIT:M>', '<STR_LIT:N>', '<STR_LIT:R>'}:<EOL><INDENT>metaph += ename[i]<EOL><DEDENT>elif ename[i] == '<STR_LIT>':<EOL><INDENT>if i > <NUM_LIT:0> and ename[i - <NUM_LIT:1>] == '<STR_LIT:C>':<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:P>':<EOL><INDENT>if ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT:H>':<EOL><INDENT>metaph += '<STR_LIT:F>'<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT:P>'<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>elif ename[i] == '<STR_LIT:S>':<EOL><INDENT>if (<EOL>i > <NUM_LIT:0><EOL>and i + <NUM_LIT:2> <= elen<EOL>and ename[i + <NUM_LIT:1>] == '<STR_LIT:I>'<EOL>and ename[i + <NUM_LIT:2>] in '<STR_LIT>'<EOL>):<EOL><INDENT>metaph += '<STR_LIT:X>'<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT:H>':<EOL><INDENT>metaph += '<STR_LIT:X>'<EOL><DEDENT>else:<EOL><INDENT>metaph += '<STR_LIT:S>'<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:T>':<EOL><INDENT>if (<EOL>i > <NUM_LIT:0><EOL>and i + <NUM_LIT:2> <= elen<EOL>and ename[i + <NUM_LIT:1>] == '<STR_LIT:I>'<EOL>and ename[i + <NUM_LIT:2>] in {'<STR_LIT:A>', '<STR_LIT:O>'}<EOL>):<EOL><INDENT>metaph += '<STR_LIT:X>'<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] == '<STR_LIT:H>':<EOL><INDENT>metaph += '<STR_LIT:0>'<EOL><DEDENT>elif ename[i + <NUM_LIT:1> : i + <NUM_LIT:3>] != '<STR_LIT>':<EOL><INDENT>if ename[i - <NUM_LIT:1> : i] != '<STR_LIT:T>':<EOL><INDENT>metaph += '<STR_LIT:T>'<EOL><DEDENT><DEDENT><DEDENT>elif ename[i] == '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT:F>'<EOL><DEDENT>elif ename[i] in '<STR_LIT>':<EOL><INDENT>if ename[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._uc_v_set:<EOL><INDENT>metaph += ename[i]<EOL><DEDENT><DEDENT>elif ename[i] == '<STR_LIT:X>':<EOL><INDENT>metaph += '<STR_LIT>'<EOL><DEDENT>elif ename[i] == '<STR_LIT>':<EOL><INDENT>metaph += '<STR_LIT:S>'<EOL><DEDENT><DEDENT>return metaph<EOL>
Return the Metaphone code for a word.

        Based on Lawrence Philips' Pick BASIC code from 1990
        :cite:`Philips:1990`, as described in :cite:`Philips:1990b`.
        This incorporates some corrections to the above code, particularly
        some of those suggested by Michael Kuhn in :cite:`Kuhn:1995`.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The maximum length of the returned Metaphone code (defaults to 64,
            but in Philips' original implementation this was 4)

        Returns
        -------
        str
            The Metaphone value

        Examples
        --------
        >>> pe = Metaphone()
        >>> pe.encode('Christopher')
        'KRSTFR'
        >>> pe.encode('Niall')
        'NL'
        >>> pe.encode('Smith')
        'SM0'
        >>> pe.encode('Schmidt')
        'SKMTT'