Spaces:
Runtime error
Runtime error
File size: 765 Bytes
050de65 21c0ae2 050de65 21c0ae2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# -*- coding: utf-8 -*-
"""autocorrectreal.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1aH5mYp1dxyn55XMjtVUllBvg37nqGVir
"""
import re
w = []
with open('Autocorrect/words.txt', 'r') as f:
file_name_data = f.read()
file_name_data = file_name_data.lower()
w = re.findall('\w+', file_name_data)
from nltk.metrics.distance import edit_distance
def edit(input_sentence):
sentence = input_sentence.split()
for i in sentence:
if i.lower() in w:
continue
else:
distances = ((edit_distance(i,word),word)for word in w)
closest = min(distances)
sentence[sentence.index(i)] = closest[1]
output_sentence = ' '.join(sentence)
return output_sentence |