Programmer_nltk
Programmer_nltk

Reputation: 915

Spelling correction in sentences

I use https://norvig.com/spell-correct.html to find spelling errors

How to find and replace misspelt words in a sentence.

Efforts so far:

sentences = "This sntence cntins errors. This sentence has to be corrcted."
list_string = sentences.split(' ') 
for word in list_string:
    print(correction(word))

Output:

this
sentence
contains
error
this
sentence
has
to
be
corrected.

Expected output:

This <<sntence>> sentence <<cntins>> contains errors. This sentence has to be <<corrcted>> corrected.

Able to achieve it using https://stackoverflow.com/questions/48123861/spelling-mistakes-pyenchant. How to find and replace misspelt words into original text while retaining misspelt words within << >>

Upvotes: 0

Views: 1289

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

Try str.join to a generator:

print(' '.join('<<'+i+'>>'+' %s'%correction(i) if correction(i) != i else i for i in sentences.split()))

Upvotes: 1

Related Questions