def encode(self, word, mode=<NUM_LIT:1>, lang='<STR_LIT>'):

phonet_hash = Counter()<EOL>alpha_pos = Counter()<EOL>phonet_hash_1 = Counter()<EOL>phonet_hash_2 = Counter()<EOL>def _initialize_phonet(lang):<EOL><INDENT>"""<STR_LIT>"""<EOL>if lang == '<STR_LIT:none>':<EOL><INDENT>_phonet_rules = self._rules_no_lang<EOL><DEDENT>else:<EOL><INDENT>_phonet_rules = self._rules_german<EOL><DEDENT>phonet_hash['<STR_LIT>'] = -<NUM_LIT:1><EOL>for j in {<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>}:<EOL><INDENT>alpha_pos[j] = <NUM_LIT:1><EOL>phonet_hash[j] = -<NUM_LIT:1><EOL><DEDENT>for i, j in enumerate('<STR_LIT>'):<EOL><INDENT>alpha_pos[j] = i + <NUM_LIT:2><EOL>phonet_hash[j] = -<NUM_LIT:1><EOL><DEDENT>for i in range(<NUM_LIT>):<EOL><INDENT>for j in range(<NUM_LIT>):<EOL><INDENT>phonet_hash_1[i, j] = -<NUM_LIT:1><EOL>phonet_hash_2[i, j] = -<NUM_LIT:1><EOL><DEDENT><DEDENT>for i in range(len(_phonet_rules)):<EOL><INDENT>rule = _phonet_rules[i]<EOL>if rule and i % <NUM_LIT:3> == <NUM_LIT:0>:<EOL><INDENT>k = _phonet_rules[i][<NUM_LIT:0>]<EOL>if phonet_hash[k] < <NUM_LIT:0> and (<EOL>_phonet_rules[i + <NUM_LIT:1>] or _phonet_rules[i + <NUM_LIT:2>]<EOL>):<EOL><INDENT>phonet_hash[k] = i<EOL><DEDENT>if k and alpha_pos[k] >= <NUM_LIT:2>:<EOL><INDENT>k = alpha_pos[k]<EOL>j = k - <NUM_LIT:2><EOL>rule = rule[<NUM_LIT:1>:]<EOL>if not rule:<EOL><INDENT>rule = '<STR_LIT:U+0020>'<EOL><DEDENT>elif rule[<NUM_LIT:0>] == '<STR_LIT:(>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>rule = rule[<NUM_LIT:0>]<EOL><DEDENT>while rule and (rule[<NUM_LIT:0>] != '<STR_LIT:)>'):<EOL><INDENT>k = alpha_pos[rule[<NUM_LIT:0>]]<EOL>if k > <NUM_LIT:0>:<EOL><INDENT>if phonet_hash_1[j, k] < <NUM_LIT:0>:<EOL><INDENT>phonet_hash_1[j, k] = i<EOL>phonet_hash_2[j, k] = i<EOL><DEDENT>if phonet_hash_2[j, k] >= (i - <NUM_LIT:30>):<EOL><INDENT>phonet_hash_2[j, k] = i<EOL><DEDENT>else:<EOL><INDENT>k = -<NUM_LIT:1><EOL><DEDENT><DEDENT>if k <= <NUM_LIT:0>:<EOL><INDENT>if phonet_hash_1[j, <NUM_LIT:0>] < <NUM_LIT:0>:<EOL><INDENT>phonet_hash_1[j, <NUM_LIT:0>] = i<EOL><DEDENT>phonet_hash_2[j, <NUM_LIT:0>] = i<EOL><DEDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>def _phonet(term, mode, lang):<EOL><INDENT>"""<STR_LIT>"""<EOL>if lang == '<STR_LIT:none>':<EOL><INDENT>_phonet_rules = self._rules_no_lang<EOL><DEDENT>else:<EOL><INDENT>_phonet_rules = self._rules_german<EOL><DEDENT>char0 = '<STR_LIT>'<EOL>dest = term<EOL>if not term:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>term_length = len(term)<EOL>src = term.translate(self._upper_trans)<EOL>i = <NUM_LIT:0><EOL>j = <NUM_LIT:0><EOL>zeta = <NUM_LIT:0><EOL>while i < len(src):<EOL><INDENT>char = src[i]<EOL>pos = alpha_pos[char]<EOL>if pos >= <NUM_LIT:2>:<EOL><INDENT>xpos = pos - <NUM_LIT:2><EOL>if i + <NUM_LIT:1> == len(src):<EOL><INDENT>pos = alpha_pos['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>pos = alpha_pos[src[i + <NUM_LIT:1>]]<EOL><DEDENT>start1 = phonet_hash_1[xpos, pos]<EOL>start2 = phonet_hash_1[xpos, <NUM_LIT:0>]<EOL>end1 = phonet_hash_2[xpos, pos]<EOL>end2 = phonet_hash_2[xpos, <NUM_LIT:0>]<EOL>if (start2 >= <NUM_LIT:0>) and ((start1 < <NUM_LIT:0>) or (start2 < start1)):<EOL><INDENT>pos = start1<EOL>start1 = start2<EOL>start2 = pos<EOL>pos = end1<EOL>end1 = end2<EOL>end2 = pos<EOL><DEDENT>if (end1 >= start2) and (start2 >= <NUM_LIT:0>):<EOL><INDENT>if end2 > end1:<EOL><INDENT>end1 = end2<EOL><DEDENT>start2 = -<NUM_LIT:1><EOL>end2 = -<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>pos = phonet_hash[char]<EOL>start1 = pos<EOL>end1 = <NUM_LIT><EOL>start2 = -<NUM_LIT:1><EOL>end2 = -<NUM_LIT:1><EOL><DEDENT>pos = start1<EOL>zeta0 = <NUM_LIT:0><EOL>if pos >= <NUM_LIT:0>:<EOL><INDENT>while (_phonet_rules[pos] is None) or (<EOL>_phonet_rules[pos][<NUM_LIT:0>] == char<EOL>):<EOL><INDENT>if pos > end1:<EOL><INDENT>if start2 > <NUM_LIT:0>:<EOL><INDENT>pos = start2<EOL>start1 = start2<EOL>start2 = -<NUM_LIT:1><EOL>end1 = end2<EOL>end2 = -<NUM_LIT:1><EOL>continue<EOL><DEDENT>break<EOL><DEDENT>if (_phonet_rules[pos] is None) or (<EOL>_phonet_rules[pos + mode] is None<EOL>):<EOL><INDENT>pos += <NUM_LIT:3><EOL>continue<EOL><DEDENT>matches = <NUM_LIT:1>  <EOL>priority = <NUM_LIT:5>  <EOL>rule = _phonet_rules[pos]<EOL>rule = rule[<NUM_LIT:1>:]<EOL>while (<EOL>rule<EOL>and (len(src) > (i + matches))<EOL>and (src[i + matches] == rule[<NUM_LIT:0>])<EOL>and not rule[<NUM_LIT:0>].isdigit()<EOL>and (rule not in '<STR_LIT>')<EOL>):<EOL><INDENT>matches += <NUM_LIT:1><EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and (rule[<NUM_LIT:0>] == '<STR_LIT:(>'):<EOL><INDENT>if (<EOL>(len(src) > (i + matches))<EOL>and src[i + matches].isalpha()<EOL>and (src[i + matches] in rule[<NUM_LIT:1>:])<EOL>):<EOL><INDENT>matches += <NUM_LIT:1><EOL>while rule and rule[<NUM_LIT:0>] != '<STR_LIT:)>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>if rule:<EOL><INDENT>priority0 = ord(rule[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>priority0 = <NUM_LIT:0><EOL><DEDENT>matches0 = matches<EOL>while rule and rule[<NUM_LIT:0>] == '<STR_LIT:->' and matches > <NUM_LIT:1>:<EOL><INDENT>matches -= <NUM_LIT:1><EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>] == '<STR_LIT:<>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>].isdigit():<EOL><INDENT>priority = int(rule[<NUM_LIT:0>])<EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if (<EOL>not rule<EOL>or (<EOL>(rule[<NUM_LIT:0>] == '<STR_LIT>')<EOL>and ((i == <NUM_LIT:0>) or not src[i - <NUM_LIT:1>].isalpha())<EOL>and (<EOL>(rule[<NUM_LIT:1>:<NUM_LIT:2>] != '<STR_LIT:$>')<EOL>or (<EOL>not (<EOL>src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>].isalpha()<EOL>)<EOL>and (<EOL>src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>]<EOL>!= '<STR_LIT:.>'<EOL>)<EOL>)<EOL>)<EOL>)<EOL>or (<EOL>(rule[<NUM_LIT:0>] == '<STR_LIT:$>')<EOL>and (i > <NUM_LIT:0>)<EOL>and src[i - <NUM_LIT:1>].isalpha()<EOL>and (<EOL>(<EOL>not src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>].isalpha()<EOL>)<EOL>and (<EOL>src[i + matches0 : i + matches0 + <NUM_LIT:1>]<EOL>!= '<STR_LIT:.>'<EOL>)<EOL>)<EOL>)<EOL>):<EOL><INDENT>pos0 = -<NUM_LIT:1><EOL>start3 = <NUM_LIT:0><EOL>start4 = <NUM_LIT:0><EOL>end3 = <NUM_LIT:0><EOL>end4 = <NUM_LIT:0><EOL>if (<EOL>(matches > <NUM_LIT:1>)<EOL>and src[i + matches : i + matches + <NUM_LIT:1>]<EOL>and (priority0 != ord('<STR_LIT:->'))<EOL>):<EOL><INDENT>char0 = src[i + matches - <NUM_LIT:1>]<EOL>pos0 = alpha_pos[char0]<EOL>if pos0 >= <NUM_LIT:2> and src[i + matches]:<EOL><INDENT>xpos = pos0 - <NUM_LIT:2><EOL>pos0 = alpha_pos[src[i + matches]]<EOL>start3 = phonet_hash_1[xpos, pos0]<EOL>start4 = phonet_hash_1[xpos, <NUM_LIT:0>]<EOL>end3 = phonet_hash_2[xpos, pos0]<EOL>end4 = phonet_hash_2[xpos, <NUM_LIT:0>]<EOL>if (start4 >= <NUM_LIT:0>) and (<EOL>(start3 < <NUM_LIT:0>) or (start4 < start3)<EOL>):<EOL><INDENT>pos0 = start3<EOL>start3 = start4<EOL>start4 = pos0<EOL>pos0 = end3<EOL>end3 = end4<EOL>end4 = pos0<EOL><DEDENT>if (end3 >= start4) and (start4 >= <NUM_LIT:0>):<EOL><INDENT>if end4 > end3:<EOL><INDENT>end3 = end4<EOL><DEDENT>start4 = -<NUM_LIT:1><EOL>end4 = -<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>pos0 = phonet_hash[char0]<EOL>start3 = pos0<EOL>end3 = <NUM_LIT><EOL>start4 = -<NUM_LIT:1><EOL>end4 = -<NUM_LIT:1><EOL><DEDENT>pos0 = start3<EOL><DEDENT>if pos0 >= <NUM_LIT:0>:<EOL><INDENT>while (_phonet_rules[pos0] is None) or (<EOL>_phonet_rules[pos0][<NUM_LIT:0>] == char0<EOL>):<EOL><INDENT>if pos0 > end3:<EOL><INDENT>if start4 > <NUM_LIT:0>:<EOL><INDENT>pos0 = start4<EOL>start3 = start4<EOL>start4 = -<NUM_LIT:1><EOL>end3 = end4<EOL>end4 = -<NUM_LIT:1><EOL>continue<EOL><DEDENT>priority0 = -<NUM_LIT:1><EOL>break<EOL><DEDENT>if (_phonet_rules[pos0] is None) or (<EOL>_phonet_rules[pos0 + mode] is None<EOL>):<EOL><INDENT>pos0 += <NUM_LIT:3><EOL>continue<EOL><DEDENT>matches0 = matches<EOL>priority0 = <NUM_LIT:5><EOL>rule = _phonet_rules[pos0]<EOL>rule = rule[<NUM_LIT:1>:]<EOL>while (<EOL>rule<EOL>and (<EOL>src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>]<EOL>== rule[<NUM_LIT:0>]<EOL>)<EOL>and (<EOL>not rule[<NUM_LIT:0>].isdigit()<EOL>or (rule in '<STR_LIT>')<EOL>)<EOL>):<EOL><INDENT>matches0 += <NUM_LIT:1><EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>] == '<STR_LIT:(>':<EOL><INDENT>if src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>].isalpha() and (<EOL>src[i + matches0] in rule[<NUM_LIT:1>:]<EOL>):<EOL><INDENT>matches0 += <NUM_LIT:1><EOL>while rule and rule[<NUM_LIT:0>] != '<STR_LIT:)>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>while rule and rule[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>] == '<STR_LIT:<>':<EOL><INDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if rule and rule[<NUM_LIT:0>].isdigit():<EOL><INDENT>priority0 = int(rule[<NUM_LIT:0>])<EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if (<EOL>not rule<EOL>or<EOL>(<EOL>(rule[<NUM_LIT:0>] == '<STR_LIT:$>')<EOL>and not src[<EOL>i + matches0 : i + matches0 + <NUM_LIT:1><EOL>].isalpha()<EOL>and (<EOL>src[<EOL>i<EOL>+ matches0 : i<EOL>+ matches0<EOL>+ <NUM_LIT:1><EOL>]<EOL>!= '<STR_LIT:.>'<EOL>)<EOL>)<EOL>):<EOL><INDENT>if matches0 == matches:<EOL><INDENT>pos0 += <NUM_LIT:3><EOL>continue<EOL><DEDENT>if priority0 < priority:<EOL><INDENT>pos0 += <NUM_LIT:3><EOL>continue<EOL><DEDENT>break<EOL><DEDENT>pos0 += <NUM_LIT:3><EOL><DEDENT>if (priority0 >= priority) and (<EOL>(_phonet_rules[pos0] is not None)<EOL>and (_phonet_rules[pos0][<NUM_LIT:0>] == char0)<EOL>):<EOL><INDENT>pos += <NUM_LIT:3><EOL>continue<EOL><DEDENT><DEDENT>if _phonet_rules[pos] and (<EOL>'<STR_LIT:<>' in _phonet_rules[pos][<NUM_LIT:1>:]<EOL>):<EOL><INDENT>priority0 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>priority0 = <NUM_LIT:0><EOL><DEDENT>rule = _phonet_rules[pos + mode]<EOL>if (priority0 == <NUM_LIT:1>) and (zeta == <NUM_LIT:0>):<EOL><INDENT>if (<EOL>(j > <NUM_LIT:0>)<EOL>and rule<EOL>and (<EOL>(dest[j - <NUM_LIT:1>] == char)<EOL>or (dest[j - <NUM_LIT:1>] == rule[<NUM_LIT:0>])<EOL>)<EOL>):<EOL><INDENT>j -= <NUM_LIT:1><EOL><DEDENT>zeta0 = <NUM_LIT:1><EOL>zeta += <NUM_LIT:1><EOL>matches0 = <NUM_LIT:0><EOL>while rule and src[i + matches0]:<EOL><INDENT>src = (<EOL>src[<NUM_LIT:0> : i + matches0]<EOL>+ rule[<NUM_LIT:0>]<EOL>+ src[i + matches0 + <NUM_LIT:1> :]<EOL>)<EOL>matches0 += <NUM_LIT:1><EOL>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if matches0 < matches:<EOL><INDENT>src = (<EOL>src[<NUM_LIT:0> : i + matches0]<EOL>+ src[i + matches :]<EOL>)<EOL><DEDENT>char = src[i]<EOL><DEDENT>else:<EOL><INDENT>i = i + matches - <NUM_LIT:1><EOL>zeta = <NUM_LIT:0><EOL>while len(rule) > <NUM_LIT:1>:<EOL><INDENT>if (j == <NUM_LIT:0>) or (dest[j - <NUM_LIT:1>] != rule[<NUM_LIT:0>]):<EOL><INDENT>dest = (<EOL>dest[<NUM_LIT:0>:j]<EOL>+ rule[<NUM_LIT:0>]<EOL>+ dest[min(len(dest), j + <NUM_LIT:1>) :]<EOL>)<EOL>j += <NUM_LIT:1><EOL><DEDENT>rule = rule[<NUM_LIT:1>:]<EOL><DEDENT>if not rule:<EOL><INDENT>rule = '<STR_LIT>'<EOL>char = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>char = rule[<NUM_LIT:0>]<EOL><DEDENT>if (<EOL>_phonet_rules[pos]<EOL>and '<STR_LIT>' in _phonet_rules[pos][<NUM_LIT:1>:]<EOL>):<EOL><INDENT>if char:<EOL><INDENT>dest = (<EOL>dest[<NUM_LIT:0>:j]<EOL>+ char<EOL>+ dest[min(len(dest), j + <NUM_LIT:1>) :]<EOL>)<EOL>j += <NUM_LIT:1><EOL><DEDENT>src = src[i + <NUM_LIT:1> :]<EOL>i = <NUM_LIT:0><EOL>zeta0 = <NUM_LIT:1><EOL><DEDENT><DEDENT>break<EOL><DEDENT>pos += <NUM_LIT:3><EOL>if pos > end1 and start2 > <NUM_LIT:0>:<EOL><INDENT>pos = start2<EOL>start1 = start2<EOL>end1 = end2<EOL>start2 = -<NUM_LIT:1><EOL>end2 = -<NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if zeta0 == <NUM_LIT:0>:<EOL><INDENT>if char and ((j == <NUM_LIT:0>) or (dest[j - <NUM_LIT:1>] != char)):<EOL><INDENT>dest = (<EOL>dest[<NUM_LIT:0>:j] + char + dest[min(j + <NUM_LIT:1>, term_length) :]<EOL>)<EOL>j += <NUM_LIT:1><EOL><DEDENT>i += <NUM_LIT:1><EOL>zeta = <NUM_LIT:0><EOL><DEDENT><DEDENT>dest = dest[<NUM_LIT:0>:j]<EOL>return dest<EOL><DEDENT>_initialize_phonet(lang)<EOL>word = unicode_normalize('<STR_LIT>', text_type(word))<EOL>return _phonet(word, mode, lang)<EOL>

Return the phonet code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        mode : int
            The ponet variant to employ (1 or 2)
        lang : str
            ``de`` (default) for German, ``none`` for no language

        Returns
        -------
        str
            The phonet value

        Examples
        --------
        >>> pe = Phonet()
        >>> pe.encode('Christopher')
        'KRISTOFA'
        >>> pe.encode('Niall')
        'NIAL'
        >>> pe.encode('Smith')
        'SMIT'
        >>> pe.encode('Schmidt')
        'SHMIT'

        >>> pe.encode('Christopher', mode=2)
        'KRIZTUFA'
        >>> pe.encode('Niall', mode=2)
        'NIAL'
        >>> pe.encode('Smith', mode=2)
        'ZNIT'
        >>> pe.encode('Schmidt', mode=2)
        'ZNIT'

        >>> pe.encode('Christopher', lang='none')
        'CHRISTOPHER'
        >>> pe.encode('Niall', lang='none')
        'NIAL'
        >>> pe.encode('Smith', lang='none')
        'SMITH'
        >>> pe.encode('Schmidt', lang='none')
        'SCHMIDT'


return SoundD().encode(word, max_length)<EOL>

Return the SoundD code.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)

    Returns
    -------
    str
        The SoundD code

    Examples
    --------
    >>> sound_d('Gough')
    '2000'
    >>> sound_d('pneuma')
    '5500'
    >>> sound_d('knight')
    '5300'
    >>> sound_d('trice')
    '3620'
    >>> sound_d('judge')
    '2200'


def encode(self, word, max_length=<NUM_LIT:4>):

word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<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>if word[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[<NUM_LIT:1>:]<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT:X>':<EOL><INDENT>word = '<STR_LIT:S>' + word[<NUM_LIT:1>:]<EOL><DEDENT>elif word[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>word = '<STR_LIT>' + word[<NUM_LIT:2>:]<EOL><DEDENT>word = (<EOL>word.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT:0>')<EOL>)<EOL>word = word.translate(self._trans)<EOL>word = self._delete_consecutive_repeats(word)<EOL>word = word.replace('<STR_LIT:0>', '<STR_LIT>')<EOL>if max_length != -<NUM_LIT:1>:<EOL><INDENT>if len(word) < max_length:<EOL><INDENT>word += '<STR_LIT:0>' * (max_length - len(word))<EOL><DEDENT>else:<EOL><INDENT>word = word[:max_length]<EOL><DEDENT><DEDENT>return word<EOL>

Return the SoundD code.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)

        Returns
        -------
        str
            The SoundD code

        Examples
        --------
        >>> sound_d('Gough')
        '2000'
        >>> sound_d('pneuma')
        '5500'
        >>> sound_d('knight')
        '5300'
        >>> sound_d('trice')
        '3620'
        >>> sound_d('judge')
        '2200'


def phonex(word, max_length=<NUM_LIT:4>, zero_pad=True):

return Phonex().encode(word, max_length, zero_pad)<EOL>

Return the Phonex code for a word.

    This is a wrapper for :py:meth:`Phonex.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The Phonex value

    Examples
    --------
    >>> phonex('Christopher')
    'C623'
    >>> phonex('Niall')
    'N400'
    >>> phonex('Schmidt')
    'S253'
    >>> phonex('Smith')
    'S530'


def encode(self, word, max_length=<NUM_LIT:4>, zero_pad=True):

name = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>name = name.replace('<STR_LIT>', '<STR_LIT>')<EOL>if max_length != -<NUM_LIT:1>:<EOL><INDENT>max_length = min(max(<NUM_LIT:4>, max_length), <NUM_LIT:64>)<EOL><DEDENT>else:<EOL><INDENT>max_length = <NUM_LIT:64><EOL><DEDENT>name_code = last = '<STR_LIT>'<EOL>while name[-<NUM_LIT:1>:] == '<STR_LIT:S>':<EOL><INDENT>name = name[:-<NUM_LIT:1>]<EOL><DEDENT>if name[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>name = '<STR_LIT:N>' + name[<NUM_LIT:2>:]  <EOL><DEDENT>elif name[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>name = '<STR_LIT:F>' + name[<NUM_LIT:2>:]  <EOL><DEDENT>elif name[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>name = '<STR_LIT:R>' + name[<NUM_LIT:2>:]  <EOL><DEDENT>if name:<EOL><INDENT>if name[<NUM_LIT:0>] == '<STR_LIT:H>':<EOL><INDENT>name = name[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>if name:<EOL><INDENT>if name[<NUM_LIT:0>] in self._uc_vy_set:<EOL><INDENT>name = '<STR_LIT:A>' + name[<NUM_LIT:1>:]<EOL><DEDENT>elif name[<NUM_LIT:0>] in {'<STR_LIT:B>', '<STR_LIT:P>'}:<EOL><INDENT>name = '<STR_LIT:B>' + name[<NUM_LIT:1>:]<EOL><DEDENT>elif name[<NUM_LIT:0>] in {'<STR_LIT>', '<STR_LIT:F>'}:<EOL><INDENT>name = '<STR_LIT:F>' + name[<NUM_LIT:1>:]<EOL><DEDENT>elif name[<NUM_LIT:0>] in {'<STR_LIT:C>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>name = '<STR_LIT:C>' + name[<NUM_LIT:1>:]<EOL><DEDENT>elif name[<NUM_LIT:0>] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>name = '<STR_LIT>' + name[<NUM_LIT:1>:]<EOL><DEDENT>elif name[<NUM_LIT:0>] in {'<STR_LIT:S>', '<STR_LIT>'}:<EOL><INDENT>name = '<STR_LIT:S>' + name[<NUM_LIT:1>:]<EOL><DEDENT>name_code = last = name[<NUM_LIT:0>]<EOL><DEDENT>for i in range(<NUM_LIT:1>, len(name)):<EOL><INDENT>code = '<STR_LIT:0>'<EOL>if name[i] in {'<STR_LIT:B>', '<STR_LIT:F>', '<STR_LIT:P>', '<STR_LIT>'}:<EOL><INDENT>code = '<STR_LIT:1>'<EOL><DEDENT>elif name[i] in {'<STR_LIT:C>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:S>', '<STR_LIT:X>', '<STR_LIT>'}:<EOL><INDENT>code = '<STR_LIT:2>'<EOL><DEDENT>elif name[i] in {'<STR_LIT:D>', '<STR_LIT:T>'}:<EOL><INDENT>if name[i + <NUM_LIT:1> : i + <NUM_LIT:2>] != '<STR_LIT:C>':<EOL><INDENT>code = '<STR_LIT:3>'<EOL><DEDENT><DEDENT>elif name[i] == '<STR_LIT:L>':<EOL><INDENT>if name[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._uc_vy_set or i + <NUM_LIT:1> == len(<EOL>name<EOL>):<EOL><INDENT>code = '<STR_LIT:4>'<EOL><DEDENT><DEDENT>elif name[i] in {'<STR_LIT:M>', '<STR_LIT:N>'}:<EOL><INDENT>if name[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in {'<STR_LIT:D>', '<STR_LIT>'}:<EOL><INDENT>name = name[: i + <NUM_LIT:1>] + name[i] + name[i + <NUM_LIT:2> :]<EOL><DEDENT>code = '<STR_LIT:5>'<EOL><DEDENT>elif name[i] == '<STR_LIT:R>':<EOL><INDENT>if name[i + <NUM_LIT:1> : i + <NUM_LIT:2>] in self._uc_vy_set or i + <NUM_LIT:1> == len(<EOL>name<EOL>):<EOL><INDENT>code = '<STR_LIT>'<EOL><DEDENT><DEDENT>if code != last and code != '<STR_LIT:0>' and i != <NUM_LIT:0>:<EOL><INDENT>name_code += code<EOL><DEDENT>last = name_code[-<NUM_LIT:1>]<EOL><DEDENT>if zero_pad:<EOL><INDENT>name_code += '<STR_LIT:0>' * max_length<EOL><DEDENT>if not name_code:<EOL><INDENT>name_code = '<STR_LIT:0>'<EOL><DEDENT>return name_code[:max_length]<EOL>

Return the Phonex code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The Phonex value

        Examples
        --------
        >>> pe = Phonex()
        >>> pe.encode('Christopher')
        'C623'
        >>> pe.encode('Niall')
        'N400'
        >>> pe.encode('Schmidt')
        'S253'
        >>> pe.encode('Smith')
        'S530'


return ParmarKumbharana().encode(word)<EOL>

Return the Parmar-Kumbharana encoding of a word.

    This is a wrapper for :py:meth:`ParmarKumbharana.encode`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The Parmar-Kumbharana encoding

    Examples
    --------
    >>> parmar_kumbharana('Gough')
    'GF'
    >>> parmar_kumbharana('pneuma')
    'NM'
    >>> parmar_kumbharana('knight')
    'NT'
    >>> parmar_kumbharana('trice')
    'TRS'
    >>> parmar_kumbharana('judge')
    'JJ'


word = word.upper()  <EOL>word = self._delete_consecutive_repeats(word)  <EOL>i = <NUM_LIT:0><EOL>while i < len(word):<EOL><INDENT>for match_len in range(<NUM_LIT:4>, <NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>if word[i : i + match_len] in self._rules[match_len]:<EOL><INDENT>repl = self._rules[match_len][word[i : i + match_len]]<EOL>word = word[:i] + repl + word[i + match_len :]<EOL>i += len(repl)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>i += <NUM_LIT:1><EOL><DEDENT><DEDENT>word = word[:<NUM_LIT:1>] + word[<NUM_LIT:1>:].translate(self._del_trans)  <EOL>return word<EOL>

Return the Parmar-Kumbharana encoding of a word.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The Parmar-Kumbharana encoding

        Examples
        --------
        >>> pe = ParmarKumbharana()
        >>> pe.encode('Gough')
        'GF'
        >>> pe.encode('pneuma')
        'NM'
        >>> pe.encode('knight')
        'NT'
        >>> pe.encode('trice')
        'TRS'
        >>> pe.encode('judge')
        'JJ'


return BeiderMorse().encode(<EOL>word, language_arg, name_mode, match_mode, concat, filter_langs<EOL>)<EOL>

Return the Beider-Morse Phonetic Matching encoding(s) of a term.

    This is a wrapper for :py:meth:`BeiderMorse.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    language_arg : str
        The language of the term; supported values include:

            - ``any``
            - ``arabic``
            - ``cyrillic``
            - ``czech``
            - ``dutch``
            - ``english``
            - ``french``
            - ``german``
            - ``greek``
            - ``greeklatin``
            - ``hebrew``
            - ``hungarian``
            - ``italian``
            - ``latvian``
            - ``polish``
            - ``portuguese``
            - ``romanian``
            - ``russian``
            - ``spanish``
            - ``turkish``

    name_mode : str
        The name mode of the algorithm:

            - ``gen`` -- general (default)
            - ``ash`` -- Ashkenazi
            - ``sep`` -- Sephardic

    match_mode : str
        Matching mode: ``approx`` or ``exact``
    concat : bool
        Concatenation mode
    filter_langs : bool
        Filter out incompatible languages

    Returns
    -------
    tuple
        The Beider-Morse phonetic value(s)

    Examples
    --------
    >>> bmpm('Christopher')
    'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir xristofir
    xristYfir xristopi xritopir xritopi xristofi xritofir xritofi
    tzristopir tzristofir zristopir zristopi zritopir zritopi zristofir
    zristofi zritofir zritofi'
    >>> bmpm('Niall')
    'nial niol'
    >>> bmpm('Smith')
    'zmit'
    >>> bmpm('Schmidt')
    'zmit stzmit'

    >>> bmpm('Christopher', language_arg='German')
    'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir xristofir
    xristYfir'
    >>> bmpm('Christopher', language_arg='English')
    'tzristofir tzrQstofir tzristafir tzrQstafir xristofir xrQstofir
    xristafir xrQstafir'
    >>> bmpm('Christopher', language_arg='German', name_mode='ash')
    'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir xristofir
    xristYfir'

    >>> bmpm('Christopher', language_arg='German', match_mode='exact')
    'xriStopher xriStofer xristopher xristofer'


name = name.strip().lower()<EOL>rules = BMDATA[name_mode]['<STR_LIT>']<EOL>all_langs = (<EOL>sum(_LANG_DICT[_] for _ in BMDATA[name_mode]['<STR_LIT>']) - <NUM_LIT:1><EOL>)<EOL>choices_remaining = all_langs<EOL>for rule in rules:<EOL><INDENT>letters, languages, accept = rule<EOL>if search(letters, name) is not None:<EOL><INDENT>if accept:<EOL><INDENT>choices_remaining &= languages<EOL><DEDENT>else:<EOL><INDENT>choices_remaining &= (~languages) % (all_langs + <NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>if choices_remaining == L_NONE:<EOL><INDENT>choices_remaining = L_ANY<EOL><DEDENT>return choices_remaining<EOL>

Return the best guess language ID for the word and language choices.

        Parameters
        ----------
        name : str
            The term to guess the language of
        name_mode : str
            The name mode of the algorithm: ``gen`` (default),
            ``ash`` (Ashkenazi), or ``sep`` (Sephardic)

        Returns
        -------
        int
            Language ID


def _redo_language(<EOL>self, term, name_mode, rules, final_rules1, final_rules2, concat<EOL>):

language_arg = self._language(term, name_mode)<EOL>return self._phonetic(<EOL>term,<EOL>name_mode,<EOL>rules,<EOL>final_rules1,<EOL>final_rules2,<EOL>language_arg,<EOL>concat,<EOL>)<EOL>

Reassess the language of the terms and call the phonetic encoder.

        Uses a split multi-word term.

        Parameters
        ----------
        term : str
            The term to encode via Beider-Morse
        name_mode : str
            The name mode of the algorithm: ``gen`` (default),
            ``ash`` (Ashkenazi), or ``sep`` (Sephardic)
        rules : tuple
            The set of initial phonetic transform regexps
        final_rules1 : tuple
            The common set of final phonetic transform regexps
        final_rules2 : tuple
            The specific set of final phonetic transform regexps
        concat : bool
            A flag to indicate concatenation

        Returns
        -------
        str
            A Beider-Morse phonetic code


term = term.replace('<STR_LIT:->', '<STR_LIT:U+0020>').strip()<EOL>if name_mode == '<STR_LIT>':  <EOL><INDENT>for pfx in BMDATA['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>if term.startswith(pfx):<EOL><INDENT>remainder = term[len(pfx) :]<EOL>combined = pfx[:-<NUM_LIT:1>] + remainder<EOL>result = (<EOL>self._redo_language(<EOL>remainder,<EOL>name_mode,<EOL>rules,<EOL>final_rules1,<EOL>final_rules2,<EOL>concat,<EOL>)<EOL>+ '<STR_LIT:->'<EOL>+ self._redo_language(<EOL>combined,<EOL>name_mode,<EOL>rules,<EOL>final_rules1,<EOL>final_rules2,<EOL>concat,<EOL>)<EOL>)<EOL>return result<EOL><DEDENT><DEDENT><DEDENT>words = (<EOL>term.split()<EOL>)  <EOL>words2 = []<EOL>if name_mode == '<STR_LIT>':  <EOL><INDENT>for word in words:<EOL><INDENT>word = word[word.rfind('<STR_LIT>') + <NUM_LIT:1> :]<EOL>if word not in BMDATA['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>words2.append(word)<EOL><DEDENT><DEDENT><DEDENT>elif name_mode == '<STR_LIT>':  <EOL><INDENT>if len(words) > <NUM_LIT:1> and words[<NUM_LIT:0>] in BMDATA['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>words2 = words[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>words2 = list(words)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>words2 = list(words)<EOL><DEDENT>if concat:<EOL><INDENT>term = '<STR_LIT:U+0020>'.join(words2)<EOL><DEDENT>elif len(words2) == <NUM_LIT:1>:  <EOL><INDENT>term = words2[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>result = '<STR_LIT:->'.join(<EOL>[<EOL>self._redo_language(<EOL>w, name_mode, rules, final_rules1, final_rules2, concat<EOL>)<EOL>for w in words2<EOL>]<EOL>)<EOL>return result<EOL><DEDENT>term_length = len(term)<EOL>phonetic = '<STR_LIT>'<EOL>skip = <NUM_LIT:0><EOL>for i in range(term_length):<EOL><INDENT>if skip:<EOL><INDENT>skip -= <NUM_LIT:1><EOL>continue<EOL><DEDENT>found = False<EOL>for rule in rules:<EOL><INDENT>pattern = rule[_PATTERN_POS]<EOL>pattern_length = len(pattern)<EOL>lcontext = rule[_LCONTEXT_POS]<EOL>rcontext = rule[_RCONTEXT_POS]<EOL>if (pattern_length > term_length - i) or (<EOL>term[i : i + pattern_length] != pattern<EOL>):  <EOL><INDENT>continue<EOL><DEDENT>right = '<STR_LIT>' + rcontext<EOL>left = lcontext + '<STR_LIT:$>'<EOL>if rcontext != '<STR_LIT>':<EOL><INDENT>if not search(right, term[i + pattern_length :]):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if lcontext != '<STR_LIT>':<EOL><INDENT>if not search(left, term[:i]):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>candidate = self._apply_rule_if_compat(<EOL>phonetic, rule[_PHONETIC_POS], language_arg<EOL>)<EOL>if candidate is not None:  <EOL><INDENT>phonetic = candidate<EOL>found = True<EOL>break<EOL><DEDENT><DEDENT>if (<EOL>not found<EOL>):  <EOL><INDENT>pattern_length = <NUM_LIT:1><EOL><DEDENT>skip = pattern_length - <NUM_LIT:1><EOL><DEDENT>phonetic = self._apply_final_rules(<EOL>phonetic, final_rules1, language_arg, False<EOL>)  <EOL>phonetic = self._apply_final_rules(<EOL>phonetic, final_rules2, language_arg, True<EOL>)  <EOL>return phonetic<EOL>

Return the Beider-Morse encoding(s) of a term.

        Parameters
        ----------
        term : str
            The term to encode via Beider-Morse
        name_mode : str
            The name mode of the algorithm: ``gen`` (default),
            ``ash`` (Ashkenazi), or ``sep`` (Sephardic)
        rules : tuple
            The set of initial phonetic transform regexps
        final_rules1 : tuple
            The common set of final phonetic transform regexps
        final_rules2 : tuple
            The specific set of final phonetic transform regexps
        language_arg : int
            The language of the term
        concat : bool
            A flag to indicate concatenation

        Returns
        -------
        str
            A Beider-Morse phonetic code


def _apply_final_rules(self, phonetic, final_rules, language_arg, strip):

<EOL>if not final_rules:<EOL><INDENT>return phonetic<EOL><DEDENT>phonetic = self._expand_alternates(phonetic)<EOL>phonetic_array = phonetic.split('<STR_LIT:|>')<EOL>for k in range(len(phonetic_array)):<EOL><INDENT>phonetic = phonetic_array[k]<EOL>phonetic2 = '<STR_LIT>'<EOL>phoneticx = self._normalize_lang_attrs(phonetic, True)<EOL>i = <NUM_LIT:0><EOL>while i < len(phonetic):<EOL><INDENT>found = False<EOL>if phonetic[i] == '<STR_LIT:[>':  <EOL><INDENT>attrib_start = i<EOL>i += <NUM_LIT:1><EOL>while True:<EOL><INDENT>if phonetic[i] == '<STR_LIT:]>':<EOL><INDENT>i += <NUM_LIT:1><EOL>phonetic2 += phonetic[attrib_start:i]<EOL>break<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>continue<EOL><DEDENT>for rule in final_rules:<EOL><INDENT>pattern = rule[_PATTERN_POS]<EOL>pattern_length = len(pattern)<EOL>lcontext = rule[_LCONTEXT_POS]<EOL>rcontext = rule[_RCONTEXT_POS]<EOL>right = '<STR_LIT>' + rcontext<EOL>left = lcontext + '<STR_LIT:$>'<EOL>if (pattern_length > len(phoneticx) - i) or phoneticx[<EOL>i : i + pattern_length<EOL>] != pattern:<EOL><INDENT>continue<EOL><DEDENT>if rcontext != '<STR_LIT>':<EOL><INDENT>if not search(right, phoneticx[i + pattern_length :]):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if lcontext != '<STR_LIT>':<EOL><INDENT>if not search(left, phoneticx[:i]):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>candidate = self._apply_rule_if_compat(<EOL>phonetic2, rule[_PHONETIC_POS], language_arg<EOL>)<EOL>if candidate is not None:  <EOL><INDENT>phonetic2 = candidate<EOL>found = True<EOL>break<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>phonetic2 += phonetic[i]<EOL>pattern_length = <NUM_LIT:1><EOL><DEDENT>i += pattern_length<EOL><DEDENT>phonetic_array[k] = self._expand_alternates(phonetic2)<EOL><DEDENT>phonetic = '<STR_LIT:|>'.join(phonetic_array)<EOL>if strip:<EOL><INDENT>phonetic = self._normalize_lang_attrs(phonetic, True)<EOL><DEDENT>if '<STR_LIT:|>' in phonetic:<EOL><INDENT>phonetic = '<STR_LIT:(>' + self._remove_dupes(phonetic) + '<STR_LIT:)>'<EOL><DEDENT>return phonetic<EOL>

Apply a set of final rules to the phonetic encoding.

        Parameters
        ----------
        phonetic : str
            The term to which to apply the final rules
        final_rules : tuple
            The set of final phonetic transform regexps
        language_arg : int
            An integer representing the target language of the phonetic
            encoding
        strip : bool
            Flag to indicate whether to normalize the language attributes

        Returns
        -------
        str
            A Beider-Morse phonetic code


if '<STR_LIT:[>' in phonetic:<EOL><INDENT>return phonetic[: phonetic.find('<STR_LIT:[>')]<EOL><DEDENT>return phonetic<EOL>

Remove bracketed text from the end of a string.

        Parameters
        ----------
        phonetic : str
            A Beider-Morse phonetic encoding

        Returns
        -------
        str
            A Beider-Morse phonetic code


alt_start = phonetic.find('<STR_LIT:(>')<EOL>if alt_start == -<NUM_LIT:1>:<EOL><INDENT>return self._normalize_lang_attrs(phonetic, False)<EOL><DEDENT>prefix = phonetic[:alt_start]<EOL>alt_start += <NUM_LIT:1>  <EOL>alt_end = phonetic.find('<STR_LIT:)>', alt_start)<EOL>alt_string = phonetic[alt_start:alt_end]<EOL>alt_end += <NUM_LIT:1>  <EOL>suffix = phonetic[alt_end:]<EOL>alt_array = alt_string.split('<STR_LIT:|>')<EOL>result = '<STR_LIT>'<EOL>for i in range(len(alt_array)):<EOL><INDENT>alt = alt_array[i]<EOL>alternate = self._expand_alternates(prefix + alt + suffix)<EOL>if alternate != '<STR_LIT>' and alternate != '<STR_LIT>':<EOL><INDENT>if result != '<STR_LIT>':<EOL><INDENT>result += '<STR_LIT:|>'<EOL><DEDENT>result += alternate<EOL><DEDENT><DEDENT>return result<EOL>

Expand phonetic alternates separated by |s.

        Parameters
        ----------
        phonetic : str
            A Beider-Morse phonetic encoding

        Returns
        -------
        str
            A Beider-Morse phonetic code


alt_start = phonetic.find('<STR_LIT:(>')<EOL>if alt_start == -<NUM_LIT:1>:<EOL><INDENT>return '<STR_LIT:U+0020>' + self._phonetic_number(phonetic)<EOL><DEDENT>prefix = phonetic[:alt_start]<EOL>alt_start += <NUM_LIT:1>  <EOL>alt_end = phonetic.find('<STR_LIT:)>', alt_start)<EOL>alt_string = phonetic[alt_start:alt_end]<EOL>alt_end += <NUM_LIT:1>  <EOL>suffix = phonetic[alt_end:]<EOL>alt_array = alt_string.split('<STR_LIT:|>')<EOL>result = '<STR_LIT>'<EOL>for alt in alt_array:<EOL><INDENT>result += self._pnums_with_leading_space(prefix + alt + suffix)<EOL><DEDENT>return result<EOL>

Join prefixes & suffixes in cases of alternate phonetic values.

        Parameters
        ----------
        phonetic : str
            A Beider-Morse phonetic encoding

        Returns
        -------
        str
            A Beider-Morse phonetic code


phonetic_array = phonetic.split('<STR_LIT:->')  <EOL>result = '<STR_LIT:U+0020>'.join(<EOL>[self._pnums_with_leading_space(i)[<NUM_LIT:1>:] for i in phonetic_array]<EOL>)<EOL>return result<EOL>

Prepare & join phonetic numbers.

        Split phonetic value on '-', run through _pnums_with_leading_space,
        and join with ' '

        Parameters
        ----------
        phonetic : str
            A Beider-Morse phonetic encoding

        Returns
        -------
        str
            A Beider-Morse phonetic code


alt_string = phonetic<EOL>alt_array = alt_string.split('<STR_LIT:|>')<EOL>result = '<STR_LIT:|>'<EOL>for i in range(len(alt_array)):<EOL><INDENT>alt = alt_array[i]<EOL>if alt and '<STR_LIT:|>' + alt + '<STR_LIT:|>' not in result:<EOL><INDENT>result += alt + '<STR_LIT:|>'<EOL><DEDENT><DEDENT>return result[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL>

Remove duplicates from a phonetic encoding list.

        Parameters
        ----------
        phonetic : str
            A Beider-Morse phonetic encoding

        Returns
        -------
        str
            A Beider-Morse phonetic code


def _normalize_lang_attrs(self, text, strip):

uninitialized = -<NUM_LIT:1>  <EOL>attrib = uninitialized<EOL>while '<STR_LIT:[>' in text:<EOL><INDENT>bracket_start = text.find('<STR_LIT:[>')<EOL>bracket_end = text.find('<STR_LIT:]>', bracket_start)<EOL>if bracket_end == -<NUM_LIT:1>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>+ text<EOL>+ '<STR_LIT>'<EOL>+ text_type(strip)<EOL>+ '<STR_LIT:)>'<EOL>)<EOL><DEDENT>attrib &= int(text[bracket_start + <NUM_LIT:1> : bracket_end])<EOL>text = text[:bracket_start] + text[bracket_end + <NUM_LIT:1> :]<EOL><DEDENT>if attrib == uninitialized or strip:<EOL><INDENT>return text<EOL><DEDENT>elif attrib == <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return text + '<STR_LIT:[>' + str(attrib) + '<STR_LIT:]>'<EOL>

Remove embedded bracketed attributes.

        This (potentially) bitwise-ands bracketed attributes together and adds
        to the end.
        This is applied to a single alternative at a time -- not to a
        parenthesized list.
        It removes all embedded bracketed attributes, logically-ands them
        together, and places them at the end.
        However if strip is true, this can indeed remove embedded bracketed
        attributes from a parenthesized list.

        Parameters
        ----------
        text : str
            A Beider-Morse phonetic encoding (in progress)
        strip : bool
            Remove the bracketed attributes (and throw away)

        Returns
        -------
        str
            A Beider-Morse phonetic code

        Raises
        ------
        ValueError
            No closing square bracket


def _apply_rule_if_compat(self, phonetic, target, language_arg):

candidate = phonetic + target<EOL>if '<STR_LIT:[>' not in candidate:  <EOL><INDENT>return candidate<EOL><DEDENT>candidate = self._expand_alternates(candidate)<EOL>candidate_array = candidate.split('<STR_LIT:|>')<EOL>candidate = '<STR_LIT>'<EOL>found = False<EOL>for i in range(len(candidate_array)):<EOL><INDENT>this_candidate = candidate_array[i]<EOL>if language_arg != <NUM_LIT:1>:<EOL><INDENT>this_candidate = self._normalize_lang_attrs(<EOL>this_candidate + '<STR_LIT:[>' + str(language_arg) + '<STR_LIT:]>', False<EOL>)<EOL><DEDENT>if this_candidate != '<STR_LIT>':<EOL><INDENT>found = True<EOL>if candidate:<EOL><INDENT>candidate += '<STR_LIT:|>'<EOL><DEDENT>candidate += this_candidate<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>return None<EOL><DEDENT>if '<STR_LIT:|>' in candidate:<EOL><INDENT>candidate = '<STR_LIT:(>' + candidate + '<STR_LIT:)>'<EOL><DEDENT>return candidate<EOL>

Apply a phonetic regex if compatible.

        tests for compatible language rules

        to do so, apply the rule, expand the results, and detect alternatives
            with incompatible attributes

        then drop each alternative that has incompatible attributes and keep
            those that are compatible

        if there are no compatible alternatives left, return false

        otherwise return the compatible alternatives

        apply the rule

        Parameters
        ----------
        phonetic : str
            The Beider-Morse phonetic encoding (so far)
        target : str
            A proposed addition to the phonetic encoding
        language_arg : int
            An integer representing the target language of the phonetic
            encoding

        Returns
        -------
        str
            A candidate encoding


def _language_index_from_code(self, code, name_mode):

if code < <NUM_LIT:1> or code > sum(<EOL>_LANG_DICT[_] for _ in BMDATA[name_mode]['<STR_LIT>']<EOL>):  <EOL><INDENT>return L_ANY<EOL><DEDENT>if (<EOL>code & (code - <NUM_LIT:1>)<EOL>) != <NUM_LIT:0>:  <EOL><INDENT>return L_ANY<EOL><DEDENT>return code<EOL>

Return the index value for a language code.

        This returns l_any if more than one code is specified or the code is
        out of bounds.

        Parameters
        ----------
        code : int
            The language code to interpret
        name_mode : str
            The name mode of the algorithm: ``gen`` (default),
            ``ash`` (Ashkenazi), or ``sep`` (Sephardic)

        Returns
        -------
        int
            Language code index


word = normalize('<STR_LIT>', text_type(word.strip().lower()))<EOL>name_mode = name_mode.strip().lower()[:<NUM_LIT:3>]<EOL>if name_mode not in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>name_mode = '<STR_LIT>'<EOL><DEDENT>if match_mode != '<STR_LIT>':<EOL><INDENT>match_mode = '<STR_LIT>'<EOL><DEDENT>all_langs = (<EOL>sum(_LANG_DICT[_] for _ in BMDATA[name_mode]['<STR_LIT>']) - <NUM_LIT:1><EOL>)<EOL>lang_choices = <NUM_LIT:0><EOL>if isinstance(language_arg, (int, float, long)):<EOL><INDENT>lang_choices = int(language_arg)<EOL><DEDENT>elif language_arg != '<STR_LIT>' and isinstance(language_arg, (text_type, str)):<EOL><INDENT>for lang in text_type(language_arg).lower().split('<STR_LIT:U+002C>'):<EOL><INDENT>if lang in _LANG_DICT and (_LANG_DICT[lang] & all_langs):<EOL><INDENT>lang_choices += _LANG_DICT[lang]<EOL><DEDENT>elif not filter_langs:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>+ name_mode<EOL>+ '<STR_LIT>'<EOL>+ lang<EOL>+ '<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT><DEDENT>if lang_choices == <NUM_LIT:0>:<EOL><INDENT>language_arg = self._language(word, name_mode)<EOL><DEDENT>else:<EOL><INDENT>language_arg = lang_choices<EOL><DEDENT>language_arg2 = self._language_index_from_code(language_arg, name_mode)<EOL>rules = BMDATA[name_mode]['<STR_LIT>'][language_arg2]<EOL>final_rules1 = BMDATA[name_mode][match_mode]['<STR_LIT>']<EOL>final_rules2 = BMDATA[name_mode][match_mode][language_arg2]<EOL>result = self._phonetic(<EOL>word,<EOL>name_mode,<EOL>rules,<EOL>final_rules1,<EOL>final_rules2,<EOL>language_arg,<EOL>concat,<EOL>)<EOL>result = self._phonetic_numbers(result)<EOL>return result<EOL>

Return the Beider-Morse Phonetic Matching encoding(s) of a term.

        Parameters
        ----------
        word : str
            The word to transform
        language_arg : int
            The language of the term; supported values include:

                - ``any``
                - ``arabic``
                - ``cyrillic``
                - ``czech``
                - ``dutch``
                - ``english``
                - ``french``
                - ``german``
                - ``greek``
                - ``greeklatin``
                - ``hebrew``
                - ``hungarian``
                - ``italian``
                - ``latvian``
                - ``polish``
                - ``portuguese``
                - ``romanian``
                - ``russian``
                - ``spanish``
                - ``turkish``

        name_mode : str
            The name mode of the algorithm:

                - ``gen`` -- general (default)
                - ``ash`` -- Ashkenazi
                - ``sep`` -- Sephardic

        match_mode : str
            Matching mode: ``approx`` or ``exact``
        concat : bool
            Concatenation mode
        filter_langs : bool
            Filter out incompatible languages

        Returns
        -------
        tuple
            The Beider-Morse phonetic value(s)

        Raises
        ------
        ValueError
            Unknown language

        Examples
        --------
        >>> pe = BeiderMorse()
        >>> pe.encode('Christopher')
        'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir
        xristofir xristYfir xristopi xritopir xritopi xristofi xritofir
        xritofi tzristopir tzristofir zristopir zristopi zritopir zritopi
        zristofir zristofi zritofir zritofi'
        >>> pe.encode('Niall')
        'nial niol'
        >>> pe.encode('Smith')
        'zmit'
        >>> pe.encode('Schmidt')
        'zmit stzmit'

        >>> pe.encode('Christopher', language_arg='German')
        'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir
        xristofir xristYfir'
        >>> pe.encode('Christopher', language_arg='English')
        'tzristofir tzrQstofir tzristafir tzrQstafir xristofir xrQstofir
        xristafir xrQstafir'
        >>> pe.encode('Christopher', language_arg='German', name_mode='ash')
        'xrQstopir xrQstYpir xristopir xristYpir xrQstofir xrQstYfir
        xristofir xristYfir'

        >>> pe.encode('Christopher', language_arg='German', match_mode='exact')
        'xriStopher xriStofer xristopher xristofer'


def phonix(word, max_length=<NUM_LIT:4>, zero_pad=True):

return Phonix().encode(word, max_length, zero_pad)<EOL>

Return the Phonix code for a word.

    This is a wrapper for :py:meth:`Phonix.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The Phonix value

    Examples
    --------
    >>> phonix('Christopher')
    'K683'
    >>> phonix('Niall')
    'N400'
    >>> phonix('Smith')
    'S530'
    >>> phonix('Schmidt')
    'S530'


self._uc_c_set = (<EOL>super(Phonix, self)._uc_set - super(Phonix, self)._uc_v_set<EOL>)<EOL>self._substitutions = (<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:R>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT:F>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT:T>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<EOL><NUM_LIT:2>,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>super(Phonix, self)._uc_v_set,<EOL>super(Phonix, self)._uc_v_set,<EOL>),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT:N>', None, self._uc_c_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:N>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:S>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:T>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:C>'),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT:S>', None, super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>', self._uc_c_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<EOL><NUM_LIT:2>,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>super(Phonix, self)._uc_v_set,<EOL>super(Phonix, self)._uc_v_set,<EOL>),<EOL>(<EOL><NUM_LIT:2>,<EOL>'<STR_LIT>',<EOL>'<STR_LIT:Y>',<EOL>super(Phonix, self)._uc_v_set,<EOL>super(Phonix, self)._uc_v_set,<EOL>),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:Y>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:E>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:S>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:F>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:T>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:T>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:N>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:0>, '<STR_LIT>', '<STR_LIT:N>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT:X>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT:S>'),<EOL>(<NUM_LIT:2>, '<STR_LIT:R>', '<STR_LIT>', super(Phonix, self)._uc_v_set, self._uc_c_set),<EOL>(<NUM_LIT:1>, '<STR_LIT:R>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:2>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set, self._uc_c_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT:R>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', self._uc_c_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', self._uc_c_set),<EOL>(<NUM_LIT:1>, '<STR_LIT:E>', '<STR_LIT>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:S>'),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT:M>', super(Phonix, self)._uc_v_set),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>(<NUM_LIT:3>, '<STR_LIT>', '<STR_LIT>'),<EOL>)<EOL>


def _start_repl(word, src, tar, post=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if post:<EOL><INDENT>for i in post:<EOL><INDENT>if word.startswith(src + i):<EOL><INDENT>return tar + word[len(src) :]<EOL><DEDENT><DEDENT><DEDENT>elif word.startswith(src):<EOL><INDENT>return tar + word[len(src) :]<EOL><DEDENT>return word<EOL><DEDENT>def _end_repl(word, src, tar, pre=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if pre:<EOL><INDENT>for i in pre:<EOL><INDENT>if word.endswith(i + src):<EOL><INDENT>return word[: -len(src)] + tar<EOL><DEDENT><DEDENT><DEDENT>elif word.endswith(src):<EOL><INDENT>return word[: -len(src)] + tar<EOL><DEDENT>return word<EOL><DEDENT>def _mid_repl(word, src, tar, pre=None, post=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if pre or post:<EOL><INDENT>if not pre:<EOL><INDENT>return word[<NUM_LIT:0>] + _all_repl(word[<NUM_LIT:1>:], src, tar, pre, post)<EOL><DEDENT>elif not post:<EOL><INDENT>return _all_repl(word[:-<NUM_LIT:1>], src, tar, pre, post) + word[-<NUM_LIT:1>]<EOL><DEDENT>return _all_repl(word, src, tar, pre, post)<EOL><DEDENT>return (<EOL>word[<NUM_LIT:0>] + _all_repl(word[<NUM_LIT:1>:-<NUM_LIT:1>], src, tar, pre, post) + word[-<NUM_LIT:1>]<EOL>)<EOL><DEDENT>def _all_repl(word, src, tar, pre=None, post=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if pre or post:<EOL><INDENT>if post:<EOL><INDENT>post = post<EOL><DEDENT>else:<EOL><INDENT>post = frozenset(('<STR_LIT>',))<EOL><DEDENT>if pre:<EOL><INDENT>pre = pre<EOL><DEDENT>else:<EOL><INDENT>pre = frozenset(('<STR_LIT>',))<EOL><DEDENT>for i, j in ((i, j) for i in pre for j in post):<EOL><INDENT>word = word.replace(i + src + j, i + tar + j)<EOL><DEDENT>return word<EOL><DEDENT>else:<EOL><INDENT>return word.replace(src, tar)<EOL><DEDENT><DEDENT>repl_at = (_start_repl, _end_repl, _mid_repl, _all_repl)<EOL>sdx = '<STR_LIT>'<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<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>if word:<EOL><INDENT>for trans in self._substitutions:<EOL><INDENT>word = repl_at[trans[<NUM_LIT:0>]](word, *trans[<NUM_LIT:1>:])<EOL><DEDENT>if word[<NUM_LIT:0>] in self._uc_vy_set:<EOL><INDENT>sdx = '<STR_LIT:v>' + word[<NUM_LIT:1>:].translate(self._trans)<EOL><DEDENT>else:<EOL><INDENT>sdx = word[<NUM_LIT:0>] + word[<NUM_LIT:1>:].translate(self._trans)<EOL><DEDENT>sdx = self._delete_consecutive_repeats(sdx)<EOL>sdx = sdx.replace('<STR_LIT:0>', '<STR_LIT>')<EOL><DEDENT>if max_length != -<NUM_LIT:1>:<EOL><INDENT>max_length = min(max(<NUM_LIT:4>, max_length), <NUM_LIT:64>)<EOL><DEDENT>else:<EOL><INDENT>max_length = <NUM_LIT:64><EOL><DEDENT>if zero_pad:<EOL><INDENT>sdx += '<STR_LIT:0>' * max_length<EOL><DEDENT>if not sdx:<EOL><INDENT>sdx = '<STR_LIT:0>'<EOL><DEDENT>return sdx[:max_length]<EOL>

Return the Phonix code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The Phonix value

        Examples
        --------
        >>> pe = Phonix()
        >>> pe.encode('Christopher')
        'K683'
        >>> pe.encode('Niall')
        'N400'
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Schmidt')
        'S530'


def onca(word, max_length=<NUM_LIT:4>, zero_pad=True):

return ONCA().encode(word, max_length, zero_pad)<EOL>

Return the Oxford Name Compression Algorithm (ONCA) code for a word.

    This is a wrapper for :py:meth:`ONCA.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The maximum length (default 5) of the code to return
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The ONCA code

    Examples
    --------
    >>> onca('Christopher')
    'C623'
    >>> onca('Niall')
    'N400'
    >>> onca('Smith')
    'S530'
    >>> onca('Schmidt')
    'S530'


<EOL>return self._soundex.encode(<EOL>self._nysiis.encode(word, max_length=max_length * <NUM_LIT:3>),<EOL>max_length,<EOL>zero_pad=zero_pad,<EOL>)<EOL>

Return the Oxford Name Compression Algorithm (ONCA) code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The maximum length (default 5) of the code to return
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The ONCA code

        Examples
        --------
        >>> pe = ONCA()
        >>> pe.encode('Christopher')
        'C623'
        >>> pe.encode('Niall')
        'N400'
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Schmidt')
        'S530'


return SfinxBis().encode(word, max_length)<EOL>

Return the SfinxBis code for a word.

    This is a wrapper for :py:meth:`SfinxBis.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to unlimited)

    Returns
    -------
    tuple
        The SfinxBis value

    Examples
    --------
    >>> sfinxbis('Christopher')
    ('K68376',)
    >>> sfinxbis('Niall')
    ('N4',)
    >>> sfinxbis('Smith')
    ('S53',)
    >>> sfinxbis('Schmidt')
    ('S53',)

    >>> sfinxbis('Johansson')
    ('J585',)
    >>> sfinxbis('Sjöberg')
    ('#162',)


def encode(self, word, max_length=-<NUM_LIT:1>):

def _foersvensker(lokal_ordet):<EOL><INDENT>"""<STR_LIT>"""<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT:F>')<EOL>for i in self._harde_vokaler:<EOL><INDENT>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT>', i + '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT:Y>', i + '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT:I>', i + '<STR_LIT>')<EOL><DEDENT>for i in self._mjuka_vokaler:<EOL><INDENT>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT>', i + '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT:Y>', i + '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace(i + '<STR_LIT:I>', i + '<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:H>' in lokal_ordet:<EOL><INDENT>for i in self._uc_c_set:<EOL><INDENT>lokal_ordet = lokal_ordet.replace('<STR_LIT:H>' + i, i)<EOL><DEDENT><DEDENT>lokal_ordet = lokal_ordet.translate(self._substitutions)<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>lokal_ordet = lokal_ordet.replace('<STR_LIT>', '<STR_LIT>')<EOL>return lokal_ordet<EOL><DEDENT>def _koda_foersta_ljudet(lokal_ordet):<EOL><INDENT>"""<STR_LIT>"""<EOL>if (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] in self._mjuka_vokaler<EOL>or lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] in self._harde_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT:$>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:2>] in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>lokal_ordet = '<STR_LIT>' + lokal_ordet[<NUM_LIT:2>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT>'<EOL>and lokal_ordet[<NUM_LIT:1>:<NUM_LIT:2>] in self._mjuka_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>lokal_ordet = '<STR_LIT>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:2>] == '<STR_LIT>' and lokal_ordet[<NUM_LIT:2>:<NUM_LIT:3>] in frozenset(<EOL>self._mjuka_vokaler | self._harde_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT:#>' + lokal_ordet[<NUM_LIT:2>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:C>'<EOL>and lokal_ordet[<NUM_LIT:1>:<NUM_LIT:2>] in self._harde_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:C>' and lokal_ordet[<NUM_LIT:1>:<NUM_LIT:2>] in self._uc_c_set<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:X>':<EOL><INDENT>lokal_ordet = '<STR_LIT:S>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:C>'<EOL>and lokal_ordet[<NUM_LIT:1>:<NUM_LIT:2>] in self._mjuka_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT:S>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:3>] in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>lokal_ordet = '<STR_LIT:#>' + lokal_ordet[<NUM_LIT:3>:]<EOL><DEDENT>elif lokal_ordet[<NUM_LIT:0>:<NUM_LIT:2>] in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>lokal_ordet = '<STR_LIT:#>' + lokal_ordet[<NUM_LIT:2>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:2>] == '<STR_LIT>'<EOL>and lokal_ordet[<NUM_LIT:2>:<NUM_LIT:3>] in self._mjuka_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT:#>' + lokal_ordet[<NUM_LIT:2>:]<EOL><DEDENT>elif (<EOL>lokal_ordet[<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT>'<EOL>and lokal_ordet[<NUM_LIT:1>:<NUM_LIT:2>] in self._mjuka_vokaler<EOL>):<EOL><INDENT>lokal_ordet = '<STR_LIT:#>' + lokal_ordet[<NUM_LIT:1>:]<EOL><DEDENT>return lokal_ordet<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:U+0020>')<EOL>for adelstitel in self._adelstitler:<EOL><INDENT>while adelstitel in word:<EOL><INDENT>word = word.replace(adelstitel, '<STR_LIT:U+0020>')<EOL><DEDENT>if word.startswith(adelstitel[<NUM_LIT:1>:]):<EOL><INDENT>word = word[len(adelstitel) - <NUM_LIT:1> :]<EOL><DEDENT><DEDENT>ordlista = word.split()<EOL>ordlista = [<EOL>self._delete_consecutive_repeats(ordet) for ordet in ordlista<EOL>]<EOL>if not ordlista:<EOL><INDENT>return ('<STR_LIT>',)<EOL><DEDENT>ordlista = [_foersvensker(ordet) for ordet in ordlista]<EOL>ordlista = [<EOL>'<STR_LIT>'.join(c for c in ordet if c in self._uc_set)<EOL>for ordet in ordlista<EOL>]<EOL>ordlista = [_koda_foersta_ljudet(ordet) for ordet in ordlista]<EOL>rest = [ordet[<NUM_LIT:1>:] for ordet in ordlista]<EOL>rest = [ordet.replace('<STR_LIT>', '<STR_LIT:T>') for ordet in rest]<EOL>rest = [ordet.replace('<STR_LIT:X>', '<STR_LIT>') for ordet in rest]<EOL>for vokal in self._mjuka_vokaler:<EOL><INDENT>rest = [ordet.replace('<STR_LIT:C>' + vokal, '<STR_LIT>' + vokal) for ordet in rest]<EOL><DEDENT>rest = [ordet.translate(self._trans) for ordet in rest]<EOL>rest = [self._delete_consecutive_repeats(ordet) for ordet in rest]<EOL>rest = [ordet.replace('<STR_LIT>', '<STR_LIT>') for ordet in rest]<EOL>ordlista = [<EOL>'<STR_LIT>'.join(ordet) for ordet in zip((_[<NUM_LIT:0>:<NUM_LIT:1>] for _ in ordlista), rest)<EOL>]<EOL>if max_length > <NUM_LIT:0>:<EOL><INDENT>ordlista = [ordet[:max_length] for ordet in ordlista]<EOL><DEDENT>return tuple(ordlista)<EOL>

Return the SfinxBis code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to unlimited)

        Returns
        -------
        tuple
            The SfinxBis value

        Examples
        --------
        >>> pe = SfinxBis()
        >>> pe.encode('Christopher')
        ('K68376',)
        >>> pe.encode('Niall')
        ('N4',)
        >>> pe.encode('Smith')
        ('S53',)
        >>> pe.encode('Schmidt')
        ('S53',)

        >>> pe.encode('Johansson')
        ('J585',)
        >>> pe.encode('Sjöberg')
        ('#162',)


def refined_soundex(word, max_length=-<NUM_LIT:1>, zero_pad=False, retain_vowels=False):

return RefinedSoundex().encode(word, max_length, zero_pad, retain_vowels)<EOL>

Return the Refined Soundex code for a word.

    This is a wrapper for :py:meth:`RefinedSoundex.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to unlimited)
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string
    retain_vowels : bool
        Retain vowels (as 0) in the resulting code

    Returns
    -------
    str
        The Refined Soundex value

    Examples
    --------
    >>> refined_soundex('Christopher')
    'C393619'
    >>> refined_soundex('Niall')
    'N87'
    >>> refined_soundex('Smith')
    'S386'
    >>> refined_soundex('Schmidt')
    'S386'


def encode(self, word, max_length=-<NUM_LIT:1>, zero_pad=False, retain_vowels=False):

<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<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>sdx = word[:<NUM_LIT:1>] + word.translate(self._trans)<EOL>sdx = self._delete_consecutive_repeats(sdx)<EOL>if not retain_vowels:<EOL><INDENT>sdx = sdx.replace('<STR_LIT:0>', '<STR_LIT>')  <EOL><DEDENT>if max_length > <NUM_LIT:0>:<EOL><INDENT>if zero_pad:<EOL><INDENT>sdx += '<STR_LIT:0>' * max_length<EOL><DEDENT>sdx = sdx[:max_length]<EOL><DEDENT>return sdx<EOL>

Return the Refined Soundex code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to unlimited)
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string
        retain_vowels : bool
            Retain vowels (as 0) in the resulting code

        Returns
        -------
        str
            The Refined Soundex value

        Examples
        --------
        >>> pe = RefinedSoundex()
        >>> pe.encode('Christopher')
        'C393619'
        >>> pe.encode('Niall')
        'N87'
        >>> pe.encode('Smith')
        'S386'
        >>> pe.encode('Schmidt')
        'S386'


def pshp_soundex_first(fname, max_length=<NUM_LIT:4>, german=False):

return PSHPSoundexFirst().encode(fname, max_length, german)<EOL>

Calculate the PSHP Soundex/Viewex Coding of a first name.

    This is a wrapper for :py:meth:`PSHPSoundexFirst.encode`.

    Parameters
    ----------
    fname : str
        The first name to encode
    max_length : int
        The length of the code returned (defaults to 4)
    german : bool
        Set to True if the name is German (different rules apply)

    Returns
    -------
    str
        The PSHP Soundex/Viewex Coding

    Examples
    --------
    >>> pshp_soundex_first('Smith')
    'S530'
    >>> pshp_soundex_first('Waters')
    'W352'
    >>> pshp_soundex_first('James')
    'J700'
    >>> pshp_soundex_first('Schmidt')
    'S500'
    >>> pshp_soundex_first('Ashcroft')
    'A220'
    >>> pshp_soundex_first('John')
    'J500'
    >>> pshp_soundex_first('Colin')
    'K400'
    >>> pshp_soundex_first('Niall')
    'N400'
    >>> pshp_soundex_first('Sally')
    'S400'
    >>> pshp_soundex_first('Jane')
    'J500'


def encode(self, fname, max_length=<NUM_LIT:4>, german=False):

fname = unicode_normalize('<STR_LIT>', text_type(fname.upper()))<EOL>fname = fname.replace('<STR_LIT>', '<STR_LIT>')<EOL>fname = '<STR_LIT>'.join(c for c in fname if c in self._uc_set)<EOL>if fname == '<STR_LIT>':<EOL><INDENT>code = '<STR_LIT>'<EOL><DEDENT>elif fname == '<STR_LIT>':<EOL><INDENT>code = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if fname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT:S>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:1>] == '<STR_LIT:C>' and fname[:<NUM_LIT:2>] != '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>if fname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT:N>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT:F>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:3>] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>if german and fname[:<NUM_LIT:1>] in {'<STR_LIT>', '<STR_LIT:M>', '<STR_LIT:Y>', '<STR_LIT>'}:<EOL><INDENT>fname = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT:M>': '<STR_LIT:N>', '<STR_LIT:Y>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT:S>'}[<EOL>fname[<NUM_LIT:0>]<EOL>] + fname[<NUM_LIT:1>:]<EOL><DEDENT>code = fname[:<NUM_LIT:1>]<EOL>fname = fname.translate(self._trans)<EOL>fname = self._delete_consecutive_repeats(fname)<EOL>code += fname[<NUM_LIT:1>:]<EOL>syl_ptr = code.find('<STR_LIT:0>')<EOL>syl2_ptr = code[syl_ptr + <NUM_LIT:1> :].find('<STR_LIT:0>')<EOL>if syl_ptr != -<NUM_LIT:1> and syl2_ptr != -<NUM_LIT:1> and syl2_ptr - syl_ptr > -<NUM_LIT:1>:<EOL><INDENT>code = code[: syl_ptr + <NUM_LIT:2>]<EOL><DEDENT>code = code.replace('<STR_LIT:0>', '<STR_LIT>')  <EOL><DEDENT>if max_length != -<NUM_LIT:1>:<EOL><INDENT>if len(code) < max_length:<EOL><INDENT>code += '<STR_LIT:0>' * (max_length - len(code))<EOL><DEDENT>else:<EOL><INDENT>code = code[:max_length]<EOL><DEDENT><DEDENT>return code<EOL>

Calculate the PSHP Soundex/Viewex Coding of a first name.

        Parameters
        ----------
        fname : str
            The first name to encode
        max_length : int
            The length of the code returned (defaults to 4)
        german : bool
            Set to True if the name is German (different rules apply)

        Returns
        -------
        str
            The PSHP Soundex/Viewex Coding

        Examples
        --------
        >>> pe = PSHPSoundexFirst()
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Waters')
        'W352'
        >>> pe.encode('James')
        'J700'
        >>> pe.encode('Schmidt')
        'S500'
        >>> pe.encode('Ashcroft')
        'A220'
        >>> pe.encode('John')
        'J500'
        >>> pe.encode('Colin')
        'K400'
        >>> pe.encode('Niall')
        'N400'
        >>> pe.encode('Sally')
        'S400'
        >>> pe.encode('Jane')
        'J500'


return RussellIndex().encode(word)<EOL>

Return the Russell Index (integer output) of a word.

    This is a wrapper for :py:meth:`RussellIndex.encode`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    int
        The Russell Index value

    Examples
    --------
    >>> russell_index('Christopher')
    3813428
    >>> russell_index('Niall')
    715
    >>> russell_index('Smith')
    3614
    >>> russell_index('Schmidt')
    3614


return RussellIndex()._to_alpha(num)<EOL>

Convert the Russell Index integer to an alphabetic string.

    This is a wrapper for :py:meth:`RussellIndex._to_alpha`.

    Parameters
    ----------
    num : int
        A Russell Index integer value

    Returns
    -------
    str
        The Russell Index as an alphabetic string

    Examples
    --------
    >>> russell_index_num_to_alpha(3813428)
    'CRACDBR'
    >>> russell_index_num_to_alpha(715)
    'NAL'
    >>> russell_index_num_to_alpha(3614)
    'CMAD'


return RussellIndex().encode_alpha(word)<EOL>

Return the Russell Index (alphabetic output) for the word.

    This is a wrapper for :py:meth:`RussellIndex.encode_alpha`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The Russell Index value as an alphabetic string

    Examples
    --------
    >>> russell_index_alpha('Christopher')
    'CRACDBR'
    >>> russell_index_alpha('Niall')
    'NAL'
    >>> russell_index_alpha('Smith')
    'CMAD'
    >>> russell_index_alpha('Schmidt')
    'CMAD'


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.rstrip('<STR_LIT>')  <EOL>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>sdx = word.translate(self._trans)<EOL>one = sdx.find('<STR_LIT:1>') + <NUM_LIT:1><EOL>if one:<EOL><INDENT>sdx = sdx[:one] + '<STR_LIT>'.join(c for c in sdx[one:] if c != '<STR_LIT:1>')<EOL><DEDENT>sdx = self._delete_consecutive_repeats(sdx)<EOL>return int(sdx) if sdx else float('<STR_LIT>')<EOL>

Return the Russell Index (integer output) of a word.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        int
            The Russell Index value

        Examples
        --------
        >>> pe = RussellIndex()
        >>> pe.encode('Christopher')
        3813428
        >>> pe.encode('Niall')
        715
        >>> pe.encode('Smith')
        3614
        >>> pe.encode('Schmidt')
        3614


num = '<STR_LIT>'.join(c for c in text_type(num) if c in self._num_set)<EOL>if num:<EOL><INDENT>return num.translate(self._num_trans)<EOL><DEDENT>return '<STR_LIT>'<EOL>

Convert the Russell Index integer to an alphabetic string.

        This follows Robert C. Russell's Index algorithm, as described in
        :cite:`Russell:1917`.

        Parameters
        ----------
        num : int
            A Russell Index integer value

        Returns
        -------
        str
            The Russell Index as an alphabetic string

        Examples
        --------
        >>> pe = RussellIndex()
        >>> pe._to_alpha(3813428)
        'CRACDBR'
        >>> pe._to_alpha(715)
        'NAL'
        >>> pe._to_alpha(3614)
        'CMAD'


if word:<EOL><INDENT>return self._to_alpha(self.encode(word))<EOL><DEDENT>return '<STR_LIT>'<EOL>

Return the Russell Index (alphabetic output) for the word.

        This follows Robert C. Russell's Index algorithm, as described in
        :cite:`Russell:1917`.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The Russell Index value as an alphabetic string

        Examples
        --------
        >>> pe = RussellIndex()
        >>> pe.encode_alpha('Christopher')
        'CRACDBR'
        >>> pe.encode_alpha('Niall')
        'NAL'
        >>> pe.encode_alpha('Smith')
        'CMAD'
        >>> pe.encode_alpha('Schmidt')
        'CMAD'


def soundex(word, max_length=<NUM_LIT:4>, var='<STR_LIT>', reverse=False, zero_pad=True):

return Soundex().encode(word, max_length, var, reverse, zero_pad)<EOL>

Return the Soundex code for a word.

    This is a wrapper for :py:meth:`Soundex.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)
    var : str
        The variant of the algorithm to employ (defaults to ``American``):

            - ``American`` follows the American Soundex algorithm, as described
              at :cite:`US:2007` and in :cite:`Knuth:1998`; this is also called
              Miracode
            - ``special`` follows the rules from the 1880-1910 US Census
              retrospective re-analysis, in which h & w are not treated as
              blocking consonants but as vowels. Cf. :cite:`Repici:2013`.
            - ``Census`` follows the rules laid out in GIL 55 :cite:`US:1997`
              by the US Census, including coding prefixed and unprefixed
              versions of some names

    reverse : bool
        Reverse the word before computing the selected Soundex (defaults to
        False); This results in "Reverse Soundex", which is useful for blocking
        in cases where the initial elements may be in error.
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The Soundex value

    Examples
    --------
    >>> soundex("Christopher")
    'C623'
    >>> soundex("Niall")
    'N400'
    >>> soundex('Smith')
    'S530'
    >>> soundex('Schmidt')
    'S530'

    >>> soundex('Christopher', max_length=-1)
    'C623160000000000000000000000000000000000000000000000000000000000'
    >>> soundex('Christopher', max_length=-1, zero_pad=False)
    'C62316'

    >>> soundex('Christopher', reverse=True)
    'R132'

    >>> soundex('Ashcroft')
    'A261'
    >>> soundex('Asicroft')
    'A226'
    >>> soundex('Ashcroft', var='special')
    'A226'
    >>> soundex('Asicroft', var='special')
    'A226'


def encode(<EOL>self, word, max_length=<NUM_LIT:4>, var='<STR_LIT>', reverse=False, zero_pad=True<EOL>):

<EOL>if max_length != -<NUM_LIT:1>:<EOL><INDENT>max_length = min(max(<NUM_LIT:4>, max_length), <NUM_LIT:64>)<EOL><DEDENT>else:<EOL><INDENT>max_length = <NUM_LIT:64><EOL><DEDENT>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>if var == '<STR_LIT>':<EOL><INDENT>if word[:<NUM_LIT:3>] in {'<STR_LIT>', '<STR_LIT>'} and len(word) > <NUM_LIT:4>:<EOL><INDENT>return (<EOL>soundex(word, max_length, '<STR_LIT>', reverse, zero_pad),<EOL>soundex(<EOL>word[<NUM_LIT:3>:], max_length, '<STR_LIT>', reverse, zero_pad<EOL>),<EOL>)<EOL><DEDENT>if word[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'} and len(word) > <NUM_LIT:3>:<EOL><INDENT>return (<EOL>soundex(word, max_length, '<STR_LIT>', reverse, zero_pad),<EOL>soundex(<EOL>word[<NUM_LIT:2>:], max_length, '<STR_LIT>', reverse, zero_pad<EOL>),<EOL>)<EOL><DEDENT><DEDENT>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>if not word:<EOL><INDENT>if zero_pad:<EOL><INDENT>return '<STR_LIT:0>' * max_length<EOL><DEDENT>return '<STR_LIT:0>'<EOL><DEDENT>if reverse:<EOL><INDENT>word = word[::-<NUM_LIT:1>]<EOL><DEDENT>sdx = word.translate(self._trans)<EOL>if var == '<STR_LIT>':<EOL><INDENT>sdx = sdx.replace('<STR_LIT>', '<STR_LIT:0>')  <EOL><DEDENT>else:<EOL><INDENT>sdx = sdx.replace('<STR_LIT>', '<STR_LIT>')  <EOL><DEDENT>sdx = self._delete_consecutive_repeats(sdx)  <EOL>if word[<NUM_LIT:0>] in '<STR_LIT>':<EOL><INDENT>sdx = word[<NUM_LIT:0>] + sdx<EOL><DEDENT>else:<EOL><INDENT>sdx = word[<NUM_LIT:0>] + sdx[<NUM_LIT:1>:]<EOL><DEDENT>sdx = sdx.replace('<STR_LIT:0>', '<STR_LIT>')  <EOL>if zero_pad:<EOL><INDENT>sdx += '<STR_LIT:0>' * max_length  <EOL><DEDENT>return sdx[:max_length]<EOL>

Return the Soundex code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)
        var : str
            The variant of the algorithm to employ (defaults to ``American``):

                - ``American`` follows the American Soundex algorithm, as
                  described at :cite:`US:2007` and in :cite:`Knuth:1998`; this
                  is also called Miracode
                - ``special`` follows the rules from the 1880-1910 US Census
                  retrospective re-analysis, in which h & w are not treated as
                  blocking consonants but as vowels. Cf. :cite:`Repici:2013`.
                - ``Census`` follows the rules laid out in GIL 55
                  :cite:`US:1997` by the US Census, including coding prefixed
                  and unprefixed versions of some names

        reverse : bool
            Reverse the word before computing the selected Soundex (defaults to
            False); This results in "Reverse Soundex", which is useful for
            blocking in cases where the initial elements may be in error.
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The Soundex value

        Examples
        --------
        >>> pe = Soundex()
        >>> pe.encode("Christopher")
        'C623'
        >>> pe.encode("Niall")
        'N400'
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Schmidt')
        'S530'

        >>> pe.encode('Christopher', max_length=-1)
        'C623160000000000000000000000000000000000000000000000000000000000'
        >>> pe.encode('Christopher', max_length=-1, zero_pad=False)
        'C62316'

        >>> pe.encode('Christopher', reverse=True)
        'R132'

        >>> pe.encode('Ashcroft')
        'A261'
        >>> pe.encode('Asicroft')
        'A226'
        >>> pe.encode('Ashcroft', var='special')
        'A226'
        >>> pe.encode('Asicroft', var='special')
        'A226'


def lein(word, max_length=<NUM_LIT:4>, zero_pad=True):

return Lein().encode(word, max_length, zero_pad)<EOL>

Return the Lein code for a word.

    This is a wrapper for :py:meth:`Lein.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The Lein code

    Examples
    --------
    >>> lein('Christopher')
    'C351'
    >>> lein('Niall')
    'N300'
    >>> lein('Smith')
    'S210'
    >>> lein('Schmidt')
    'S521'


<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<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>code = word[:<NUM_LIT:1>]  <EOL>word = word[<NUM_LIT:1>:].translate(self._del_trans)  <EOL>word = self._delete_consecutive_repeats(word)  <EOL>code += word.translate(self._trans)  <EOL>if zero_pad:<EOL><INDENT>code += '<STR_LIT:0>' * max_length  <EOL><DEDENT>return code[:max_length]<EOL>

Return the Lein code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The Lein code

        Examples
        --------
        >>> pe = Lein()
        >>> pe.encode('Christopher')
        'C351'
        >>> pe.encode('Niall')
        'N300'
        >>> pe.encode('Smith')
        'S210'
        >>> pe.encode('Schmidt')
        'S521'


def roger_root(word, max_length=<NUM_LIT:5>, zero_pad=True):

return RogerRoot().encode(word, max_length, zero_pad)<EOL>

Return the Roger Root code for a word.

    This is a wrapper for :py:meth:`RogerRoot.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The maximum length (default 5) of the code to return
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The Roger Root code

    Examples
    --------
    >>> roger_root('Christopher')
    '06401'
    >>> roger_root('Niall')
    '02500'
    >>> roger_root('Smith')
    '00310'
    >>> roger_root('Schmidt')
    '06310'


def encode(self, word, max_length=<NUM_LIT:5>, zero_pad=True):

<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<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>code = '<STR_LIT>'<EOL>pos = <NUM_LIT:0><EOL>for num in range(<NUM_LIT:4>, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if word[:num] in self._init_patterns[num]:<EOL><INDENT>code = self._init_patterns[num][word[:num]]<EOL>pos += num<EOL>break<EOL><DEDENT><DEDENT>while pos < len(word):<EOL><INDENT>for num in range(<NUM_LIT:4>, <NUM_LIT:0>, -<NUM_LIT:1>):  <EOL><INDENT>if word[pos : pos + num] in self._med_patterns[num]:<EOL><INDENT>code += self._med_patterns[num][word[pos : pos + num]]<EOL>pos += num<EOL>break<EOL><DEDENT><DEDENT><DEDENT>code = self._delete_consecutive_repeats(code)<EOL>code = code.replace('<STR_LIT:*>', '<STR_LIT>')<EOL>if zero_pad:<EOL><INDENT>code += '<STR_LIT:0>' * max_length<EOL><DEDENT>return code[:max_length]<EOL>

Return the Roger Root code for a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The maximum length (default 5) of the code to return
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The Roger Root code

        Examples
        --------
        >>> roger_root('Christopher')
        '06401'
        >>> roger_root('Niall')
        '02500'
        >>> roger_root('Smith')
        '00310'
        >>> roger_root('Schmidt')
        '06310'


def soundex_br(word, max_length=<NUM_LIT:4>, zero_pad=True):

return SoundexBR().encode(word, max_length, zero_pad)<EOL>

Return the SoundexBR encoding of a word.

    This is a wrapper for :py:meth:`SoundexBR.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to 4)
    zero_pad : bool
        Pad the end of the return value with 0s to achieve a max_length string

    Returns
    -------
    str
        The SoundexBR code

    Examples
    --------
    >>> soundex_br('Oliveira')
    'O416'
    >>> soundex_br('Almeida')
    'A453'
    >>> soundex_br('Barbosa')
    'B612'
    >>> soundex_br('Araújo')
    'A620'
    >>> soundex_br('Gonçalves')
    'G524'
    >>> soundex_br('Goncalves')
    'G524'


def encode(self, word, max_length=<NUM_LIT:4>, zero_pad=True):

word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>if word[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>first = '<STR_LIT>'<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT>' and word[<NUM_LIT:1>:<NUM_LIT:2>] in {'<STR_LIT:A>', '<STR_LIT:O>', '<STR_LIT>'}:<EOL><INDENT>first = '<STR_LIT:C>'<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT:C>' and word[<NUM_LIT:1>:<NUM_LIT:2>] in {'<STR_LIT:I>', '<STR_LIT:E>'}:<EOL><INDENT>first = '<STR_LIT:S>'<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT>' and word[<NUM_LIT:1>:<NUM_LIT:2>] in {'<STR_LIT:E>', '<STR_LIT:I>'}:<EOL><INDENT>first = '<STR_LIT>'<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT:Y>':<EOL><INDENT>first = '<STR_LIT:I>'<EOL><DEDENT>elif word[:<NUM_LIT:1>] == '<STR_LIT:H>':<EOL><INDENT>first = word[<NUM_LIT:1>:<NUM_LIT:2>]<EOL>word = word[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>first = word[:<NUM_LIT:1>]<EOL><DEDENT>sdx = first + word[<NUM_LIT:1>:].translate(self._trans)<EOL>sdx = self._delete_consecutive_repeats(sdx)<EOL>sdx = sdx.replace('<STR_LIT:0>', '<STR_LIT>')<EOL>if zero_pad:<EOL><INDENT>sdx += '<STR_LIT:0>' * max_length<EOL><DEDENT>return sdx[:max_length]<EOL>

Return the SoundexBR encoding of a word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to 4)
        zero_pad : bool
            Pad the end of the return value with 0s to achieve a max_length
            string

        Returns
        -------
        str
            The SoundexBR code

        Examples
        --------
        >>> soundex_br('Oliveira')
        'O416'
        >>> soundex_br('Almeida')
        'A453'
        >>> soundex_br('Barbosa')
        'B612'
        >>> soundex_br('Araújo')
        'A620'
        >>> soundex_br('Gonçalves')
        'G524'
        >>> soundex_br('Goncalves')
        'G524'


return NRL().encode(word)<EOL>

Return the Naval Research Laboratory phonetic encoding of a word.

    This is a wrapper for :py:meth:`NRL.encode`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The NRL phonetic encoding

    Examples
    --------
    >>> nrl('the')
    'DHAX'
    >>> nrl('round')
    'rAWnd'
    >>> nrl('quick')
    'kwIHk'
    >>> nrl('eaten')
    'IYtEHn'
    >>> nrl('Smith')
    'smIHTH'
    >>> nrl('Larsen')
    'lAArsEHn'


def _to_regex(pattern, left_match=True):<EOL><INDENT>new_pattern = '<STR_LIT>'<EOL>replacements = {<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>',<EOL>'<STR_LIT:+>': '<STR_LIT>',<EOL>'<STR_LIT:U+0020>': '<STR_LIT>',<EOL>}<EOL>for char in pattern:<EOL><INDENT>new_pattern += (<EOL>replacements[char] if char in replacements else char<EOL>)<EOL><DEDENT>if left_match:<EOL><INDENT>new_pattern += '<STR_LIT:$>'<EOL>if '<STR_LIT>' not in pattern:<EOL><INDENT>new_pattern = '<STR_LIT>' + new_pattern<EOL><DEDENT><DEDENT>else:<EOL><INDENT>new_pattern = '<STR_LIT>' + new_pattern.replace('<STR_LIT>', '<STR_LIT:$>')<EOL>if '<STR_LIT:$>' not in new_pattern:<EOL><INDENT>new_pattern += '<STR_LIT>'<EOL><DEDENT><DEDENT>return new_pattern<EOL><DEDENT>word = word.upper()<EOL>pron = '<STR_LIT>'<EOL>pos = <NUM_LIT:0><EOL>while pos < len(word):<EOL><INDENT>left_orig = word[:pos]<EOL>right_orig = word[pos:]<EOL>first = word[pos] if word[pos] in self._rules else '<STR_LIT:U+0020>'<EOL>for rule in self._rules[first]:<EOL><INDENT>left, match, right, out = rule<EOL>if right_orig.startswith(match):<EOL><INDENT>if left:<EOL><INDENT>l_pattern = _to_regex(left, left_match=True)<EOL><DEDENT>if right:<EOL><INDENT>r_pattern = _to_regex(right, left_match=False)<EOL><DEDENT>if (not left or re_match(l_pattern, left_orig)) and (<EOL>not right<EOL>or re_match(r_pattern, right_orig[len(match) :])<EOL>):<EOL><INDENT>pron += out<EOL>pos += len(match)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>pron += word[pos]<EOL>pos += <NUM_LIT:1><EOL><DEDENT><DEDENT>return pron<EOL>

Return the Naval Research Laboratory phonetic encoding of a word.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The NRL phonetic encoding

        Examples
        --------
        >>> pe = NRL()
        >>> pe.encode('the')
        'DHAX'
        >>> pe.encode('round')
        'rAWnd'
        >>> pe.encode('quick')
        'kwIHk'
        >>> pe.encode('eaten')
        'IYtEHn'
        >>> pe.encode('Smith')
        'smIHTH'
        >>> pe.encode('Larsen')
        'lAArsEHn'


return PhoneticSpanish().encode(word, max_length)<EOL>

Return the PhoneticSpanish coding of word.

    This is a wrapper for :py:meth:`PhoneticSpanish.encode`.

    Parameters
    ----------
    word : str
        The word to transform
    max_length : int
        The length of the code returned (defaults to unlimited)

    Returns
    -------
    str
        The PhoneticSpanish code

    Examples
    --------
    >>> phonetic_spanish('Perez')
    '094'
    >>> phonetic_spanish('Martinez')
    '69364'
    >>> phonetic_spanish('Gutierrez')
    '83994'
    >>> phonetic_spanish('Santiago')
    '4638'
    >>> phonetic_spanish('Nicolás')
    '6454'


<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:L>')<EOL>word = word.replace('<STR_LIT:R>', '<STR_LIT:R>')<EOL>sdx = word.translate(self._trans)<EOL>if max_length > <NUM_LIT:0>:<EOL><INDENT>sdx = (sdx + ('<STR_LIT:0>' * max_length))[:max_length]<EOL><DEDENT>return sdx<EOL>

Return the PhoneticSpanish coding of word.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            The length of the code returned (defaults to unlimited)

        Returns
        -------
        str
            The PhoneticSpanish code

        Examples
        --------
        >>> pe = PhoneticSpanish()
        >>> pe.encode('Perez')
        '094'
        >>> pe.encode('Martinez')
        '69364'
        >>> pe.encode('Gutierrez')
        '83994'
        >>> pe.encode('Santiago')
        '4638'
        >>> pe.encode('Nicolás')
        '6454'


return '<STR_LIT>'.join(char for char, _ in groupby(word))<EOL>

Delete consecutive repeated characters in a word.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            Word with consecutive repeating characters collapsed to a single
            instance

        Examples
        --------
        >>> pe = _Phonetic()
        >>> pe._delete_consecutive_repeats('REDDEE')
        'REDE'
        >>> pe._delete_consecutive_repeats('AEIOU')
        'AEIOU'
        >>> pe._delete_consecutive_repeats('AAACCCTTTGGG')
        'ACTG'


pass<EOL>

Encode phonetically.

        Parameters
        ----------
        word : str
            The word to transform


return self.encode(word)<EOL>

Encode phonetically using alphabetic characters.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The word transformed


return MRA().encode(word)<EOL>

Return the MRA personal numeric identifier (PNI) for a word.

    This is a wrapper for :py:meth:`MRA.encode`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The MRA PNI

    Examples
    --------
    >>> mra('Christopher')
    'CHRPHR'
    >>> mra('Niall')
    'NL'
    >>> mra('Smith')
    'SMTH'
    >>> mra('Schmidt')
    'SCHMDT'


if not word:<EOL><INDENT>return word<EOL><DEDENT>word = word.upper()<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word[<NUM_LIT:0>] + '<STR_LIT>'.join(<EOL>c for c in word[<NUM_LIT:1>:] if c not in self._uc_v_set<EOL>)<EOL>word = self._delete_consecutive_repeats(word)<EOL>if len(word) > <NUM_LIT:6>:<EOL><INDENT>word = word[:<NUM_LIT:3>] + word[-<NUM_LIT:3>:]<EOL><DEDENT>return word<EOL>

Return the MRA personal numeric identifier (PNI) for a word.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The MRA PNI

        Examples
        --------
        >>> pe = MRA()
        >>> pe.encode('Christopher')
        'CHRPHR'
        >>> pe.encode('Niall')
        'NL'
        >>> pe.encode('Smith')
        'SMTH'
        >>> pe.encode('Schmidt')
        'SCHMDT'


return Koelner().encode(word)<EOL>

Return the Kölner Phonetik (numeric output) code for a word.

    This is a wrapper for :py:meth:`Koelner.encode`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The Kölner Phonetik value as a numeric string

    Example
    -------
    >>> koelner_phonetik('Christopher')
    '478237'
    >>> koelner_phonetik('Niall')
    '65'
    >>> koelner_phonetik('Smith')
    '862'
    >>> koelner_phonetik('Schmidt')
    '862'
    >>> koelner_phonetik('Müller')
    '657'
    >>> koelner_phonetik('Zimmermann')
    '86766'


return Koelner()._to_alpha(num)<EOL>

Convert a Kölner Phonetik code from numeric to alphabetic.

    This is a wrapper for :py:meth:`Koelner._to_alpha`.

    Parameters
    ----------
    num : str or int
        A numeric Kölner Phonetik representation

    Returns
    -------
    str
        An alphabetic representation of the same word

    Examples
    --------
    >>> koelner_phonetik_num_to_alpha('862')
    'SNT'
    >>> koelner_phonetik_num_to_alpha('657')
    'NLR'
    >>> koelner_phonetik_num_to_alpha('86766')
    'SNRNN'


return Koelner().encode_alpha(word)<EOL>

Return the Kölner Phonetik (alphabetic output) code for a word.

    This is a wrapper for :py:meth:`Koelner.encode_alpha`.

    Parameters
    ----------
    word : str
        The word to transform

    Returns
    -------
    str
        The Kölner Phonetik value as an alphabetic string

    Examples
    --------
    >>> koelner_phonetik_alpha('Smith')
    'SNT'
    >>> koelner_phonetik_alpha('Schmidt')
    'SNT'
    >>> koelner_phonetik_alpha('Müller')
    'NLR'
    >>> koelner_phonetik_alpha('Zimmermann')
    'SNRNN'


def _after(word, pos, letters):<EOL><INDENT>"""<STR_LIT>"""<EOL>return pos > <NUM_LIT:0> and word[pos - <NUM_LIT:1>] in letters<EOL><DEDENT>def _before(word, pos, letters):<EOL><INDENT>"""<STR_LIT>"""<EOL>return pos + <NUM_LIT:1> < len(word) and word[pos + <NUM_LIT:1>] in letters<EOL><DEDENT>sdx = '<STR_LIT>'<EOL>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>if not word:<EOL><INDENT>return sdx<EOL><DEDENT>for i in range(len(word)):<EOL><INDENT>if word[i] in self._uc_v_set:<EOL><INDENT>sdx += '<STR_LIT:0>'<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, i, {'<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>if sdx:<EOL><INDENT>sdx = sdx[:<NUM_LIT:1>] + sdx[<NUM_LIT:1>:].replace('<STR_LIT:0>', '<STR_LIT>')<EOL><DEDENT>return sdx<EOL>

Return the Kölner Phonetik (numeric output) code for a word.

        While the output code is numeric, it is still a str because 0s can lead
        the code.

        Parameters
        ----------
        word : str
            The word to transform

        Returns
        -------
        str
            The Kölner Phonetik value as a numeric string

        Example
        -------
        >>> pe = Koelner()
        >>> pe.encode('Christopher')
        '478237'
        >>> pe.encode('Niall')
        '65'
        >>> pe.encode('Smith')
        '862'
        >>> pe.encode('Schmidt')
        '862'
        >>> pe.encode('Müller')
        '657'
        >>> pe.encode('Zimmermann')
        '86766'


num = '<STR_LIT>'.join(c for c in text_type(num) if c in self._num_set)<EOL>return num.translate(self._num_trans)<EOL>

Convert a Kölner Phonetik code from numeric to alphabetic.

        Parameters
        ----------
        num : str or int
            A numeric Kölner Phonetik representation

        Returns
        -------
        str
            An alphabetic representation of the same word

        Examples
        --------
        >>> pe = Koelner()
        >>> pe._to_alpha('862')
        'SNT'
        >>> pe._to_alpha('657')
        'NLR'
        >>> pe._to_alpha('86766')
        'SNRNN'