<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import numpy as np <EOL> def cosine_similarity ( vec1 , vec2 ) : <EOL> """<STR_LIT>""" <EOL> return np . dot ( vec1 , vec2 ) / ( np . linalg . norm ( vec1 ) * np . linalg . norm ( vec2 ) ) <EOL> def levenshtein_distance ( str1 , str2 ) : <EOL> """<STR_LIT>""" <EOL> if len ( str1 ) > len ( str2 ) : <EOL> str1 , str2 = str2 , str1 <EOL> distances = range ( len ( str1 ) + <NUM_LIT:1> ) <EOL> for index2 , char2 in enumerate ( str2 ) : <EOL> new_distances = [ index2 + <NUM_LIT:1> ] <EOL> for index1 , char1 in enumerate ( str1 ) : <EOL> if char1 == char2 : <EOL> new_distances . append ( distances [ index1 ] ) <EOL> else : <EOL> new_distances . append ( <NUM_LIT:1> + min ( ( distances [ index1 ] , distances [ index1 + <NUM_LIT:1> ] , new_distances [ - <NUM_LIT:1> ] ) ) ) <EOL> distances = new_distances <EOL> return distances [ - <NUM_LIT:1> ] </s>
