Created
August 1, 2024 11:55
-
-
Save thisisarjuns/d5cfa39828cd93897acf33157dce37cf to your computer and use it in GitHub Desktop.
lv distance similarity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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