def sim(self, src, tar):
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