Get Similarity Score

So, let's imagine that you want to simply compare two words, without running get_similar on a wordlist. There is a method that is far more lightweight than get_similar for this purpose, called get_similarity_score. It takes two words as arguments and returns a float between 0 and 1, where 0 means that the words are completely different and 1 means that the words are exactly the same. The score is calculated using the Levenshtein distance algorithm. Here's an example:

from lesp import Proofreader

proofreader = Proofreader()

print(proofreader.get_similarity_score("hello", "helo")) # 0.8
print(proofreader.get_similarity_score("hello", "hello")) # 1.0
print(proofreader.get_similarity_score("hello", "world")) # 0.0

This usually doesn't take more than a few milliseconds to run, so it's a good option if you want to do this job quickly. get_similar actually uses this method itself, but due to the fact that it has to compare the word with every word in the wordlist, it takes a lot more time to run (still not that much, though).

Last updated