def sim(self, src, tar, min_ss_len=None, left_ext=None, right_ext=None):

if src == tar:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>if not src or not tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>max_len = max(len(src), len(tar))<EOL>if not (min_ss_len and left_ext and right_ext):<EOL><INDENT>if max_len >= <NUM_LIT:7>:<EOL><INDENT>min_ss_len = <NUM_LIT:2><EOL>left_ext = <NUM_LIT:2><EOL>right_ext = <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>min_ss_len = <NUM_LIT:1><EOL>left_ext = <NUM_LIT:0><EOL>right_ext = <NUM_LIT:0><EOL><DEDENT><DEDENT>pos = <NUM_LIT:0><EOL>match_len = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if pos + min_ss_len > len(src):<EOL><INDENT>return match_len / max_len<EOL><DEDENT>hit_len = <NUM_LIT:0><EOL>ix = <NUM_LIT:1><EOL>substring = src[pos : pos + min_ss_len]<EOL>search_begin = pos - left_ext<EOL>if search_begin < <NUM_LIT:0>:<EOL><INDENT>search_begin = <NUM_LIT:0><EOL>left_ext_len = pos<EOL><DEDENT>else:<EOL><INDENT>left_ext_len = left_ext<EOL><DEDENT>if pos + min_ss_len + right_ext >= len(tar):<EOL><INDENT>right_ext_len = len(tar) - pos - min_ss_len<EOL><DEDENT>else:<EOL><INDENT>right_ext_len = right_ext<EOL><DEDENT>if (<EOL>search_begin + left_ext_len + min_ss_len + right_ext_len<EOL>> search_begin<EOL>):<EOL><INDENT>search_val = tar[<EOL>search_begin : (<EOL>search_begin<EOL>+ left_ext_len<EOL>+ min_ss_len<EOL>+ right_ext_len<EOL>)<EOL>]<EOL><DEDENT>else:<EOL><INDENT>search_val = '<STR_LIT>'<EOL><DEDENT>flagged_tar = '<STR_LIT>'<EOL>while substring in search_val and pos + ix <= len(src):<EOL><INDENT>hit_len = len(substring)<EOL>flagged_tar = tar.replace(substring, '<STR_LIT:#>' * hit_len)<EOL>if pos + min_ss_len + ix <= len(src):<EOL><INDENT>substring = src[pos : pos + min_ss_len + ix]<EOL><DEDENT>if pos + min_ss_len + right_ext_len + <NUM_LIT:1> <= len(tar):<EOL><INDENT>right_ext_len += <NUM_LIT:1><EOL><DEDENT>search_val = tar[<EOL>search_begin : (<EOL>search_begin<EOL>+ left_ext_len<EOL>+ min_ss_len<EOL>+ right_ext_len<EOL>)<EOL>]<EOL>ix += <NUM_LIT:1><EOL><DEDENT>if hit_len > <NUM_LIT:0>:<EOL><INDENT>tar = flagged_tar<EOL><DEDENT>match_len += hit_len<EOL>pos += ix<EOL><DEDENT>

Return the Baystat similarity.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        min_ss_len : int
            Minimum substring length to be considered
        left_ext :int
            Left-side extension length
        right_ext :int
            Right-side extension length

        Returns
        -------
        float
            The Baystat similarity

        Examples
        --------
        >>> cmp = Baystat()
        >>> round(cmp.sim('cat', 'hat'), 12)
        0.666666666667
        >>> cmp.sim('Niall', 'Neil')
        0.4
        >>> round(cmp.sim('Colin', 'Cuilen'), 12)
        0.166666666667
        >>> cmp.sim('ATCG', 'TAGC')
        0.0


def sim_baystat(src, tar, min_ss_len=None, left_ext=None, right_ext=None):

return Baystat().sim(src, tar, min_ss_len, left_ext, right_ext)<EOL>

Return the Baystat similarity.

    This is a wrapper for :py:meth:`Baystat.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    min_ss_len : int
        Minimum substring length to be considered
    left_ext :int
        Left-side extension length
    right_ext :int
        Right-side extension length

    Returns
    -------
    float
        The Baystat similarity

    Examples
    --------
    >>> round(sim_baystat('cat', 'hat'), 12)
    0.666666666667
    >>> sim_baystat('Niall', 'Neil')
    0.4
    >>> round(sim_baystat('Colin', 'Cuilen'), 12)
    0.166666666667
    >>> sim_baystat('ATCG', 'TAGC')
    0.0


def dist_baystat(src, tar, min_ss_len=None, left_ext=None, right_ext=None):

return Baystat().dist(src, tar, min_ss_len, left_ext, right_ext)<EOL>

Return the Baystat distance.

    This is a wrapper for :py:meth:`Baystat.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    min_ss_len : int
        Minimum substring length to be considered
    left_ext : int
        Left-side extension length
    right_ext : int
        Right-side extension length

    Returns
    -------
    float
        The Baystat distance

    Examples
    --------
    >>> round(dist_baystat('cat', 'hat'), 12)
    0.333333333333
    >>> dist_baystat('Niall', 'Neil')
    0.6
    >>> round(dist_baystat('Colin', 'Cuilen'), 12)
    0.833333333333
    >>> dist_baystat('ATCG', 'TAGC')
    1.0


def sift4_simplest(src, tar, max_offset=<NUM_LIT:5>):

return Sift4Simplest().dist_abs(src, tar, max_offset)<EOL>

Return the "simplest" Sift4 distance between two terms.

    This is a wrapper for :py:meth:`Sift4Simplest.dist_abs`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    max_offset : int
        The number of characters to search for matching letters

    Returns
    -------
    int
        The Sift4 distance according to the simplest formula

    Examples
    --------
    >>> sift4_simplest('cat', 'hat')
    1
    >>> sift4_simplest('Niall', 'Neil')
    2
    >>> sift4_simplest('Colin', 'Cuilen')
    3
    >>> sift4_simplest('ATCG', 'TAGC')
    2


return Indel().dist(src, tar)<EOL>

Return the normalized indel distance between two strings.

    This is equivalent to normalized Levenshtein distance, when only inserts
    and deletes are possible.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Normalized indel distance

    Examples
    --------
    >>> round(dist_indel('cat', 'hat'), 12)
    0.333333333333
    >>> round(dist_indel('Niall', 'Neil'), 12)
    0.333333333333
    >>> round(dist_indel('Colin', 'Cuilen'), 12)
    0.454545454545
    >>> dist_indel('ATCG', 'TAGC')
    0.5


return self._lev.dist_abs(<EOL>src, tar, mode='<STR_LIT>', cost=(<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT>, <NUM_LIT>)<EOL>)<EOL>

Return the indel distance between two strings.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        int
            Indel distance

        Examples
        --------
        >>> cmp = Indel()
        >>> cmp.dist_abs('cat', 'hat')
        2
        >>> cmp.dist_abs('Niall', 'Neil')
        3
        >>> cmp.dist_abs('Colin', 'Cuilen')
        5
        >>> cmp.dist_abs('ATCG', 'TAGC')
        4


return Indel().dist_abs(src, tar)<EOL>

Return the indel distance between two strings.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    int
        Indel distance

    Examples
    --------
    >>> indel('cat', 'hat')
    2
    >>> indel('Niall', 'Neil')
    3
    >>> indel('Colin', 'Cuilen')
    5
    >>> indel('ATCG', 'TAGC')
    4


if src == tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>return self.dist_abs(src, tar) / (len(src) + len(tar))<EOL>

Return the normalized indel distance between two strings.

        This is equivalent to normalized Levenshtein distance, when only
        inserts and deletes are possible.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Normalized indel distance

        Examples
        --------
        >>> cmp = Indel()
        >>> round(cmp.dist('cat', 'hat'), 12)
        0.333333333333
        >>> round(cmp.dist('Niall', 'Neil'), 12)
        0.333333333333
        >>> round(cmp.dist('Colin', 'Cuilen'), 12)
        0.454545454545
        >>> cmp.dist('ATCG', 'TAGC')
        0.5


return RatcliffObershelp().sim(src, tar)<EOL>

Return the Ratcliff-Obershelp similarity of two strings.

    This is a wrapper for :py:meth:`RatcliffObershelp.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Ratcliff-Obershelp similarity

    Examples
    --------
    >>> round(sim_ratcliff_obershelp('cat', 'hat'), 12)
    0.666666666667
    >>> round(sim_ratcliff_obershelp('Niall', 'Neil'), 12)
    0.666666666667
    >>> round(sim_ratcliff_obershelp('aluminum', 'Catalan'), 12)
    0.4
    >>> sim_ratcliff_obershelp('ATCG', 'TAGC')
    0.5


def _lcsstr_stl(src, tar):<EOL><INDENT>"""<STR_LIT>"""<EOL>lengths = np_zeros((len(src) + <NUM_LIT:1>, len(tar) + <NUM_LIT:1>), dtype=np_int)<EOL>longest, src_longest, tar_longest = <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0><EOL>for i in range(<NUM_LIT:1>, len(src) + <NUM_LIT:1>):<EOL><INDENT>for j in range(<NUM_LIT:1>, len(tar) + <NUM_LIT:1>):<EOL><INDENT>if src[i - <NUM_LIT:1>] == tar[j - <NUM_LIT:1>]:<EOL><INDENT>lengths[i, j] = lengths[i - <NUM_LIT:1>, j - <NUM_LIT:1>] + <NUM_LIT:1><EOL>if lengths[i, j] > longest:<EOL><INDENT>longest = lengths[i, j]<EOL>src_longest = i<EOL>tar_longest = j<EOL><DEDENT><DEDENT>else:<EOL><INDENT>lengths[i, j] = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT>return src_longest - longest, tar_longest - longest, longest<EOL><DEDENT>def _sstr_matches(src, tar):<EOL><INDENT>"""<STR_LIT>"""<EOL>src_start, tar_start, length = _lcsstr_stl(src, tar)<EOL>if length == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>return (<EOL>_sstr_matches(src[:src_start], tar[:tar_start])<EOL>+ length<EOL>+ _sstr_matches(<EOL>src[src_start + length :], tar[tar_start + length :]<EOL>)<EOL>)<EOL><DEDENT>if src == tar:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>elif not src or not tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>return <NUM_LIT:2> * _sstr_matches(src, tar) / (len(src) + len(tar))<EOL>

Return the Ratcliff-Obershelp similarity of two strings.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Ratcliff-Obershelp similarity

        Examples
        --------
        >>> cmp = RatcliffObershelp()
        >>> round(cmp.sim('cat', 'hat'), 12)
        0.666666666667
        >>> round(cmp.sim('Niall', 'Neil'), 12)
        0.666666666667
        >>> round(cmp.sim('aluminum', 'Catalan'), 12)
        0.4
        >>> cmp.sim('ATCG', 'TAGC')
        0.5


def dist(src, tar, method=sim_levenshtein):

if callable(method):<EOL><INDENT>return <NUM_LIT:1> - method(src, tar)<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError('<STR_LIT>' + str(method))<EOL><DEDENT>

Return a distance between two strings.

    This is a generalized function for calling other distance functions.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    method : function
        Specifies the similarity metric (:py:func:`sim_levenshtein` by default)
        -- Note that this takes a similarity metric function, not a distance
        metric function.

    Returns
    -------
    float
        Distance according to the specified function

    Raises
    ------
    AttributeError
        Unknown distance function

    Examples
    --------
    >>> round(dist('cat', 'hat'), 12)
    0.333333333333
    >>> round(dist('Niall', 'Neil'), 12)
    0.6
    >>> dist('aluminum', 'Catalan')
    0.875
    >>> dist('ATCG', 'TAGC')
    0.75


def dist_abs(self, src, tar, qval=<NUM_LIT:2>, normalized=False, alphabet=None):

return super(self.__class__, self).dist_abs(<EOL>src, tar, qval, <NUM_LIT:1>, normalized, alphabet<EOL>)<EOL>

Return the Manhattan distance between two strings.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version
        normalized : bool
            Normalizes to [0, 1] if True
        alphabet : collection or int
            The values or size of the alphabet

        Returns
        -------
        float
            The Manhattan distance

        Examples
        --------
        >>> cmp = Manhattan()
        >>> cmp.dist_abs('cat', 'hat')
        4.0
        >>> cmp.dist_abs('Niall', 'Neil')
        7.0
        >>> cmp.dist_abs('Colin', 'Cuilen')
        9.0
        >>> cmp.dist_abs('ATCG', 'TAGC')
        10.0


def dist(self, src, tar, qval=<NUM_LIT:2>, alphabet=None):

return self.dist_abs(src, tar, qval, True, alphabet)<EOL>

Return the normalized Manhattan distance between two strings.

        The normalized Manhattan distance is a distance metric in
        :math:`L^1`-space, normalized to [0, 1].

        This is identical to Canberra distance.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version
        alphabet : collection or int
            The values or size of the alphabet

        Returns
        -------
        float
            The normalized Manhattan distance

        Examples
        --------
        >>> cmp = Manhattan()
        >>> cmp.dist('cat', 'hat')
        0.5
        >>> round(cmp.dist('Niall', 'Neil'), 12)
        0.636363636364
        >>> round(cmp.dist('Colin', 'Cuilen'), 12)
        0.692307692308
        >>> cmp.dist('ATCG', 'TAGC')
        1.0


return MRA().sim(src, tar)<EOL>

Return the normalized MRA similarity of two strings.

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

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Normalized MRA similarity

    Examples
    --------
    >>> sim_mra('cat', 'hat')
    0.8333333333333334
    >>> sim_mra('Niall', 'Neil')
    1.0
    >>> sim_mra('aluminum', 'Catalan')
    0.0
    >>> sim_mra('ATCG', 'TAGC')
    0.8333333333333334


return mra_compare(src, tar) / <NUM_LIT:6><EOL>

Return the normalized MRA similarity of two strings.

        This is the MRA normalized to :math:`[0, 1]`, given that MRA itself is
        constrained to the range :math:`[0, 6]`.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Normalized MRA similarity

        Examples
        --------
        >>> cmp = MRA()
        >>> cmp.sim('cat', 'hat')
        0.8333333333333334
        >>> cmp.sim('Niall', 'Neil')
        1.0
        >>> cmp.sim('aluminum', 'Catalan')
        0.0
        >>> cmp.sim('ATCG', 'TAGC')
        0.8333333333333334


return Prefix().dist(src, tar)<EOL>

Return the prefix distance between two strings.

    This is a wrapper for :py:meth:`Prefix.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Prefix distance

    Examples
    --------
    >>> dist_prefix('cat', 'hat')
    1.0
    >>> dist_prefix('Niall', 'Neil')
    0.75
    >>> dist_prefix('aluminum', 'Catalan')
    1.0
    >>> dist_prefix('ATCG', 'TAGC')
    1.0


return Ident().dist(src, tar)<EOL>

Return the identity distance between two strings.

    This is a wrapper for :py:meth:`Ident.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Identity distance

    Examples
    --------
    >>> dist_ident('cat', 'hat')
    1.0
    >>> dist_ident('cat', 'cat')
    0.0


return Ident().sim(src, tar)<EOL>

Return the identity similarity of two strings.

    This is a wrapper for :py:meth:`Ident.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Identity similarity

    Examples
    --------
    >>> sim_ident('cat', 'hat')
    0.0
    >>> sim_ident('cat', 'cat')
    1.0


return NCDbwtrle().sim(src, tar)<EOL>

Return the NCD similarity between two strings using BWT plus RLE.

    This is a wrapper for :py:meth:`NCDbwtrle.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Compression similarity

    Examples
    --------
    >>> sim_ncd_bwtrle('cat', 'hat')
    0.25
    >>> sim_ncd_bwtrle('Niall', 'Neil')
    0.16666666666666663
    >>> sim_ncd_bwtrle('aluminum', 'Catalan')
    0.0
    >>> sim_ncd_bwtrle('ATCG', 'TAGC')
    0.19999999999999996


return Length().sim(src, tar)<EOL>

Return the length similarity of two strings.

    This is a wrapper for :py:meth:`Length.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Length similarity

    Examples
    --------
    >>> sim_length('cat', 'hat')
    1.0
    >>> sim_length('Niall', 'Neil')
    0.8
    >>> sim_length('aluminum', 'Catalan')
    0.875
    >>> sim_length('ATCG', 'TAGC')
    1.0


if src == tar:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>if not src or not tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>return (<EOL>len(src) / len(tar) if len(src) < len(tar) else len(tar) / len(src)<EOL>)<EOL>

Return the length similarity of two strings.

        Length similarity is the ratio of the length of the shorter string to
        the longer.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Length similarity

        Examples
        --------
        >>> cmp = Length()
        >>> cmp.sim('cat', 'hat')
        1.0
        >>> cmp.sim('Niall', 'Neil')
        0.8
        >>> cmp.sim('aluminum', 'Catalan')
        0.875
        >>> cmp.sim('ATCG', 'TAGC')
        1.0


self._level = level<EOL>

Initialize bzip2 compressor.

        Parameters
        ----------
        level : int
            The compression level (0 to 9)


if src == tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>src = src.encode('<STR_LIT:utf-8>')<EOL>tar = tar.encode('<STR_LIT:utf-8>')<EOL>src_comp = bz2.compress(src, self._level)[<NUM_LIT:10>:]<EOL>tar_comp = bz2.compress(tar, self._level)[<NUM_LIT:10>:]<EOL>concat_comp = bz2.compress(src + tar, self._level)[<NUM_LIT:10>:]<EOL>concat_comp2 = bz2.compress(tar + src, self._level)[<NUM_LIT:10>:]<EOL>return (<EOL>min(len(concat_comp), len(concat_comp2))<EOL>- min(len(src_comp), len(tar_comp))<EOL>) / max(len(src_comp), len(tar_comp))<EOL>

Return the NCD between two strings using bzip2 compression.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Compression distance

        Examples
        --------
        >>> cmp = NCDbz2()
        >>> cmp.dist('cat', 'hat')
        0.06666666666666667
        >>> cmp.dist('Niall', 'Neil')
        0.03125
        >>> cmp.dist('aluminum', 'Catalan')
        0.17647058823529413
        >>> cmp.dist('ATCG', 'TAGC')
        0.03125


if mode == '<STR_LIT>':<EOL><INDENT>if boost_threshold > <NUM_LIT:1> or boost_threshold < <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>)<EOL><DEDENT>if scaling_factor > <NUM_LIT> or scaling_factor < <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT>if src == tar:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>src = QGrams(src.strip(), qval)._ordered_list<EOL>tar = QGrams(tar.strip(), qval)._ordered_list<EOL>lens = len(src)<EOL>lent = len(tar)<EOL>if lens == <NUM_LIT:0> or lent == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>if lens > lent:<EOL><INDENT>search_range = lens<EOL>minv = lent<EOL><DEDENT>else:<EOL><INDENT>search_range = lent<EOL>minv = lens<EOL><DEDENT>src_flag = [<NUM_LIT:0>] * search_range<EOL>tar_flag = [<NUM_LIT:0>] * search_range<EOL>search_range = max(<NUM_LIT:0>, search_range // <NUM_LIT:2> - <NUM_LIT:1>)<EOL>num_com = <NUM_LIT:0><EOL>yl1 = lent - <NUM_LIT:1><EOL>for i in range(lens):<EOL><INDENT>low_lim = (i - search_range) if (i >= search_range) else <NUM_LIT:0><EOL>hi_lim = (i + search_range) if ((i + search_range) <= yl1) else yl1<EOL>for j in range(low_lim, hi_lim + <NUM_LIT:1>):<EOL><INDENT>if (tar_flag[j] == <NUM_LIT:0>) and (tar[j] == src[i]):<EOL><INDENT>tar_flag[j] = <NUM_LIT:1><EOL>src_flag[i] = <NUM_LIT:1><EOL>num_com += <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT><DEDENT>if num_com == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>k = n_trans = <NUM_LIT:0><EOL>for i in range(lens):<EOL><INDENT>if src_flag[i] != <NUM_LIT:0>:<EOL><INDENT>j = <NUM_LIT:0><EOL>for j in range(k, lent):  <EOL><INDENT>if tar_flag[j] != <NUM_LIT:0>:<EOL><INDENT>k = j + <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>if src[i] != tar[j]:<EOL><INDENT>n_trans += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>n_trans //= <NUM_LIT:2><EOL>weight = (<EOL>num_com / lens + num_com / lent + (num_com - n_trans) / num_com<EOL>)<EOL>weight /= <NUM_LIT><EOL>if mode == '<STR_LIT>' and weight > boost_threshold:<EOL><INDENT>j = <NUM_LIT:4> if (minv >= <NUM_LIT:4>) else minv<EOL>i = <NUM_LIT:0><EOL>while (i < j) and (src[i] == tar[i]):<EOL><INDENT>i += <NUM_LIT:1><EOL><DEDENT>weight += i * scaling_factor * (<NUM_LIT:1.0> - weight)<EOL>if (<EOL>long_strings<EOL>and (minv > <NUM_LIT:4>)<EOL>and (num_com > i + <NUM_LIT:1>)<EOL>and (<NUM_LIT:2> * num_com >= minv + i)<EOL>):<EOL><INDENT>weight += (<NUM_LIT:1.0> - weight) * (<EOL>(num_com - i - <NUM_LIT:1>) / (lens + lent - i * <NUM_LIT:2> + <NUM_LIT:2>)<EOL>)<EOL><DEDENT><DEDENT>return weight<EOL>

Return the Jaro or Jaro-Winkler similarity of two strings.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        qval : int
            The length of each q-gram (defaults to 1: character-wise matching)
        mode : str
            Indicates which variant of this distance metric to compute:

                - ``winkler`` -- computes the Jaro-Winkler distance (default)
                  which increases the score for matches near the start of the
                  word
                - ``jaro`` -- computes the Jaro distance

        long_strings : bool
            Set to True to "Increase the probability of a match when the number
            of matched characters is large. This option allows for a little
            more tolerance when the strings are large. It is not an appropriate
            test when comparing fixed length fields such as phone and social
            security numbers." (Used in 'winkler' mode only.)
        boost_threshold : float
            A value between 0 and 1, below which the Winkler boost is not
            applied (defaults to 0.7). (Used in 'winkler' mode only.)
        scaling_factor : float
            A value between 0 and 0.25, indicating by how much to boost scores
            for matching prefixes (defaults to 0.1). (Used in 'winkler' mode
            only.)

        Returns
        -------
        float
            Jaro or Jaro-Winkler similarity

        Raises
        ------
        ValueError
            Unsupported boost_threshold assignment; boost_threshold must be
            between 0 and 1.
        ValueError
            Unsupported scaling_factor assignment; scaling_factor must be
            between 0 and 0.25.'

        Examples
        --------
        >>> round(sim_jaro_winkler('cat', 'hat'), 12)
        0.777777777778
        >>> round(sim_jaro_winkler('Niall', 'Neil'), 12)
        0.805
        >>> round(sim_jaro_winkler('aluminum', 'Catalan'), 12)
        0.60119047619
        >>> round(sim_jaro_winkler('ATCG', 'TAGC'), 12)
        0.833333333333

        >>> round(sim_jaro_winkler('cat', 'hat', mode='jaro'), 12)
        0.777777777778
        >>> round(sim_jaro_winkler('Niall', 'Neil', mode='jaro'), 12)
        0.783333333333
        >>> round(sim_jaro_winkler('aluminum', 'Catalan', mode='jaro'), 12)
        0.60119047619
        >>> round(sim_jaro_winkler('ATCG', 'TAGC', mode='jaro'), 12)
        0.833333333333


return JaroWinkler().dist(<EOL>src, tar, qval, mode, long_strings, boost_threshold, scaling_factor<EOL>)<EOL>

Return the Jaro or Jaro-Winkler distance between two strings.

    This is a wrapper for :py:meth:`JaroWinkler.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    qval : int
        The length of each q-gram (defaults to 1: character-wise matching)
    mode : str
        Indicates which variant of this distance metric to compute:

            - ``winkler`` -- computes the Jaro-Winkler distance (default) which
              increases the score for matches near the start of the word
            - ``jaro`` -- computes the Jaro distance

    long_strings : bool
        Set to True to "Increase the probability of a match when the number of
        matched characters is large. This option allows for a little more
        tolerance when the strings are large. It is not an appropriate test
        when comparing fixedlength fields such as phone and social security
        numbers." (Used in 'winkler' mode only.)
    boost_threshold : float
        A value between 0 and 1, below which the Winkler boost is not applied
        (defaults to 0.7). (Used in 'winkler' mode only.)
    scaling_factor : float
        A value between 0 and 0.25, indicating by how much to boost scores for
        matching prefixes (defaults to 0.1). (Used in 'winkler' mode only.)

    Returns
    -------
    float
        Jaro or Jaro-Winkler distance

    Examples
    --------
    >>> round(dist_jaro_winkler('cat', 'hat'), 12)
    0.222222222222
    >>> round(dist_jaro_winkler('Niall', 'Neil'), 12)
    0.195
    >>> round(dist_jaro_winkler('aluminum', 'Catalan'), 12)
    0.39880952381
    >>> round(dist_jaro_winkler('ATCG', 'TAGC'), 12)
    0.166666666667

    >>> round(dist_jaro_winkler('cat', 'hat', mode='jaro'), 12)
    0.222222222222
    >>> round(dist_jaro_winkler('Niall', 'Neil', mode='jaro'), 12)
    0.216666666667
    >>> round(dist_jaro_winkler('aluminum', 'Catalan', mode='jaro'), 12)
    0.39880952381
    >>> round(dist_jaro_winkler('ATCG', 'TAGC', mode='jaro'), 12)
    0.166666666667


def dist_overlap(src, tar, qval=<NUM_LIT:2>):

return Overlap().dist(src, tar, qval)<EOL>

Return the overlap distance between two strings.

    This is a wrapper for :py:meth:`Overlap.dist`.

    Parameters
    ----------
    src : str
        Source string (or QGrams/Counter objects) for comparison
    tar : str
        Target string (or QGrams/Counter objects) for comparison
    qval : int
        The length of each q-gram; 0 for non-q-gram version

    Returns
    -------
    float
        Overlap distance

    Examples
    --------
    >>> dist_overlap('cat', 'hat')
    0.5
    >>> dist_overlap('Niall', 'Neil')
    0.6
    >>> dist_overlap('aluminum', 'Catalan')
    0.875
    >>> dist_overlap('ATCG', 'TAGC')
    1.0


ins_cost, del_cost, sub_cost, shift_cost = cost<EOL>if src == tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>if not src:<EOL><INDENT>return len(tar) * ins_cost<EOL><DEDENT>if not tar:<EOL><INDENT>return len(src) * del_cost<EOL><DEDENT>keyboard = self._keyboard[layout]<EOL>lowercase = {item for sublist in keyboard[<NUM_LIT:0>] for item in sublist}<EOL>uppercase = {item for sublist in keyboard[<NUM_LIT:1>] for item in sublist}<EOL>def _kb_array_for_char(char):<EOL><INDENT>"""<STR_LIT>"""<EOL>if char in lowercase:<EOL><INDENT>return keyboard[<NUM_LIT:0>]<EOL><DEDENT>elif char in uppercase:<EOL><INDENT>return keyboard[<NUM_LIT:1>]<EOL><DEDENT>raise ValueError(char + '<STR_LIT>')<EOL><DEDENT>def _substitution_cost(char1, char2):<EOL><INDENT>cost = sub_cost<EOL>cost *= metric_dict[metric](char1, char2) + shift_cost * (<EOL>_kb_array_for_char(char1) != _kb_array_for_char(char2)<EOL>)<EOL>return cost<EOL><DEDENT>def _get_char_coord(char, kb_array):<EOL><INDENT>"""<STR_LIT>"""<EOL>for row in kb_array:  <EOL><INDENT>if char in row:<EOL><INDENT>return kb_array.index(row), row.index(char)<EOL><DEDENT><DEDENT><DEDENT>def _euclidean_keyboard_distance(char1, char2):<EOL><INDENT>row1, col1 = _get_char_coord(char1, _kb_array_for_char(char1))<EOL>row2, col2 = _get_char_coord(char2, _kb_array_for_char(char2))<EOL>return ((row1 - row2) ** <NUM_LIT:2> + (col1 - col2) ** <NUM_LIT:2>) ** <NUM_LIT:0.5><EOL><DEDENT>def _manhattan_keyboard_distance(char1, char2):<EOL><INDENT>row1, col1 = _get_char_coord(char1, _kb_array_for_char(char1))<EOL>row2, col2 = _get_char_coord(char2, _kb_array_for_char(char2))<EOL>return abs(row1 - row2) + abs(col1 - col2)<EOL><DEDENT>def _log_euclidean_keyboard_distance(char1, char2):<EOL><INDENT>return log(<NUM_LIT:1> + _euclidean_keyboard_distance(char1, char2))<EOL><DEDENT>def _log_manhattan_keyboard_distance(char1, char2):<EOL><INDENT>return log(<NUM_LIT:1> + _manhattan_keyboard_distance(char1, char2))<EOL><DEDENT>metric_dict = {<EOL>'<STR_LIT>': _euclidean_keyboard_distance,<EOL>'<STR_LIT>': _manhattan_keyboard_distance,<EOL>'<STR_LIT>': _log_euclidean_keyboard_distance,<EOL>'<STR_LIT>': _log_manhattan_keyboard_distance,<EOL>}<EOL>d_mat = np_zeros((len(src) + <NUM_LIT:1>, len(tar) + <NUM_LIT:1>), dtype=np_float32)<EOL>for i in range(len(src) + <NUM_LIT:1>):<EOL><INDENT>d_mat[i, <NUM_LIT:0>] = i * del_cost<EOL><DEDENT>for j in range(len(tar) + <NUM_LIT:1>):<EOL><INDENT>d_mat[<NUM_LIT:0>, j] = j * ins_cost<EOL><DEDENT>for i in range(len(src)):<EOL><INDENT>for j in range(len(tar)):<EOL><INDENT>d_mat[i + <NUM_LIT:1>, j + <NUM_LIT:1>] = min(<EOL>d_mat[i + <NUM_LIT:1>, j] + ins_cost,  <EOL>d_mat[i, j + <NUM_LIT:1>] + del_cost,  <EOL>d_mat[i, j]<EOL>+ (<EOL>_substitution_cost(src[i], tar[j])<EOL>if src[i] != tar[j]<EOL>else <NUM_LIT:0><EOL>),  <EOL>)<EOL><DEDENT><DEDENT>return d_mat[len(src), len(tar)]<EOL>

Return the typo distance between two strings.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        metric : str
            Supported values include: ``euclidean``, ``manhattan``,
            ``log-euclidean``, and ``log-manhattan``
        cost : tuple
            A 4-tuple representing the cost of the four possible edits:
            inserts, deletes, substitutions, and shift, respectively (by
            default: (1, 1, 0.5, 0.5)) The substitution & shift costs should be
            significantly less than the cost of an insertion & deletion unless
            a log metric is used.
        layout : str
            Name of the keyboard layout to use (Currently supported:
            ``QWERTY``, ``Dvorak``, ``AZERTY``, ``QWERTZ``)

        Returns
        -------
        float
            Typo distance

        Raises
        ------
        ValueError
            char not found in any keyboard layouts

        Examples
        --------
        >>> cmp = Typo()
        >>> cmp.dist_abs('cat', 'hat')
        1.5811388
        >>> cmp.dist_abs('Niall', 'Neil')
        2.8251407
        >>> cmp.dist_abs('Colin', 'Cuilen')
        3.4142137
        >>> cmp.dist_abs('ATCG', 'TAGC')
        2.5

        >>> cmp.dist_abs('cat', 'hat', metric='manhattan')
        2.0
        >>> cmp.dist_abs('Niall', 'Neil', metric='manhattan')
        3.0
        >>> cmp.dist_abs('Colin', 'Cuilen', metric='manhattan')
        3.5
        >>> cmp.dist_abs('ATCG', 'TAGC', metric='manhattan')
        2.5

        >>> cmp.dist_abs('cat', 'hat', metric='log-manhattan')
        0.804719
        >>> cmp.dist_abs('Niall', 'Neil', metric='log-manhattan')
        2.2424533
        >>> cmp.dist_abs('Colin', 'Cuilen', metric='log-manhattan')
        2.2424533
        >>> cmp.dist_abs('ATCG', 'TAGC', metric='log-manhattan')
        2.3465736


def typo(src, tar, metric='<STR_LIT>', cost=(<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0.5>, <NUM_LIT:0.5>), layout='<STR_LIT>'):

return Typo().dist_abs(src, tar, metric, cost, layout)<EOL>

Return the typo distance between two strings.

    This is a wrapper for :py:meth:`Typo.typo`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    metric : str
        Supported values include: ``euclidean``, ``manhattan``,
        ``log-euclidean``, and ``log-manhattan``
    cost : tuple
        A 4-tuple representing the cost of the four possible edits: inserts,
        deletes, substitutions, and shift, respectively (by default:
        (1, 1, 0.5, 0.5)) The substitution & shift costs should be
        significantly less than the cost of an insertion & deletion unless a
        log metric is used.
    layout : str
        Name of the keyboard layout to use (Currently supported:
        ``QWERTY``, ``Dvorak``, ``AZERTY``, ``QWERTZ``)

    Returns
    -------
    float
        Typo distance

    Examples
    --------
    >>> typo('cat', 'hat')
    1.5811388
    >>> typo('Niall', 'Neil')
    2.8251407
    >>> typo('Colin', 'Cuilen')
    3.4142137
    >>> typo('ATCG', 'TAGC')
    2.5

    >>> typo('cat', 'hat', metric='manhattan')
    2.0
    >>> typo('Niall', 'Neil', metric='manhattan')
    3.0
    >>> typo('Colin', 'Cuilen', metric='manhattan')
    3.5
    >>> typo('ATCG', 'TAGC', metric='manhattan')
    2.5

    >>> typo('cat', 'hat', metric='log-manhattan')
    0.804719
    >>> typo('Niall', 'Neil', metric='log-manhattan')
    2.2424533
    >>> typo('Colin', 'Cuilen', metric='log-manhattan')
    2.2424533
    >>> typo('ATCG', 'TAGC', metric='log-manhattan')
    2.3465736


def dist_minkowski(src, tar, qval=<NUM_LIT:2>, pval=<NUM_LIT:1>, alphabet=None):

return Minkowski().dist(src, tar, qval, pval, alphabet)<EOL>

Return normalized Minkowski distance of two strings.

    This is a wrapper for :py:meth:`Minkowski.dist`.

    Parameters
    ----------
    src : str
        Source string (or QGrams/Counter objects) for comparison
    tar : str
        Target string (or QGrams/Counter objects) for comparison
    qval : int
        The length of each q-gram; 0 for non-q-gram version
    pval : int or float
        The :math:`p`-value of the :math:`L^p`-space
    alphabet : collection or int
        The values or size of the alphabet

    Returns
    -------
    float
        The normalized Minkowski distance

    Examples
    --------
    >>> dist_minkowski('cat', 'hat')
    0.5
    >>> round(dist_minkowski('Niall', 'Neil'), 12)
    0.636363636364
    >>> round(dist_minkowski('Colin', 'Cuilen'), 12)
    0.692307692308
    >>> dist_minkowski('ATCG', 'TAGC')
    1.0


def dist_abs(<EOL>self, src, tar, qval=<NUM_LIT:2>, pval=<NUM_LIT:1>, normalized=False, alphabet=None<EOL>):

q_src, q_tar = self._get_qgrams(src, tar, qval)<EOL>diffs = ((q_src - q_tar) + (q_tar - q_src)).values()<EOL>normalizer = <NUM_LIT:1><EOL>if normalized:<EOL><INDENT>totals = (q_src + q_tar).values()<EOL>if alphabet is not None:<EOL><INDENT>normalizer = (<EOL>alphabet if isinstance(alphabet, Number) else len(alphabet)<EOL>)<EOL><DEDENT>elif pval == <NUM_LIT:0>:<EOL><INDENT>normalizer = len(totals)<EOL><DEDENT>else:<EOL><INDENT>normalizer = sum(_ ** pval for _ in totals) ** (<NUM_LIT:1> / pval)<EOL><DEDENT><DEDENT>if len(diffs) == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>if pval == float('<STR_LIT>'):<EOL><INDENT>return max(diffs) / normalizer<EOL><DEDENT>if pval == <NUM_LIT:0>:<EOL><INDENT>return len(diffs) / normalizer<EOL><DEDENT>return sum(_ ** pval for _ in diffs) ** (<NUM_LIT:1> / pval) / normalizer<EOL>

Return the Minkowski distance (:math:`L^p`-norm) of two strings.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version
        pval : int or float
            The :math:`p`-value of the :math:`L^p`-space
        normalized : bool
            Normalizes to [0, 1] if True
        alphabet : collection or int
            The values or size of the alphabet

        Returns
        -------
        float
            The Minkowski distance

        Examples
        --------
        >>> cmp = Minkowski()
        >>> cmp.dist_abs('cat', 'hat')
        4.0
        >>> cmp.dist_abs('Niall', 'Neil')
        7.0
        >>> cmp.dist_abs('Colin', 'Cuilen')
        9.0
        >>> cmp.dist_abs('ATCG', 'TAGC')
        10.0


def dist(self, src, tar, qval=<NUM_LIT:2>, pval=<NUM_LIT:1>, alphabet=None):

return self.dist_abs(src, tar, qval, pval, True, alphabet)<EOL>

Return normalized Minkowski distance of two strings.

        The normalized Minkowski distance :cite:`Minkowski:1910` is a distance
        metric in :math:`L^p`-space, normalized to [0, 1].

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version
        pval : int or float
            The :math:`p`-value of the :math:`L^p`-space
        alphabet : collection or int
            The values or size of the alphabet

        Returns
        -------
        float
            The normalized Minkowski distance

        Examples
        --------
        >>> cmp = Minkowski()
        >>> cmp.dist('cat', 'hat')
        0.5
        >>> round(cmp.dist('Niall', 'Neil'), 12)
        0.636363636364
        >>> round(cmp.dist('Colin', 'Cuilen'), 12)
        0.692307692308
        >>> cmp.dist('ATCG', 'TAGC')
        1.0


def minkowski(src, tar, qval=<NUM_LIT:2>, pval=<NUM_LIT:1>, normalized=False, alphabet=None):

return Minkowski().dist_abs(src, tar, qval, pval, normalized, alphabet)<EOL>

Return the Minkowski distance (:math:`L^p`-norm) of two strings.

    This is a wrapper for :py:meth:`Minkowski.dist_abs`.

    Parameters
    ----------
    src : str
        Source string (or QGrams/Counter objects) for comparison
    tar : str
        Target string (or QGrams/Counter objects) for comparison
    qval : int
        The length of each q-gram; 0 for non-q-gram version
    pval : int or float
        The :math:`p`-value of the :math:`L^p`-space
    normalized : bool
        Normalizes to [0, 1] if True
    alphabet : collection or int
        The values or size of the alphabet

    Returns
    -------
    float
        The Minkowski distance

    Examples
    --------
    >>> minkowski('cat', 'hat')
    4.0
    >>> minkowski('Niall', 'Neil')
    7.0
    >>> minkowski('Colin', 'Cuilen')
    9.0
    >>> minkowski('ATCG', 'TAGC')
    10.0


def sim_minkowski(src, tar, qval=<NUM_LIT:2>, pval=<NUM_LIT:1>, alphabet=None):

return Minkowski().sim(src, tar, qval, pval, alphabet)<EOL>

Return normalized Minkowski similarity of two strings.

    This is a wrapper for :py:meth:`Minkowski.sim`.

    Parameters
    ----------
    src : str
        Source string (or QGrams/Counter objects) for comparison
    tar : str
        Target string (or QGrams/Counter objects) for comparison
    qval : int
        The length of each q-gram; 0 for non-q-gram version
    pval : int or float
        The :math:`p`-value of the :math:`L^p`-space
    alphabet : collection or int
        The values or size of the alphabet

    Returns
    -------
    float
        The normalized Minkowski similarity

    Examples
    --------
    >>> sim_minkowski('cat', 'hat')
    0.5
    >>> round(sim_minkowski('Niall', 'Neil'), 12)
    0.363636363636
    >>> round(sim_minkowski('Colin', 'Cuilen'), 12)
    0.307692307692
    >>> sim_minkowski('ATCG', 'TAGC')
    0.0


if src == tar:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>if not src or not tar:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>min_word, max_word = (src, tar) if len(src) < len(tar) else (tar, src)<EOL>min_len = len(min_word)<EOL>for i in range(min_len, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if min_word[-i:] == max_word[-i:]:<EOL><INDENT>return i / min_len<EOL><DEDENT><DEDENT>return <NUM_LIT:0.0><EOL>

Return the suffix similarity of two strings.

        Suffix similarity is the ratio of the length of the shorter term that
        exactly matches the longer term to the length of the shorter term,
        beginning at the end of both terms.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison

        Returns
        -------
        float
            Suffix similarity

        Examples
        --------
        >>> cmp = Suffix()
        >>> cmp.sim('cat', 'hat')
        0.6666666666666666
        >>> cmp.sim('Niall', 'Neil')
        0.25
        >>> cmp.sim('aluminum', 'Catalan')
        0.0
        >>> cmp.sim('ATCG', 'TAGC')
        0.0


return Suffix().sim(src, tar)<EOL>

Return the suffix similarity of two strings.

    This is a wrapper for :py:meth:`Suffix.sim`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Suffix similarity

    Examples
    --------
    >>> sim_suffix('cat', 'hat')
    0.6666666666666666
    >>> sim_suffix('Niall', 'Neil')
    0.25
    >>> sim_suffix('aluminum', 'Catalan')
    0.0
    >>> sim_suffix('ATCG', 'TAGC')
    0.0


return Suffix().dist(src, tar)<EOL>

Return the suffix distance between two strings.

    This is a wrapper for :py:meth:`Suffix.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Suffix distance

    Examples
    --------
    >>> dist_suffix('cat', 'hat')
    0.33333333333333337
    >>> dist_suffix('Niall', 'Neil')
    0.75
    >>> dist_suffix('aluminum', 'Catalan')
    1.0
    >>> dist_suffix('ATCG', 'TAGC')
    1.0


def dist_abs(self, src, tar, *args, **kwargs):

return self.dist(src, tar, *args, **kwargs)<EOL>

Return absolute distance.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        *args
            Variable length argument list.
        **kwargs
            Arbitrary keyword arguments.

        Returns
        -------
        int
            Absolute distance


return NCDlzma().dist(src, tar)<EOL>

Return the NCD between two strings using LZMA compression.

    This is a wrapper for :py:meth:`NCDlzma.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison

    Returns
    -------
    float
        Compression distance

    Examples
    --------
    >>> dist_ncd_lzma('cat', 'hat')
    0.08695652173913043
    >>> dist_ncd_lzma('Niall', 'Neil')
    0.16
    >>> dist_ncd_lzma('aluminum', 'Catalan')
    0.16
    >>> dist_ncd_lzma('ATCG', 'TAGC')
    0.08695652173913043


def dist(self, src, tar, weights='<STR_LIT>', max_length=<NUM_LIT:8>):

return self.dist_abs(src, tar, weights, max_length, True)<EOL>

Return normalized distance between the Eudex hashes of two terms.

        This is Eudex distance normalized to [0, 1].

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        weights : str, iterable, or generator function
            The weights or weights generator function
        max_length : int
            The number of characters to encode as a eudex hash

        Returns
        -------
        int
            The normalized Eudex Hamming distance

        Examples
        --------
        >>> cmp = Eudex()
        >>> round(cmp.dist('cat', 'hat'), 12)
        0.062745098039
        >>> round(cmp.dist('Niall', 'Neil'), 12)
        0.000980392157
        >>> round(cmp.dist('Colin', 'Cuilen'), 12)
        0.004901960784
        >>> round(cmp.dist('ATCG', 'TAGC'), 12)
        0.197549019608


def eudex_hamming(<EOL>src, tar, weights='<STR_LIT>', max_length=<NUM_LIT:8>, normalized=False<EOL>):

return Eudex().dist_abs(src, tar, weights, max_length, normalized)<EOL>

Calculate the Hamming distance between the Eudex hashes of two terms.

    This is a wrapper for :py:meth:`Eudex.eudex_hamming`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    weights : str, iterable, or generator function
        The weights or weights generator function
    max_length : int
        The number of characters to encode as a eudex hash
    normalized : bool
        Normalizes to [0, 1] if True

    Returns
    -------
    int
        The Eudex Hamming distance

    Examples
    --------
    >>> eudex_hamming('cat', 'hat')
    128
    >>> eudex_hamming('Niall', 'Neil')
    2
    >>> eudex_hamming('Colin', 'Cuilen')
    10
    >>> eudex_hamming('ATCG', 'TAGC')
    403

    >>> eudex_hamming('cat', 'hat', weights='fibonacci')
    34
    >>> eudex_hamming('Niall', 'Neil', weights='fibonacci')
    2
    >>> eudex_hamming('Colin', 'Cuilen', weights='fibonacci')
    7
    >>> eudex_hamming('ATCG', 'TAGC', weights='fibonacci')
    117

    >>> eudex_hamming('cat', 'hat', weights=None)
    1
    >>> eudex_hamming('Niall', 'Neil', weights=None)
    1
    >>> eudex_hamming('Colin', 'Cuilen', weights=None)
    2
    >>> eudex_hamming('ATCG', 'TAGC', weights=None)
    9

    >>> # Using the OEIS A000142:
    >>> eudex_hamming('cat', 'hat', [1, 1, 2, 6, 24, 120, 720, 5040])
    1
    >>> eudex_hamming('Niall', 'Neil', [1, 1, 2, 6, 24, 120, 720, 5040])
    720
    >>> eudex_hamming('Colin', 'Cuilen', [1, 1, 2, 6, 24, 120, 720, 5040])
    744
    >>> eudex_hamming('ATCG', 'TAGC', [1, 1, 2, 6, 24, 120, 720, 5040])
    6243


def dist_abs(<EOL>self, src, tar, weights='<STR_LIT>', max_length=<NUM_LIT:8>, normalized=False<EOL>):

<EOL>xored = eudex(src, max_length=max_length) ^ eudex(<EOL>tar, max_length=max_length<EOL>)<EOL>if not weights:<EOL><INDENT>binary = bin(xored)<EOL>distance = binary.count('<STR_LIT:1>')<EOL>if normalized:<EOL><INDENT>return distance / (len(binary) - <NUM_LIT:2>)<EOL><DEDENT>return distance<EOL><DEDENT>if callable(weights):<EOL><INDENT>weights = weights()<EOL><DEDENT>elif weights == '<STR_LIT>':<EOL><INDENT>weights = Eudex.gen_exponential()<EOL><DEDENT>elif weights == '<STR_LIT>':<EOL><INDENT>weights = Eudex.gen_fibonacci()<EOL><DEDENT>if isinstance(weights, GeneratorType):<EOL><INDENT>weights = [next(weights) for _ in range(max_length)][::-<NUM_LIT:1>]<EOL><DEDENT>distance = <NUM_LIT:0><EOL>max_distance = <NUM_LIT:0><EOL>while (xored or normalized) and weights:<EOL><INDENT>max_distance += <NUM_LIT:8> * weights[-<NUM_LIT:1>]<EOL>distance += bin(xored & <NUM_LIT>).count('<STR_LIT:1>') * weights.pop()<EOL>xored >>= <NUM_LIT:8><EOL><DEDENT>if normalized:<EOL><INDENT>distance /= max_distance<EOL><DEDENT>return distance<EOL>

Calculate the distance between the Eudex hashes of two terms.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        weights : str, iterable, or generator function
            The weights or weights generator function

                - If set to ``None``, a simple Hamming distance is calculated.
                - If set to ``exponential``, weight decays by powers of 2, as
                  proposed in the eudex specification:
                  https://github.com/ticki/eudex.
                - If set to ``fibonacci``, weight decays through the Fibonacci
                  series, as in the eudex reference implementation.
                - If set to a callable function, this assumes it creates a
                  generator and the generator is used to populate a series of
                  weights.
                - If set to an iterable, the iterable's values should be
                  integers and will be used as the weights.

        max_length : int
            The number of characters to encode as a eudex hash
        normalized : bool
            Normalizes to [0, 1] if True

        Returns
        -------
        int
            The Eudex Hamming distance

        Examples
        --------
        >>> cmp = Eudex()
        >>> cmp.dist_abs('cat', 'hat')
        128
        >>> cmp.dist_abs('Niall', 'Neil')
        2
        >>> cmp.dist_abs('Colin', 'Cuilen')
        10
        >>> cmp.dist_abs('ATCG', 'TAGC')
        403

        >>> cmp.dist_abs('cat', 'hat', weights='fibonacci')
        34
        >>> cmp.dist_abs('Niall', 'Neil', weights='fibonacci')
        2
        >>> cmp.dist_abs('Colin', 'Cuilen', weights='fibonacci')
        7
        >>> cmp.dist_abs('ATCG', 'TAGC', weights='fibonacci')
        117

        >>> cmp.dist_abs('cat', 'hat', weights=None)
        1
        >>> cmp.dist_abs('Niall', 'Neil', weights=None)
        1
        >>> cmp.dist_abs('Colin', 'Cuilen', weights=None)
        2
        >>> cmp.dist_abs('ATCG', 'TAGC', weights=None)
        9

        >>> # Using the OEIS A000142:
        >>> cmp.dist_abs('cat', 'hat', [1, 1, 2, 6, 24, 120, 720, 5040])
        1
        >>> cmp.dist_abs('Niall', 'Neil', [1, 1, 2, 6, 24, 120, 720, 5040])
        720
        >>> cmp.dist_abs('Colin', 'Cuilen',
        ... [1, 1, 2, 6, 24, 120, 720, 5040])
        744
        >>> cmp.dist_abs('ATCG', 'TAGC', [1, 1, 2, 6, 24, 120, 720, 5040])
        6243


def tanimoto_coeff(self, src, tar, qval=<NUM_LIT:2>):

coeff = self.sim(src, tar, qval)<EOL>if coeff != <NUM_LIT:0>:<EOL><INDENT>return log(coeff, <NUM_LIT:2>)<EOL><DEDENT>return float('<STR_LIT>')<EOL>

Return the Tanimoto distance between two strings.

        Tanimoto distance :cite:`Tanimoto:1958` is
        :math:`-log_{2} sim_{Tanimoto}(X, Y)`.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version

        Returns
        -------
        float
            Tanimoto distance

        Examples
        --------
        >>> cmp = Jaccard()
        >>> cmp.tanimoto_coeff('cat', 'hat')
        -1.5849625007211563
        >>> cmp.tanimoto_coeff('Niall', 'Neil')
        -2.1699250014423126
        >>> cmp.tanimoto_coeff('aluminum', 'Catalan')
        -4.0
        >>> cmp.tanimoto_coeff('ATCG', 'TAGC')
        -inf


def sim(self, src, tar, qval=<NUM_LIT:2>):

return super(self.__class__, self).sim(src, tar, qval, <NUM_LIT:1>, <NUM_LIT:1>)<EOL>

r"""Return the Jaccard similarity of two strings.

        Parameters
        ----------
        src : str
            Source string (or QGrams/Counter objects) for comparison
        tar : str
            Target string (or QGrams/Counter objects) for comparison
        qval : int
            The length of each q-gram; 0 for non-q-gram version

        Returns
        -------
        float
            Jaccard similarity

        Examples
        --------
        >>> cmp = Jaccard()
        >>> cmp.sim('cat', 'hat')
        0.3333333333333333
        >>> cmp.sim('Niall', 'Neil')
        0.2222222222222222
        >>> cmp.sim('aluminum', 'Catalan')
        0.0625
        >>> cmp.sim('ATCG', 'TAGC')
        0.0


def tanimoto(src, tar, qval=<NUM_LIT:2>):

return Jaccard().tanimoto_coeff(src, tar, qval)<EOL>

Return the Tanimoto coefficient of two strings.

    This is a wrapper for :py:meth:`Jaccard.tanimoto_coeff`.

    Parameters
    ----------
    src : str
        Source string (or QGrams/Counter objects) for comparison
    tar : str
        Target string (or QGrams/Counter objects) for comparison
    qval : int
        The length of each q-gram; 0 for non-q-gram version

    Returns
    -------
    float
        Tanimoto distance

    Examples
    --------
    >>> tanimoto('cat', 'hat')
    -1.5849625007211563
    >>> tanimoto('Niall', 'Neil')
    -2.1699250014423126
    >>> tanimoto('aluminum', 'Catalan')
    -4.0
    >>> tanimoto('ATCG', 'TAGC')
    -inf


def dist_sift4(src, tar, max_offset=<NUM_LIT:5>, max_distance=<NUM_LIT:0>):

return Sift4().dist(src, tar, max_offset, max_distance)<EOL>

Return the normalized "common" Sift4 distance between two terms.

    This is a wrapper for :py:meth:`Sift4.dist`.

    Parameters
    ----------
    src : str
        Source string for comparison
    tar : str
        Target string for comparison
    max_offset : int
        The number of characters to search for matching letters
    max_distance : int
        The distance at which to stop and exit

    Returns
    -------
    float
        The normalized Sift4 distance

    Examples
    --------
    >>> round(dist_sift4('cat', 'hat'), 12)
    0.333333333333
    >>> dist_sift4('Niall', 'Neil')
    0.4
    >>> dist_sift4('Colin', 'Cuilen')
    0.5
    >>> dist_sift4('ATCG', 'TAGC')
    0.5


def _synoname_word_approximation(<EOL>self, src_ln, tar_ln, src_fn='<STR_LIT>', tar_fn='<STR_LIT>', features=None<EOL>):

if features is None:<EOL><INDENT>features = {}<EOL><DEDENT>if '<STR_LIT>' not in features:<EOL><INDENT>features['<STR_LIT>'] = []<EOL><DEDENT>if '<STR_LIT>' not in features:<EOL><INDENT>features['<STR_LIT>'] = []<EOL><DEDENT>src_len_specials = len(features['<STR_LIT>'])<EOL>tar_len_specials = len(features['<STR_LIT>'])<EOL>if ('<STR_LIT>' in features and features['<STR_LIT>']) or (<EOL>'<STR_LIT>' in features and features['<STR_LIT>']<EOL>):<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>full_tar1 = '<STR_LIT:U+0020>'.join((tar_ln, tar_fn)).replace('<STR_LIT:->', '<STR_LIT:U+0020>').strip()<EOL>for s_pos, s_type in features['<STR_LIT>']:<EOL><INDENT>if s_type == '<STR_LIT:a>':<EOL><INDENT>full_tar1 = full_tar1[<EOL>: -(<EOL><NUM_LIT:1><EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>)<EOL>)<EOL>]<EOL><DEDENT>elif s_type == '<STR_LIT:b>':<EOL><INDENT>loc = (<EOL>full_tar1.find(<EOL>'<STR_LIT:U+0020>'<EOL>+ self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>+ '<STR_LIT:U+0020>'<EOL>)<EOL>+ <NUM_LIT:1><EOL>)<EOL>full_tar1 = (<EOL>full_tar1[:loc]<EOL>+ full_tar1[<EOL>loc<EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>) :<EOL>]<EOL>)<EOL><DEDENT>elif s_type == '<STR_LIT:c>':<EOL><INDENT>full_tar1 = full_tar1[<EOL><NUM_LIT:1><EOL>+ len(<EOL>self._stc._synoname_special_table[s_pos][  <EOL><NUM_LIT:1><EOL>]<EOL>) :<EOL>]<EOL><DEDENT><DEDENT>full_src1 = '<STR_LIT:U+0020>'.join((src_ln, src_fn)).replace('<STR_LIT:->', '<STR_LIT:U+0020>').strip()<EOL>for s_pos, s_type in features['<STR_LIT>']:<EOL><INDENT>if s_type == '<STR_LIT:a>':<EOL><INDENT>full_src1 = full_src1[<EOL>: -(<EOL><NUM_LIT:1><EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>)<EOL>)<EOL>]<EOL><DEDENT>elif s_type == '<STR_LIT:b>':<EOL><INDENT>loc = (<EOL>full_src1.find(<EOL>'<STR_LIT:U+0020>'<EOL>+ self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>+ '<STR_LIT:U+0020>'<EOL>)<EOL>+ <NUM_LIT:1><EOL>)<EOL>full_src1 = (<EOL>full_src1[:loc]<EOL>+ full_src1[<EOL>loc<EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>) :<EOL>]<EOL>)<EOL><DEDENT>elif s_type == '<STR_LIT:c>':<EOL><INDENT>full_src1 = full_src1[<EOL><NUM_LIT:1><EOL>+ len(<EOL>self._stc._synoname_special_table[s_pos][  <EOL><NUM_LIT:1><EOL>]<EOL>) :<EOL>]<EOL><DEDENT><DEDENT>full_tar2 = full_tar1<EOL>for s_pos, s_type in features['<STR_LIT>']:<EOL><INDENT>if s_type == '<STR_LIT:d>':<EOL><INDENT>full_tar2 = full_tar2[<EOL>len(<EOL>self._stc._synoname_special_table[s_pos][  <EOL><NUM_LIT:1><EOL>]<EOL>) :<EOL>]<EOL><DEDENT>elif (<EOL>s_type == '<STR_LIT:X>'<EOL>and self._stc._synoname_special_table[s_pos][<NUM_LIT:1>]  <EOL>in full_tar2<EOL>):<EOL><INDENT>loc = full_tar2.find(<EOL>'<STR_LIT:U+0020>'<EOL>+ self._stc._synoname_special_table[s_pos][<NUM_LIT:1>]  <EOL>)<EOL>full_tar2 = (<EOL>full_tar2[:loc]<EOL>+ full_tar2[<EOL>loc<EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>) :<EOL>]<EOL>)<EOL><DEDENT><DEDENT>full_src2 = full_src1<EOL>for s_pos, s_type in features['<STR_LIT>']:<EOL><INDENT>if s_type == '<STR_LIT:d>':<EOL><INDENT>full_src2 = full_src2[<EOL>len(<EOL>self._stc._synoname_special_table[s_pos][  <EOL><NUM_LIT:1><EOL>]<EOL>) :<EOL>]<EOL><DEDENT>elif (<EOL>s_type == '<STR_LIT:X>'<EOL>and self._stc._synoname_special_table[s_pos][<NUM_LIT:1>]  <EOL>in full_src2<EOL>):<EOL><INDENT>loc = full_src2.find(<EOL>'<STR_LIT:U+0020>'<EOL>+ self._stc._synoname_special_table[s_pos][<NUM_LIT:1>]  <EOL>)<EOL>full_src2 = (<EOL>full_src2[:loc]<EOL>+ full_src2[<EOL>loc<EOL>+ len(<EOL>self._stc._synoname_special_table[  <EOL>s_pos<EOL>][<NUM_LIT:1>]<EOL>) :<EOL>]<EOL>)<EOL><DEDENT><DEDENT>full_tar1 = self._synoname_strip_punct(full_tar1)<EOL>tar1_words = full_tar1.split()<EOL>tar1_num_words = len(tar1_words)<EOL>full_src1 = self._synoname_strip_punct(full_src1)<EOL>src1_words = full_src1.split()<EOL>src1_num_words = len(src1_words)<EOL>full_tar2 = self._synoname_strip_punct(full_tar2)<EOL>tar2_words = full_tar2.split()<EOL>tar2_num_words = len(tar2_words)<EOL>full_src2 = self._synoname_strip_punct(full_src2)<EOL>src2_words = full_src2.split()<EOL>src2_num_words = len(src2_words)<EOL>if (<EOL>src1_num_words < <NUM_LIT:2><EOL>and src_len_specials == <NUM_LIT:0><EOL>and src2_num_words < <NUM_LIT:2><EOL>and tar_len_specials == <NUM_LIT:0><EOL>):<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if (<EOL>tar1_num_words == <NUM_LIT:1><EOL>and src1_num_words == <NUM_LIT:1><EOL>and tar1_words[<NUM_LIT:0>] == src1_words[<NUM_LIT:0>]<EOL>):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>if tar1_num_words < <NUM_LIT:2> and tar_len_specials == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>last_found = False<EOL>for word in tar1_words:<EOL><INDENT>if src_ln.endswith(word) or word + '<STR_LIT:U+0020>' in src_ln:<EOL><INDENT>last_found = True<EOL><DEDENT><DEDENT>if not last_found:<EOL><INDENT>for word in src1_words:<EOL><INDENT>if tar_ln.endswith(word) or word + '<STR_LIT:U+0020>' in tar_ln:<EOL><INDENT>last_found = True<EOL><DEDENT><DEDENT><DEDENT>matches = <NUM_LIT:0><EOL>if last_found:<EOL><INDENT>for i, s_word in enumerate(src1_words):<EOL><INDENT>for j, t_word in enumerate(tar1_words):<EOL><INDENT>if s_word == t_word:<EOL><INDENT>src1_words[i] = '<STR_LIT:@>'<EOL>tar1_words[j] = '<STR_LIT:@>'<EOL>matches += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>w_ratio = matches / max(tar1_num_words, src1_num_words)<EOL>if matches > <NUM_LIT:1> or (<EOL>matches == <NUM_LIT:1><EOL>and src1_num_words == <NUM_LIT:1><EOL>and tar1_num_words == <NUM_LIT:1><EOL>and (tar_len_specials > <NUM_LIT:0> or src_len_specials > <NUM_LIT:0>)<EOL>):<EOL><INDENT>return w_ratio<EOL><DEDENT>if (<EOL>tar2_num_words == <NUM_LIT:1><EOL>and src2_num_words == <NUM_LIT:1><EOL>and tar2_words[<NUM_LIT:0>] == src2_words[<NUM_LIT:0>]<EOL>):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>if tar2_num_words < <NUM_LIT:2> and tar_len_specials == <NUM_LIT:0>:  <EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>last_found = False<EOL>for word in tar2_words:<EOL><INDENT>if src_ln.endswith(word) or word + '<STR_LIT:U+0020>' in src_ln:<EOL><INDENT>last_found = True<EOL><DEDENT><DEDENT>if not last_found:<EOL><INDENT>for word in src2_words:<EOL><INDENT>if tar_ln.endswith(word) or word + '<STR_LIT:U+0020>' in tar_ln:<EOL><INDENT>last_found = True<EOL><DEDENT><DEDENT><DEDENT>if not last_found:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>matches = <NUM_LIT:0><EOL>if last_found:<EOL><INDENT>for i, s_word in enumerate(src2_words):<EOL><INDENT>for j, t_word in enumerate(tar2_words):<EOL><INDENT>if s_word == t_word:<EOL><INDENT>src2_words[i] = '<STR_LIT:@>'<EOL>tar2_words[j] = '<STR_LIT:@>'<EOL>matches += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>w_ratio = matches / max(tar2_num_words, src2_num_words)<EOL>if matches > <NUM_LIT:1> or (<EOL>matches == <NUM_LIT:1><EOL>and src2_num_words == <NUM_LIT:1><EOL>and tar2_num_words == <NUM_LIT:1><EOL>and (tar_len_specials > <NUM_LIT:0> or src_len_specials > <NUM_LIT:0>)<EOL>):<EOL><INDENT>return w_ratio<EOL><DEDENT>return <NUM_LIT:0><EOL>

Return the Synoname word approximation score for two names.

        Parameters
        ----------
        src_ln : str
            Last name of the source
        tar_ln : str
            Last name of the target
        src_fn : str
            First name of the source (optional)
        tar_fn : str
            First name of the target (optional)
        features : dict
            A dict containing special features calculated using
            :py:class:`fingerprint.SynonameToolcode` (optional)

        Returns
        -------
        float
            The word approximation score

        Examples
        --------
        >>> pe = Synoname()
        >>> pe._synoname_word_approximation('Smith Waterman', 'Waterman',
        ... 'Tom Joe Bob', 'Tom Joe')
        0.6


if self.population() == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>random_precision = self.cond_pos_pop() / self.population()<EOL>return self.precision() / random_precision<EOL>

r"""Return gain in precision.

        The gain in precision is defined as:
        :math:`G(precision) = \frac{precision}{random~ precision}`

        Cf. https://en.wikipedia.org/wiki/Gain_(information_retrieval)

        Returns
        -------
        float
            The gain in precision of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.precision_gain()
        1.3142857142857143


if self.population() == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>random_accuracy = (<EOL>(self._tn + self._fp) * (self._tn + self._fn)<EOL>+ (self._fn + self._tp) * (self._fp + self._tp)<EOL>) / self.population() ** <NUM_LIT:2><EOL>return (self.accuracy() - random_accuracy) / (<NUM_LIT:1> - random_accuracy)<EOL>

r"""Return κ statistic.

        The κ statistic is defined as:
        :math:`\kappa = \frac{accuracy - random~ accuracy}
        {1 - random~ accuracy}`

        The κ statistic compares the performance of the classifier relative to
        the performance of a random classifier. :math:`\kappa` = 0 indicates
        performance identical to random. :math:`\kappa` = 1 indicates perfect
        predictive success. :math:`\kappa` = -1 indicates perfect predictive
        failure.

        Returns
        -------
        float
            The κ statistic of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.kappa_statistic()
        0.5344129554655871


return '<STR_LIT>'.format(<EOL>self._tp, self._tn, self._fp, self._fn<EOL>)<EOL>

Cast to str.

        Returns
        -------
        str
            A human-readable version of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> str(ct)
        'tp:120, tn:60, fp:20, fn:30'


if self._tp + self._fn == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return self._tp / (self._tp + self._fn)<EOL>

r"""Return recall.

        Recall is defined as :math:`\frac{tp}{tp + fn}`

        AKA sensitivity

        AKA true positive rate (TPR)

        Cf. https://en.wikipedia.org/wiki/Precision_and_recall

        Cf. https://en.wikipedia.org/wiki/Sensitivity_(test)

        Cf. https://en.wikipedia.org/wiki/Information_retrieval#Recall

        Returns
        -------
        float
            The recall of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.recall()
        0.8


return self.recall() + self.specificity() - <NUM_LIT:1><EOL>

Return informedness.

        Informedness is defined as :math:`sensitivity + specificity - 1`.

        AKA Youden's J statistic (:cite:`Youden:1950`)

        AKA DeltaP'

        Cf. https://en.wikipedia.org/wiki/Youden%27s_J_statistic

        Returns
        -------
        float
            The informedness of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.informedness()
        0.55


return qmean((self.precision(), self.recall()))<EOL>

r"""Return quadratic mean of precision & recall.

        The quadratic mean of precision and recall is defined as:
        :math:`\sqrt{\frac{precision^{2} + recall^{2}}{2}}`

        Cf. https://en.wikipedia.org/wiki/Quadratic_mean

        Returns
        -------
        float
            The quadratic mean of the confusion table's precision & recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_qmean()
        0.8290638930598233


return self.fbeta_score(<NUM_LIT>)<EOL>

Return :math:`F_{2}`.

        The :math:`F_{2}` score emphasizes recall over precision in comparison
        to the :math:`F_{1}` score

        Cf. https://en.wikipedia.org/wiki/F1_score

        Returns
        -------
        float
            The :math:`F_{2}` of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.f2_score()
        0.8108108108108109


if self._tn + self._fn == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return self._tn / (self._tn + self._fn)<EOL>

r"""Return negative predictive value (NPV).

        NPV is defined as :math:`\frac{tn}{tn + fn}`

        Cf. https://en.wikipedia.org/wiki/Negative_predictive_value

        Returns
        -------
        float
            The negative predictive value of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.npv()
        0.6666666666666666


return self._tp + self._tn<EOL>

Return correct population.

        Returns
        -------
        int
            The correct population of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.correct_pop()
        180


return hoelder_mean((self.precision(), self.recall()), exp)<EOL>

r"""Return Hölder (power/generalized) mean of precision & recall.

        The power mean of precision and recall is defined as:
        :math:`\frac{1}{2} \cdot
        \sqrt[exp]{precision^{exp} + recall^{exp}}`
        for :math:`exp \ne 0`, and the geometric mean for :math:`exp = 0`

        Cf. https://en.wikipedia.org/wiki/Generalized_mean

        Parameters
        ----------
        exp : float
            The exponent of the Hölder mean

        Returns
        -------
        float
            The Hölder mean for the given exponent of the confusion table's
            precision & recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_hoelder_mean()
        0.8290638930598233


return amean((self.precision(), self.recall()))<EOL>

r"""Return arithmetic mean of precision & recall.

        The arithmetic mean of precision and recall is defined as:
        :math:`\frac{precision \cdot recall}{2}`

        Cf. https://en.wikipedia.org/wiki/Arithmetic_mean

        Returns
        -------
        float
            The arithmetic mean of the confusion table's precision & recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_amean()
        0.8285714285714285


if isinstance(other, ConfusionTable):<EOL><INDENT>if id(self) == id(other):<EOL><INDENT>return True<EOL><DEDENT>if (<EOL>self._tp == other.true_pos()<EOL>and self._tn == other.true_neg()<EOL>and self._fp == other.false_pos()<EOL>and self._fn == other.false_neg()<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>elif isinstance(other, (tuple, list)):<EOL><INDENT>if (<EOL>self._tp == other[<NUM_LIT:0>]<EOL>and self._tn == other[<NUM_LIT:1>]<EOL>and self._fp == other[<NUM_LIT:2>]<EOL>and self._fn == other[<NUM_LIT:3>]<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>elif isinstance(other, dict):<EOL><INDENT>if (<EOL>self._tp == other['<STR_LIT>']<EOL>and self._tn == other['<STR_LIT>']<EOL>and self._fp == other['<STR_LIT>']<EOL>and self._fn == other['<STR_LIT>']<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Perform eqality (==) comparison.

        Compares a ConfusionTable to another ConfusionTable or its equivalent
        in the form of a tuple, list, or dict.

        Parameters
        ----------
        other : ConfusionTable
            Another ConfusionTable object to compare to

        Returns
        -------
        bool
            True if two ConfusionTables are the same object or all four of
            their attributes are equal

        Examples
        --------
        >>> ct1 = ConfusionTable(120, 60, 20, 30)
        >>> ct2 = ConfusionTable(120, 60, 20, 30)
        >>> ct3 = ConfusionTable(60, 30, 10, 15)

        >>> ct1 == ct2
        True
        >>> ct1 == ct3
        False

        >>> ct1 != ct2
        False
        >>> ct1 != ct3
        True


return heronian_mean((self.precision(), self.recall()))<EOL>

r"""Return Heronian mean of precision & recall.

        The Heronian mean of precision and recall is defined as:
        :math:`\frac{precision + \sqrt{precision \cdot recall} + recall}{3}`

        Cf. https://en.wikipedia.org/wiki/Heronian_mean

        Returns
        -------
        float
            The Heronian mean of the confusion table's precision & recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_heronian_mean()
        0.8284071761178939


def __init__(self, tp=<NUM_LIT:0>, tn=<NUM_LIT:0>, fp=<NUM_LIT:0>, fn=<NUM_LIT:0>):

if isinstance(tp, (tuple, list)):<EOL><INDENT>if len(tp) == <NUM_LIT:4>:<EOL><INDENT>self._tp = tp[<NUM_LIT:0>]<EOL>self._tn = tp[<NUM_LIT:1>]<EOL>self._fp = tp[<NUM_LIT:2>]<EOL>self._fn = tp[<NUM_LIT:3>]<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError(<EOL>'<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT>elif isinstance(tp, dict):<EOL><INDENT>if '<STR_LIT>' in tp:<EOL><INDENT>self._tp = tp['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in tp:<EOL><INDENT>self._tn = tp['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in tp:<EOL><INDENT>self._fp = tp['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in tp:<EOL><INDENT>self._fn = tp['<STR_LIT>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._tp = tp<EOL>self._tn = tn<EOL>self._fp = fp<EOL>self._fn = fn<EOL><DEDENT>

Initialize ConfusionTable.

        Parameters
        ----------
        tp : int or a tuple, list, or dict
            True positives; If a tuple or list is supplied, it must include 4
            values in the order [tp, tn, fp, fn]. If a dict is supplied, it
            must have 4 keys, namely 'tp', 'tn', 'fp', & 'fn'.
        tn : int
            True negatives
        fp : int
            False positives
        fn : int
            False negatives

        Raises
        ------
        AttributeError
            ConfusionTable requires a 4-tuple when being created from a tuple.

        Examples
        --------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct == ConfusionTable((120, 60, 20, 30))
        True
        >>> ct == ConfusionTable([120, 60, 20, 30])
        True
        >>> ct == ConfusionTable({'tp': 120, 'tn': 60, 'fp': 20, 'fn': 30})
        True


return self._tp + self._tn + self._fp + self._fn<EOL>

Return population, N.

        Returns
        -------
        int
            The population (N) of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.population()
        230


return self.pr_gmean()<EOL>

r"""Return G-measure.

        :math:`G`-measure is the geometric mean of precision and recall:
        :math:`\sqrt{precision \cdot recall}`

        This is identical to the Fowlkes–Mallows (FM) index for two
        clusters.

        Cf. https://en.wikipedia.org/wiki/F1_score#G-measure

        Cf. https://en.wikipedia.org/wiki/Fowlkes%E2%80%93Mallows_index

        Returns
        -------
        float
            The :math:`G`-measure of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.g_measure()
        0.828078671210825


return self.fbeta_score(<NUM_LIT:0.5>)<EOL>

Return :math:`F_{0.5}` score.

        The :math:`F_{0.5}` score emphasizes precision over recall in
        comparison to the :math:`F_{1}` score

        Cf. https://en.wikipedia.org/wiki/F1_score

        Returns
        -------
        float
            The :math:`F_{0.5}` score of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.fhalf_score()
        0.8450704225352114


return self.precision() + self.npv() - <NUM_LIT:1><EOL>

Return markedness.

        Markedness is defined as :math:`precision + npv - 1`

        Returns
        -------
        float
            The markedness of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.markedness()
        0.5238095238095237


if self._fp + self._tn == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return self._fp / (self._fp + self._tn)<EOL>

r"""Return fall-out.

        Fall-out is defined as :math:`\frac{fp}{fp + tn}`

        AKA false positive rate (FPR)

        Cf. https://en.wikipedia.org/wiki/Information_retrieval#Fall-out

        Returns
        -------
        float
            The fall-out of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.fallout()
        0.25


return ghmean((self.precision(), self.recall()))<EOL>

Return geometric-harmonic mean of precision & recall.

        Iterates between geometric & harmonic means until they converge to
        a single value (rounded to 12 digits)

        Cf. https://en.wikipedia.org/wiki/Geometric-harmonic_mean

        Returns
        -------
        float
            The geometric-harmonic mean of the confusion table's precision &
            recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_ghmean()
        0.8278323841238441


return self._tp, self._tn, self._fp, self._fn<EOL>

Cast to tuple.

        Returns
        -------
        tuple
            The confusion table as a 4-tuple (tp, tn, fp, fn)

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.to_tuple()
        (120, 60, 20, 30)


return <NUM_LIT:1> - self.fbeta_score(beta)<EOL>

r"""Return :math:`E`-score.

        This is Van Rijsbergen's effectiveness measure:
        :math:`E=1-F_{\beta}`.

        Cf. https://en.wikipedia.org/wiki/Information_retrieval#F-measure

        Parameters
        ----------
        beta : float
            The :math:`\beta` parameter in the above formula

        Returns
        -------
        float
            The :math:`E`-score of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.e_score()
        0.17241379310344818


if self.population() == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>random_accuracy = (self.cond_pos_pop() / self.population()) ** <NUM_LIT:2> + (<EOL>self.cond_neg_pop() / self.population()<EOL>) ** <NUM_LIT:2><EOL>return self.accuracy() / random_accuracy<EOL>

r"""Return gain in accuracy.

        The gain in accuracy is defined as:
        :math:`G(accuracy) = \frac{accuracy}{random~ accuracy}`

        Cf. https://en.wikipedia.org/wiki/Gain_(information_retrieval)

        Returns
        -------
        float
            The gain in accuracy of the confusion table

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.accuracy_gain()
        1.4325259515570934


return cmean((self.precision(), self.recall()))<EOL>

r"""Return contraharmonic mean of precision & recall.

        The contraharmonic mean is:
        :math:`\frac{precision^{2} + recall^{2}}{precision + recall}`

        Cf. https://en.wikipedia.org/wiki/Contraharmonic_mean

        Returns
        -------
        float
            The contraharmonic mean of the confusion table's precision & recall

        Example
        -------
        >>> ct = ConfusionTable(120, 60, 20, 30)
        >>> ct.pr_cmean()
        0.8295566502463055


if len(nums) == <NUM_LIT:1>:<EOL><INDENT>return nums[<NUM_LIT:0>]<EOL><DEDENT>if len(nums) > <NUM_LIT:2>:<EOL><INDENT>raise AttributeError('<STR_LIT>')<EOL><DEDENT>if nums[<NUM_LIT:0>] + nums[<NUM_LIT:1>] == <NUM_LIT:0> or nums[<NUM_LIT:0>] - nums[<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return (nums[<NUM_LIT:0>] - nums[<NUM_LIT:1>]) / (<EOL><NUM_LIT:2> * math.asin((nums[<NUM_LIT:0>] - nums[<NUM_LIT:1>]) / (nums[<NUM_LIT:0>] + nums[<NUM_LIT:1>]))<EOL>)<EOL>

r"""Return Seiffert's mean.

    Seiffert's mean of two numbers x and y is:
    :math:`\frac{x - y}{4 \cdot arctan \sqrt{\frac{x}{y}} - \pi}`

    It is defined in :cite:`Seiffert:1993`.

    Parameters
    ----------
    nums : list
        A series of numbers

    Returns
    -------
    float
        Sieffert's mean of nums

    Raises
    ------
    AttributeError
        seiffert_mean supports no more than two values

    Examples
    --------
    >>> seiffert_mean([1, 2])
    1.4712939827611637
    >>> seiffert_mean([1, 0])
    0.3183098861837907
    >>> seiffert_mean([2, 4])
    2.9425879655223275
    >>> seiffert_mean([2, 1000])
    336.84053300118825


return <NUM_LIT:0.5> * (max(nums) + min(nums))<EOL>

Return midrange.

    The midrange is the arithmetic mean of the maximum & minimum of a series.

    Cf. https://en.wikipedia.org/wiki/Midrange

    Parameters
    ----------
    nums : list
        A series of numbers

    Returns
    -------
    float
        The midrange of nums

    Examples
    --------
    >>> midrange([1, 2, 3])
    2.0
    >>> midrange([1, 2, 2, 3])
    2.0
    >>> midrange([1, 2, 1000, 3])
    500.5


if len(nums) == <NUM_LIT:1>:<EOL><INDENT>return nums[<NUM_LIT:0>]<EOL><DEDENT>if len(nums) > <NUM_LIT:2>:<EOL><INDENT>raise AttributeError('<STR_LIT>')<EOL><DEDENT>if nums[<NUM_LIT:0>] <= <NUM_LIT:0> or nums[<NUM_LIT:1>] <= <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>elif nums[<NUM_LIT:0>] == nums[<NUM_LIT:1>]:<EOL><INDENT>return nums[<NUM_LIT:0>]<EOL><DEDENT>return (<NUM_LIT:1> / math.e) * (nums[<NUM_LIT:0>] ** nums[<NUM_LIT:0>] / nums[<NUM_LIT:1>] ** nums[<NUM_LIT:1>]) ** (<EOL><NUM_LIT:1> / (nums[<NUM_LIT:0>] - nums[<NUM_LIT:1>])<EOL>)<EOL>

r"""Return identric (exponential) mean.

    The identric mean of two numbers x and y is:
    x if x = y
    otherwise :math:`\frac{1}{e} \sqrt[x-y]{\frac{x^x}{y^y}}`

    Cf. https://en.wikipedia.org/wiki/Identric_mean

    Parameters
    ----------
    nums : list
        A series of numbers

    Returns
    -------
    float
        The identric mean of nums

    Raises
    ------
    AttributeError
        imean supports no more than two values

    Examples
    --------
    >>> imean([1, 2])
    1.4715177646857693
    >>> imean([1, 0])
    nan
    >>> imean([2, 4])
    2.9430355293715387


nums = sorted(nums)<EOL>mag = len(nums)<EOL>if mag % <NUM_LIT:2>:<EOL><INDENT>mag = int((mag - <NUM_LIT:1>) / <NUM_LIT:2>)<EOL>return nums[mag]<EOL><DEDENT>mag = int(mag / <NUM_LIT:2>)<EOL>med = (nums[mag - <NUM_LIT:1>] + nums[mag]) / <NUM_LIT:2><EOL>return med if not med.is_integer() else int(med)<EOL>

Return median.

    With numbers sorted by value, the median is the middle value (if there is
    an odd number of values) or the arithmetic mean of the two middle values
    (if there is an even number of values).

    Cf. https://en.wikipedia.org/wiki/Median

    Parameters
    ----------
    nums : list
        A series of numbers

    Returns
    -------
    int or float
        The median of nums

    Examples
    --------
    >>> median([1, 2, 3])
    2
    >>> median([1, 2, 3, 4])
    2.5
    >>> median([1, 2, 2, 4])
    2


if exp == <NUM_LIT:0>:<EOL><INDENT>return gmean(nums)<EOL><DEDENT>return ((<NUM_LIT:1> / len(nums)) * sum(i ** exp for i in nums)) ** (<NUM_LIT:1> / exp)<EOL>

r"""Return Hölder (power/generalized) mean.

    The Hölder mean is defined as:
    :math:`\sqrt[p]{\frac{1}{|nums|} \cdot \sum\limits_i{x_i^p}}`
    for :math:`p \ne 0`, and the geometric mean for :math:`p = 0`

    Cf. https://en.wikipedia.org/wiki/Generalized_mean

    Parameters
    ----------
    nums : list
        A series of numbers
    exp : numeric
        The exponent of the Hölder mean

    Returns
    -------
    float
        The Hölder mean of nums for the given exponent

    Examples
    --------
    >>> hoelder_mean([1, 2, 3, 4])
    2.7386127875258306
    >>> hoelder_mean([1, 2])
    1.5811388300841898
    >>> hoelder_mean([0, 5, 1000])
    577.3574860228857


return (sum(i ** <NUM_LIT:2> for i in nums) / len(nums)) ** <NUM_LIT:0.5><EOL>

r"""Return quadratic mean.

    The quadratic mean of precision and recall is defined as:
    :math:`\sqrt{\sum\limits_{i} \frac{num_i^2}{|nums|}}`

    Cf. https://en.wikipedia.org/wiki/Quadratic_mean

    Parameters
    ----------
    nums : list
        A series of numbers

    Returns
    -------
    float
        The quadratic mean of nums

    Examples
    --------
    >>> qmean([1, 2, 3, 4])
    2.7386127875258306
    >>> qmean([1, 2])
    1.5811388300841898
    >>> qmean([0, 5, 1000])
    577.3574860228857


def mean_pairwise_similarity(<EOL>collection, metric=sim, mean_func=hmean, symmetric=False<EOL>):

if not callable(mean_func):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not callable(metric):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if hasattr(collection, '<STR_LIT>'):<EOL><INDENT>collection = collection.split()<EOL><DEDENT>if not hasattr(collection, '<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif len(collection) < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>collection = list(collection)<EOL>pairwise_values = []<EOL>for i in range(len(collection)):<EOL><INDENT>for j in range(i + <NUM_LIT:1>, len(collection)):<EOL><INDENT>pairwise_values.append(metric(collection[i], collection[j]))<EOL>if symmetric:<EOL><INDENT>pairwise_values.append(metric(collection[j], collection[i]))<EOL><DEDENT><DEDENT><DEDENT>return mean_func(pairwise_values)<EOL>

Calculate the mean pairwise similarity of a collection of strings.

    Takes the mean of the pairwise similarity between each member of a
    collection, optionally in both directions (for asymmetric similarity
    metrics.

    Parameters
    ----------
    collection : list
        A collection of terms or a string that can be split
    metric : function
        A similarity metric function
    mean_func : function
        A mean function that takes a list of values and returns a float
    symmetric : bool
        Set to True if all pairwise similarities should be calculated in both
        directions

    Returns
    -------
    float
        The mean pairwise similarity of a collection of strings

    Raises
    ------
    ValueError
        mean_func must be a function
    ValueError
        metric must be a function
    ValueError
        collection is neither a string nor iterable type
    ValueError
        collection has fewer than two members

    Examples
    --------
    >>> round(mean_pairwise_similarity(['Christopher', 'Kristof',
    ... 'Christobal']), 12)
    0.519801980198
    >>> round(mean_pairwise_similarity(['Niall', 'Neal', 'Neil']), 12)
    0.545454545455


if not callable(mean_func):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not callable(metric):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if hasattr(src_collection, '<STR_LIT>'):<EOL><INDENT>src_collection = src_collection.split()<EOL><DEDENT>if not hasattr(src_collection, '<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if hasattr(tar_collection, '<STR_LIT>'):<EOL><INDENT>tar_collection = tar_collection.split()<EOL><DEDENT>if not hasattr(tar_collection, '<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>src_collection = list(src_collection)<EOL>tar_collection = list(tar_collection)<EOL>pairwise_values = []<EOL>for src in src_collection:<EOL><INDENT>for tar in tar_collection:<EOL><INDENT>pairwise_values.append(metric(src, tar))<EOL>if symmetric:<EOL><INDENT>pairwise_values.append(metric(tar, src))<EOL><DEDENT><DEDENT><DEDENT>return (<EOL>max(pairwise_values),<EOL>min(pairwise_values),<EOL>mean_func(pairwise_values),<EOL>std(pairwise_values, mean_func, <NUM_LIT:0>),<EOL>)<EOL>

Calculate the pairwise similarity statistics a collection of strings.

    Calculate pairwise similarities among members of two collections,
    returning the maximum, minimum, mean (according to a supplied function,
    arithmetic mean, by default), and (population) standard deviation
    of those similarities.

    Parameters
    ----------
    src_collection : list
        A collection of terms or a string that can be split
    tar_collection : list
        A collection of terms or a string that can be split
    metric : function
        A similarity metric function
    mean_func : function
        A mean function that takes a list of values and returns a float
    symmetric : bool
        Set to True if all pairwise similarities should be calculated in both
        directions

    Returns
    -------
    tuple
        The max, min, mean, and standard deviation of similarities

    Raises
    ------
    ValueError
        mean_func must be a function
    ValueError
        metric must be a function
    ValueError
        src_collection is neither a string nor iterable
    ValueError
        tar_collection is neither a string nor iterable

    Example
    -------
    >>> tuple(round(_, 12) for _ in pairwise_similarity_statistics(
    ... ['Christopher', 'Kristof', 'Christobal'], ['Niall', 'Neal', 'Neil']))
    (0.2, 0.0, 0.118614718615, 0.075070477184)


def count_fingerprint(word, n_bits=<NUM_LIT:16>, most_common=MOST_COMMON_LETTERS_CG):

return Count().fingerprint(word, n_bits, most_common)<EOL>

Return the count fingerprint.

    This is a wrapper for :py:meth:`Count.fingerprint`.

    Parameters
    ----------
    word : str
        The word to fingerprint
    n_bits : int
        Number of bits in the fingerprint returned
    most_common : list
        The most common tokens in the target language, ordered by frequency

    Returns
    -------
    int
        The count fingerprint

    Examples
    --------
    >>> bin(count_fingerprint('hat'))
    '0b1010000000001'
    >>> bin(count_fingerprint('niall'))
    '0b10001010000'
    >>> bin(count_fingerprint('colin'))
    '0b101010000'
    >>> bin(count_fingerprint('atcg'))
    '0b1010000000000'
    >>> bin(count_fingerprint('entreatment'))
    '0b1111010000100000'


return String().fingerprint(phrase, joiner)<EOL>

Return string fingerprint.

    This is a wrapper for :py:meth:`String.fingerprint`.

    Parameters
    ----------
    phrase : str
        The string from which to calculate the fingerprint
    joiner : str
        The string that will be placed between each word

    Returns
    -------
    str
        The fingerprint of the phrase

    Example
    -------
    >>> str_fingerprint('The quick brown fox jumped over the lazy dog.')
    'brown dog fox jumped lazy over quick the'


def occurrence_halved_fingerprint(<EOL>word, n_bits=<NUM_LIT:16>, most_common=MOST_COMMON_LETTERS_CG<EOL>):

return OccurrenceHalved().fingerprint(word, n_bits, most_common)<EOL>

Return the occurrence halved fingerprint.

    This is a wrapper for :py:meth:`OccurrenceHalved.fingerprint`.

    Parameters
    ----------
    word : str
        The word to fingerprint
    n_bits : int
        Number of bits in the fingerprint returned
    most_common : list
        The most common tokens in the target language, ordered by frequency

    Returns
    -------
    int
        The occurrence halved fingerprint

    Examples
    --------
    >>> bin(occurrence_halved_fingerprint('hat'))
    '0b1010000000010'
    >>> bin(occurrence_halved_fingerprint('niall'))
    '0b10010100000'
    >>> bin(occurrence_halved_fingerprint('colin'))
    '0b1001010000'
    >>> bin(occurrence_halved_fingerprint('atcg'))
    '0b10100000000000'
    >>> bin(occurrence_halved_fingerprint('entreatment'))
    '0b1111010000110000'


def fingerprint(self, word, n_bits=<NUM_LIT:16>, most_common=MOST_COMMON_LETTERS_CG):

if n_bits % <NUM_LIT:2>:<EOL><INDENT>n_bits += <NUM_LIT:1><EOL><DEDENT>w_len = len(word) // <NUM_LIT:2><EOL>w_1 = set(word[:w_len])<EOL>w_2 = set(word[w_len:])<EOL>fingerprint = <NUM_LIT:0><EOL>for letter in most_common:<EOL><INDENT>if n_bits:<EOL><INDENT>fingerprint <<= <NUM_LIT:1><EOL>if letter in w_1:<EOL><INDENT>fingerprint += <NUM_LIT:1><EOL><DEDENT>fingerprint <<= <NUM_LIT:1><EOL>if letter in w_2:<EOL><INDENT>fingerprint += <NUM_LIT:1><EOL><DEDENT>n_bits -= <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if n_bits > <NUM_LIT:0>:<EOL><INDENT>fingerprint <<= n_bits<EOL><DEDENT>return fingerprint<EOL>

Return the occurrence halved fingerprint.

        Based on the occurrence halved fingerprint from :cite:`Cislak:2017`.

        Parameters
        ----------
        word : str
            The word to fingerprint
        n_bits : int
            Number of bits in the fingerprint returned
        most_common : list
            The most common tokens in the target language, ordered by frequency

        Returns
        -------
        int
            The occurrence halved fingerprint

        Examples
        --------
        >>> ohf = OccurrenceHalved()
        >>> bin(ohf.fingerprint('hat'))
        '0b1010000000010'
        >>> bin(ohf.fingerprint('niall'))
        '0b10010100000'
        >>> bin(ohf.fingerprint('colin'))
        '0b1001010000'
        >>> bin(ohf.fingerprint('atcg'))
        '0b10100000000000'
        >>> bin(ohf.fingerprint('entreatment'))
        '0b1111010000110000'


phonetic = '<STR_LIT>'<EOL>for word in phrase.split():<EOL><INDENT>word = phonetic_algorithm(word, *args, **kwargs)<EOL>if not isinstance(word, text_type) and hasattr(word, '<STR_LIT>'):<EOL><INDENT>word = word[<NUM_LIT:0>]<EOL><DEDENT>phonetic += word + joiner<EOL><DEDENT>phonetic = phonetic[: -len(joiner)]<EOL>return super(self.__class__, self).fingerprint(phonetic)<EOL>

Return the phonetic fingerprint of a phrase.

        Parameters
        ----------
        phrase : str
            The string from which to calculate the phonetic fingerprint
        phonetic_algorithm : function
            A phonetic algorithm that takes a string and returns a string
            (presumably a phonetic representation of the original string). By
            default, this function uses :py:func:`.double_metaphone`.
        joiner : str
            The string that will be placed between each word
        *args
            Variable length argument list
        **kwargs
            Arbitrary keyword arguments

        Returns
        -------
        str
            The phonetic fingerprint of the phrase

        Examples
        --------
        >>> pf = Phonetic()
        >>> pf.fingerprint('The quick brown fox jumped over the lazy dog.')
        '0 afr fks jmpt kk ls prn tk'
        >>> from abydos.phonetic import soundex
        >>> pf.fingerprint('The quick brown fox jumped over the lazy dog.',
        ... phonetic_algorithm=soundex)
        'b650 d200 f200 j513 l200 o160 q200 t000'


def phonetic_fingerprint(<EOL>phrase, phonetic_algorithm=double_metaphone, joiner='<STR_LIT:U+0020>', *args, **kwargs<EOL>):

return Phonetic().fingerprint(<EOL>phrase, phonetic_algorithm, joiner, *args, **kwargs<EOL>)<EOL>

Return the phonetic fingerprint of a phrase.

    This is a wrapper for :py:meth:`Phonetic.fingerprint`.

    Parameters
    ----------
    phrase : str
        The string from which to calculate the phonetic fingerprint
    phonetic_algorithm : function
        A phonetic algorithm that takes a string and returns a string
        (presumably a phonetic representation of the original string). By
        default, this function uses :py:func:`.double_metaphone`.
    joiner : str
        The string that will be placed between each word
    *args
        Variable length argument list
    **kwargs
        Arbitrary keyword arguments

    Returns
    -------
    str
        The phonetic fingerprint of the phrase

    Examples
    --------
    >>> phonetic_fingerprint('The quick brown fox jumped over the lazy dog.')
    '0 afr fks jmpt kk ls prn tk'
    >>> from abydos.phonetic import soundex
    >>> phonetic_fingerprint('The quick brown fox jumped over the lazy dog.',
    ... phonetic_algorithm=soundex)
    'b650 d200 f200 j513 l200 o160 q200 t000'


def qgram_fingerprint(phrase, qval=<NUM_LIT:2>, start_stop='<STR_LIT>', joiner='<STR_LIT>'):

return QGram().fingerprint(phrase, qval, start_stop, joiner)<EOL>

Return Q-Gram fingerprint.

    This is a wrapper for :py:meth:`QGram.fingerprint`.

    Parameters
    ----------
    phrase : str
        The string from which to calculate the q-gram fingerprint
    qval : int
        The length of each q-gram (by default 2)
    start_stop : str
        The start & stop symbol(s) to concatenate on either end of the phrase,
        as defined in :py:class:`tokenizer.QGrams`
    joiner : str
        The string that will be placed between each word

    Returns
    -------
    str
        The q-gram fingerprint of the phrase

    Examples
    --------
    >>> qgram_fingerprint('The quick brown fox jumped over the lazy dog.')
    'azbrckdoedeleqerfoheicjukblampnfogovowoxpequrortthuiumvewnxjydzy'
    >>> qgram_fingerprint('Christopher')
    'cherhehrisopphristto'
    >>> qgram_fingerprint('Niall')
    'aliallni'


def fingerprint(self, phrase, qval=<NUM_LIT:2>, start_stop='<STR_LIT>', joiner='<STR_LIT>'):

phrase = unicode_normalize('<STR_LIT>', text_type(phrase.strip().lower()))<EOL>phrase = '<STR_LIT>'.join(c for c in phrase if c.isalnum())<EOL>phrase = QGrams(phrase, qval, start_stop)<EOL>phrase = joiner.join(sorted(phrase))<EOL>return phrase<EOL>

Return Q-Gram fingerprint.

        Parameters
        ----------
        phrase : str
            The string from which to calculate the q-gram fingerprint
        qval : int
            The length of each q-gram (by default 2)
        start_stop : str
            The start & stop symbol(s) to concatenate on either end of the
            phrase, as defined in :py:class:`tokenizer.QGrams`
        joiner : str
            The string that will be placed between each word

        Returns
        -------
        str
            The q-gram fingerprint of the phrase

        Examples
        --------
        >>> qf = QGram()
        >>> qf.fingerprint('The quick brown fox jumped over the lazy dog.')
        'azbrckdoedeleqerfoheicjukblampnfogovowoxpequrortthuiumvewnxjydzy'
        >>> qf.fingerprint('Christopher')
        'cherhehrisopphristto'
        >>> qf.fingerprint('Niall')
        'aliallni'


word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = '<STR_LIT>'.join(c for c in word if c in self._letters)<EOL>start = word[<NUM_LIT:0>:<NUM_LIT:1>]<EOL>consonant_part = '<STR_LIT>'<EOL>vowel_part = '<STR_LIT>'<EOL>for char in word[<NUM_LIT:1>:]:<EOL><INDENT>if char != start:<EOL><INDENT>if char in self._vowels:<EOL><INDENT>if char not in vowel_part:<EOL><INDENT>vowel_part += char<EOL><DEDENT><DEDENT>elif char not in consonant_part:<EOL><INDENT>consonant_part += char<EOL><DEDENT><DEDENT><DEDENT>return start + consonant_part + vowel_part<EOL>

Return the skeleton key.

        Parameters
        ----------
        word : str
            The word to transform into its skeleton key

        Returns
        -------
        str
            The skeleton key

        Examples
        --------
        >>> sk = SkeletonKey()
        >>> sk.fingerprint('The quick brown fox jumped over the lazy dog.')
        'THQCKBRWNFXJMPDVLZYGEUIOA'
        >>> sk.fingerprint('Christopher')
        'CHRSTPIOE'
        >>> sk.fingerprint('Niall')
        'NLIA'


def synoname_toolcode(lname, fname='<STR_LIT>', qual='<STR_LIT>', normalize=<NUM_LIT:0>):

return SynonameToolcode().fingerprint(lname, fname, qual, normalize)<EOL>

Build the Synoname toolcode.

    This is a wrapper for :py:meth:`SynonameToolcode.fingerprint`.

    Parameters
    ----------
    lname : str
        Last name
    fname : str
        First name (can be blank)
    qual : str
        Qualifier
    normalize : int
        Normalization mode (0, 1, or 2)

    Returns
    -------
    tuple
        The transformed names and the synoname toolcode

    Examples
    --------
    >>> synoname_toolcode('hat')
    ('hat', '', '0000000003$$h')
    >>> synoname_toolcode('niall')
    ('niall', '', '0000000005$$n')
    >>> synoname_toolcode('colin')
    ('colin', '', '0000000005$$c')
    >>> synoname_toolcode('atcg')
    ('atcg', '', '0000000004$$a')
    >>> synoname_toolcode('entreatment')
    ('entreatment', '', '0000000011$$e')

    >>> synoname_toolcode('Ste.-Marie', 'Count John II', normalize=2)
    ('ste.-marie ii', 'count john', '0200491310$015b049a127c$smcji')
    >>> synoname_toolcode('Michelangelo IV', '', 'Workshop of')
    ('michelangelo iv', '', '3000550015$055b$mi')


return _super_corpus_file(name, corpora_dir)<EOL>

Return the path to a corpus file.

    Parameters
    ----------
    name : str
        Corpus file
    corpora_dir : str
        The directory containing the corpora

    Returns
    -------
    str
        The path to the corpus file


<EOL>score_cutoffs = (<NUM_LIT:0>, <NUM_LIT:10>, <NUM_LIT>, <NUM_LIT:50>, <NUM_LIT:100>)<EOL>for i in range(len(score_cutoffs)):<EOL><INDENT>if score <= score_cutoffs[i]:<EOL><INDENT>return BADGE_COLORS[i]<EOL><DEDENT><DEDENT>return BADGE_COLORS[-<NUM_LIT:1>]<EOL>

Return pydocstyle badge color.

    Parameters
    ----------
    score : float
        A pydocstyle score

    Returns
    -------
    str
        Badge color


<EOL>score_cutoffs = (<NUM_LIT:10>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:5>)<EOL>for i in range(len(score_cutoffs)):<EOL><INDENT>if score >= score_cutoffs[i]:<EOL><INDENT>return BADGE_COLORS[i]<EOL><DEDENT><DEDENT>return BADGE_COLORS[-<NUM_LIT:1>]<EOL>

Return Pylint badge color.

    Parameters
    ----------
    score : float
        A Pylint score

    Returns
    -------
    str
        Badge color