def sim(self, src, tar, long_strings=False):
def _in_range(char):<EOL><INDENT>"""<STR_LIT>"""<EOL>return <NUM_LIT> > ord(char) > <NUM_LIT:0><EOL><DEDENT>ying = src.strip().upper()<EOL>yang = tar.strip().upper()<EOL>if ying == yang:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>if not ying or not yang:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>adjwt = defaultdict(int)<EOL>for i in self._sp_mx:<EOL><INDENT>adjwt[(i[<NUM_LIT:0>], i[<NUM_LIT:1>])] = <NUM_LIT:3><EOL>adjwt[(i[<NUM_LIT:1>], i[<NUM_LIT:0>])] = <NUM_LIT:3><EOL><DEDENT>if len(ying) > len(yang):<EOL><INDENT>search_range = len(ying)<EOL>minv = len(yang)<EOL><DEDENT>else:<EOL><INDENT>search_range = len(yang)<EOL>minv = len(ying)<EOL><DEDENT>ying_flag = [<NUM_LIT:0>] * search_range<EOL>yang_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 = len(yang) - <NUM_LIT:1><EOL>for i in range(len(ying)):<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 (yang_flag[j] == <NUM_LIT:0>) and (yang[j] == ying[i]):<EOL><INDENT>yang_flag[j] = <NUM_LIT:1><EOL>ying_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(len(ying)):<EOL><INDENT>if ying_flag[i] != <NUM_LIT:0>:<EOL><INDENT>j = <NUM_LIT:0><EOL>for j in range(k, len(yang)):  <EOL><INDENT>if yang_flag[j] != <NUM_LIT:0>:<EOL><INDENT>k = j + <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>if ying[i] != yang[j]:<EOL><INDENT>n_trans += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>n_trans //= <NUM_LIT:2><EOL>n_simi = <NUM_LIT:0><EOL>if minv > num_com:<EOL><INDENT>for i in range(len(ying)):<EOL><INDENT>if ying_flag[i] == <NUM_LIT:0> and _in_range(ying[i]):<EOL><INDENT>for j in range(len(yang)):<EOL><INDENT>if yang_flag[j] == <NUM_LIT:0> and _in_range(yang[j]):<EOL><INDENT>if (ying[i], yang[j]) in adjwt:<EOL><INDENT>n_simi += adjwt[(ying[i], yang[j])]<EOL>yang_flag[j] = <NUM_LIT:2><EOL>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>num_sim = n_simi / <NUM_LIT> + num_com<EOL>weight = (<EOL>num_sim / len(ying)<EOL>+ num_sim / len(yang)<EOL>+ (num_com - n_trans) / num_com<EOL>)<EOL>weight /= <NUM_LIT><EOL>if weight > <NUM_LIT>:<EOL><INDENT>j = <NUM_LIT:4> if (minv >= <NUM_LIT:4>) else minv<EOL>i = <NUM_LIT:0><EOL>while (i < j) and (ying[i] == yang[i]) and (not ying[i].isdigit()):<EOL><INDENT>i += <NUM_LIT:1><EOL><DEDENT>if i:<EOL><INDENT>weight += i * <NUM_LIT:0.1> * (<NUM_LIT:1.0> - weight)<EOL><DEDENT>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>if not ying[<NUM_LIT:0>].isdigit():<EOL><INDENT>weight += (<NUM_LIT:1.0> - weight) * (<EOL>(num_com - i - <NUM_LIT:1>) / (len(ying) + len(yang) - i * <NUM_LIT:2> + <NUM_LIT:2>)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return weight<EOL>
Return the strcmp95 similarity of two strings.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        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.

        Returns
        -------
        float
            Strcmp95 similarity

        Examples
        --------
        >>> cmp = Strcmp95()
        >>> cmp.sim('cat', 'hat')
        0.7777777777777777
        >>> cmp.sim('Niall', 'Neil')
        0.8454999999999999
        >>> cmp.sim('aluminum', 'Catalan')
        0.6547619047619048
        >>> cmp.sim('ATCG', 'TAGC')
        0.8333333333333334