def encode(self, word, primary_only=False):
def _after(word, pos, letters):<EOL><INDENT>"""<STR_LIT>"""<EOL>if pos > <NUM_LIT:0> and word[pos - <NUM_LIT:1>] in letters:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL><DEDENT>def _before(word, pos, letters):<EOL><INDENT>"""<STR_LIT>"""<EOL>if pos + <NUM_LIT:1> < len(word) and word[pos + <NUM_LIT:1>] in letters:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL><DEDENT>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>variants = []<EOL>if primary_only:<EOL><INDENT>variants = [word]<EOL><DEDENT>else:<EOL><INDENT>pos = <NUM_LIT:0><EOL>if word[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>variants.append(('<STR_LIT>', '<STR_LIT>'))<EOL>pos += <NUM_LIT:2><EOL><DEDENT>len_3_vars = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:O>',<EOL>'<STR_LIT>': '<STR_LIT:O>',<EOL>}<EOL>while pos < len(word):<EOL><INDENT>if word[pos : pos + <NUM_LIT:4>] == '<STR_LIT>':<EOL><INDENT>variants.append(('<STR_LIT>', '<STR_LIT:I>'))<EOL>pos += <NUM_LIT:4><EOL><DEDENT>elif word[pos : pos + <NUM_LIT:3>] in len_3_vars:<EOL><INDENT>variants.append(<EOL>(word[pos : pos + <NUM_LIT:3>], len_3_vars[word[pos : pos + <NUM_LIT:3>]])<EOL>)<EOL>pos += <NUM_LIT:3><EOL><DEDENT>elif word[pos : pos + <NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>variants.append(('<STR_LIT>', '<STR_LIT>'))<EOL>pos += <NUM_LIT:2><EOL><DEDENT>elif len(word[pos:]) == <NUM_LIT:3> and word[pos:] == '<STR_LIT>':<EOL><INDENT>variants.append(('<STR_LIT>', '<STR_LIT:O>'))<EOL>pos += <NUM_LIT:3><EOL><DEDENT>elif len(word[pos:]) == <NUM_LIT:1> and word[pos:] in {'<STR_LIT:A>', '<STR_LIT:O>'}:<EOL><INDENT>if word[pos:] == '<STR_LIT:O>':<EOL><INDENT>variants.append(('<STR_LIT:O>', '<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>variants.append(('<STR_LIT:A>', '<STR_LIT>'))<EOL><DEDENT>pos += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>variants.append((word[pos],))<EOL>pos += <NUM_LIT:1><EOL><DEDENT><DEDENT>variants = ['<STR_LIT>'.join(letters) for letters in product(*variants)]<EOL><DEDENT>def _haase_code(word):<EOL><INDENT>sdx = '<STR_LIT>'<EOL>for i in range(len(word)):<EOL><INDENT>if word[i] in self._uc_v_set:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>elif word[i] == '<STR_LIT:B>':<EOL><INDENT>sdx += '<STR_LIT:1>'<EOL><DEDENT>elif word[i] == '<STR_LIT:P>':<EOL><INDENT>if _before(word, i, {'<STR_LIT:H>'}):<EOL><INDENT>sdx += '<STR_LIT:3>'<EOL><DEDENT>else:<EOL><INDENT>sdx += '<STR_LIT:1>'<EOL><DEDENT><DEDENT>elif word[i] in {'<STR_LIT:D>', '<STR_LIT:T>'}:<EOL><INDENT>if _before(word, i, {'<STR_LIT:C>', '<STR_LIT:S>', '<STR_LIT>'}):<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>sdx += '<STR_LIT:2>'<EOL><DEDENT><DEDENT>elif word[i] in {'<STR_LIT:F>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>sdx += '<STR_LIT:3>'<EOL><DEDENT>elif word[i] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>sdx += '<STR_LIT:4>'<EOL><DEDENT>elif word[i] == '<STR_LIT:C>':<EOL><INDENT>if _after(word, i, {'<STR_LIT:S>', '<STR_LIT>'}):<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>elif i == <NUM_LIT:0>:<EOL><INDENT>if _before(<EOL>word,<EOL>i,<EOL>{'<STR_LIT:A>', '<STR_LIT:H>', '<STR_LIT>', '<STR_LIT:L>', '<STR_LIT:O>', '<STR_LIT>', '<STR_LIT:R>', '<STR_LIT>', '<STR_LIT:X>'},<EOL>):<EOL><INDENT>sdx += '<STR_LIT:4>'<EOL><DEDENT>else:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif _before(word, i, {'<STR_LIT:A>', '<STR_LIT:H>', '<STR_LIT>', '<STR_LIT:O>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:X>'}):<EOL><INDENT>sdx += '<STR_LIT:4>'<EOL><DEDENT>else:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif word[i] == '<STR_LIT:X>':<EOL><INDENT>if _after(word, i, {'<STR_LIT:C>', '<STR_LIT>', '<STR_LIT>'}):<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif word[i] == '<STR_LIT:L>':<EOL><INDENT>sdx += '<STR_LIT:5>'<EOL><DEDENT>elif word[i] in {'<STR_LIT:M>', '<STR_LIT:N>'}:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>elif word[i] == '<STR_LIT:R>':<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT>elif word[i] in {'<STR_LIT:S>', '<STR_LIT>'}:<EOL><INDENT>sdx += '<STR_LIT>'<EOL><DEDENT><DEDENT>sdx = self._delete_consecutive_repeats(sdx)<EOL>return sdx<EOL><DEDENT>encoded = tuple(_haase_code(word) for word in variants)<EOL>if len(encoded) > <NUM_LIT:1>:<EOL><INDENT>encoded_set = set()<EOL>encoded_single = []<EOL>for code in encoded:<EOL><INDENT>if code not in encoded_set:<EOL><INDENT>encoded_set.add(code)<EOL>encoded_single.append(code)<EOL><DEDENT><DEDENT>return tuple(encoded_single)<EOL><DEDENT>return encoded<EOL>
Return the Haase Phonetik (numeric output) code for a word.

        While the output code is numeric, it is nevertheless a str.

        Parameters
        ----------
        word : str
            The word to transform
        primary_only : bool
            If True, only the primary code is returned

        Returns
        -------
        tuple
            The Haase Phonetik value as a numeric string

        Examples
        --------
        >>> pe = Haase()
        >>> pe.encode('Joachim')
        ('9496',)
        >>> pe.encode('Christoph')
        ('4798293', '8798293')
        >>> pe.encode('Jörg')
        ('974',)
        >>> pe.encode('Smith')
        ('8692',)
        >>> pe.encode('Schmidt')
        ('8692', '4692')