def _similarity_distance(s1, s2, ignore):
    '''
    compute similarity with distance measurement
    '''
    g = 0.0
    try:
        g_ = cosine(_flat_sum_array(_get_wv(s1, ignore)), _flat_sum_array(_get_wv(s2, ignore)))
        if is_digit(g_): g = g_
    except: pass

    u = _nearby_levenshtein_distance(s1, s2)
    logging.debug("g: %s, u: %s" % (g, u))
    if u >= 0.99:
        r = 1.0
    elif u > 0.9:
        r = _similarity_smooth(g, 0.05, u, 0.05)
    elif u > 0.8:
        r = _similarity_smooth(g, 0.1, u, 0.2)
    elif u > 0.4:
        r = _similarity_smooth(g, 0.2, u, 0.15)
    elif u > 0.2:
        r = _similarity_smooth(g, 0.3, u, 0.1)
    else:
        r = _similarity_smooth(g, 0.4, u, 0)

    if r < 0: r = abs(r)
    r = min(r, 1.0)
    return float("%.3f" % r)
def _similarity_distance ( s1 , s2 , ignore ) : g = 0.0 try : g_ = cosine ( _flat_sum_array ( _get_wv ( s1 , ignore ) ) , _flat_sum_array ( _get_wv ( s2 , ignore ) ) ) if is_digit ( g_ ) : g = g_ except : pass u = _nearby_levenshtein_distance ( s1 , s2 ) logging . debug ( "g: %s, u: %s" % ( g , u ) ) if u >= 0.99 : r = 1.0 elif u > 0.9 : r = _similarity_smooth ( g , 0.05 , u , 0.05 ) elif u > 0.8 : r = _similarity_smooth ( g , 0.1 , u , 0.2 ) elif u > 0.4 : r = _similarity_smooth ( g , 0.2 , u , 0.15 ) elif u > 0.2 : r = _similarity_smooth ( g , 0.3 , u , 0.1 ) else : r = _similarity_smooth ( g , 0.4 , u , 0 ) if r < 0 : r = abs ( r ) r = min ( r , 1.0 ) return float ( "%.3f" % r )
compute similarity with distance measurement