(query, title)
return (False, False)
return (match, update)
return (match, update)
return ( match update )
def title_correct(query, title):
    """ return (match, update) """
    title = title.replace('[PDF]', '')
    q = ''.join([t for t in query if t in string.letters]).lower()
    now = ''.join([t for t in title if t in string.letters]).lower()
    ed_thres = min(len(query), len(title)) / 5
    ERROR_RATIO = 0.6
    if levenshtein(q, now) < ed_thres:
        return (True, True)
    for k in range(min([int(len(query) * ERROR_RATIO), 30]), len(query)):
        if levenshtein(q[:k], now) < ed_thres:
            return (True, False)
    for k in range(int(len(title) * ERROR_RATIO), len(title)):
        if levenshtein(now[:k], q) < ed_thres:
            return (True, False)
    return (False, False)
def title_correct ( query , title ) : title = title . replace ( '[PDF]' , '' ) q = '' . join ( [ t for t in query if t in string . letters ] ) . lower ( ) now = '' . join ( [ t for t in title if t in string . letters ] ) . lower ( ) ed_thres = min ( len ( query ) , len ( title ) ) / 5 ERROR_RATIO = 0.6 if levenshtein ( q , now ) < ed_thres : return ( True , True ) for k in range ( min ( [ int ( len ( query ) * ERROR_RATIO ) , 30 ] ) , len ( query ) ) : if levenshtein ( q [ : k ] , now ) < ed_thres : return ( True , False ) for k in range ( int ( len ( title ) * ERROR_RATIO ) , len ( title ) ) : if levenshtein ( now [ : k ] , q ) < ed_thres : return ( True , False ) return ( False , False )