简体   繁体   中英

Creating a spell checking function in python (Check misspellings)

I have a file with a few lines of English sentences. Some of these words are misspelled and I am looking to construct a function that:

  1. Detects spelling mistakes and displays them in a list.
  2. After finding the wrong words, write them correctly and return them to the output.

for example input: x = "This is the lnguage of Pithon " Result: = Wrong words: ['lnguage','pithon']

You can use the GingerIt API with python library like this

IN TERMINAL

pip install gingerit

FOR CODE

from gingerit.gingerit import GingerIt
text = input("Enter text to be corrected")
result = GingerIt().parse(text)
corrections = result['corrections']
correctText = result['result']

print("Correct Text:",correctText)
print()
print("CORRECTIONS")
for d in corrections:
  print("________________")  
  print("Previous:",d['text'])  
  print("Correction:",d['correct'])   
  print("Definiton:",d['definition'])
 

Test it here

https://repl.it/@SiddharthAgraw2/StackOverFlowQueries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM