Skip to content

Instantly share code, notes, and snippets.

@thisisarjuns
Created August 1, 2024 11:55
Show Gist options
  • Save thisisarjuns/d5cfa39828cd93897acf33157dce37cf to your computer and use it in GitHub Desktop.
Save thisisarjuns/d5cfa39828cd93897acf33157dce37cf to your computer and use it in GitHub Desktop.
lv distance similarity
import rapidfuzz
def get_confidence_lv(init_data_name: str, document_name: str) -> float:
edit_distance = rapidfuzz.distance.Levenshtein.distance(init_data_name, document_name)
similarity = 1 - (edit_distance / max(len(init_data_name), len(document_name)))
return round(similarity, 2)
input = [
("Arjun", "Arjun" ),
("Arjun", "Arun" ),
("Arjun Sunil", "Arjun Sunl" ),
("Arjun Sunil", "Arjun Sunil Mar" ),
("Arjun Sunil", "Arjun Sunil Marc" ),
("Arjun Sunil", "Arjun Sunil Marce" ),
("Arjun Sunil", "Arjun Sunil Marcel" ),
("Arjun Sunil", "Arjun Sunil Marcel O" ),
("Arjun Sunil", "Arjun Sunil Marcel Oc" ),
]
for i in input:
print(i[0], i[1], "-->", get_confidence_lv(i[0], i[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment