I am working on correcting Turkish words by using Levensthein distance. First of all I detect wrong written words and compare them with a list that contains all Turkish words. The list contains about 1.300.000 words. I use Levensthein distance to compare word with the words in the list. Here is the part of my code.
index_to_track_document_order = 1
log_text = ''
main_directory = "C:\\words.txt"
f= codecs.open(main_directory,mode="rb",encoding="utf-8")
f=f.readlines()
similarity = 0
text_to_find = 'aktarıları'
best_fit_word = ''
for line in f:
word = word_tokenize( line, language= 'turkish')[0]
root = word_tokenize( line, language= 'turkish')[1]
new_similarity = textdistance.levenshtein.normalized_similarity(text_to_find , word) * 100
if new_similarity > similarity:
similarity = new_similarity
best_fit_word = word
if(similarity > 90):
print(best_fit_word, str(similarity))
As I mentioned, word.txt contains more than a million records and so that my code takes more than 5 minutes to complete. How I can optimize the code so that it can complete in a shorter time. Thank you.