How to fix text and automatically return the corrected text using PyEnchant

import enchant import wx from enchant.checker import SpellChecker from enchant.checker.wxSpellCheckerDialog import wxSpellCheckerDialog from enchant.checker.CmdLineChecker import CmdLineChecker a = "Ceci est un text avec beuacuop d'ereurs et pas snychro" chkr = enchant.checker.SpellChecker("fr_FR") chkr.set_text(a) cmdln = CmdLineChecker() cmdln.set_checker(chkr) b = cmdln.run() c = chkr.get_text() # returns corrected text print c 

How do I get c to return the corrected text without using 0 manually from cmdlinechecker ?

The program should go through a line containing unadjusted text, correct it and save it in a variable for export to the MySQL database.

+5
source share
3 answers
 a = "Ceci est un text avec beuacuop d'ereurs et pas snychro" chkr = enchant.checker.SpellChecker("fr_FR") chkr.set_text(a) for err in chkr: print err.word sug = err.suggest()[0] err.replace(sug) c = chkr.get_text()#returns corrected text print c 

It works just like I was going to make it work. Add filters and corrects all small texts that automatically allow you to search by keywords, etc.

Took me in 13 hours to understand :(

+6
source

I'm actually not familiar with python and the libraries you describe, but the general approach to the correct text uses a dictionary. In other words, you check if the word is included in the French dictionary (or a list of French words), and if so, the word is true, otherwise use the word from the dictionary.

+1
source

For my purposes, the level of automation that you provided here was too risky - the words included the correct names, so I built a little more verification on the system.

I add fixes to the recording file later in the process.

I thought it would be useful for others, since the documentation is not enough for me.

 for data_field in fields: checker.set_text(str(data_field)) for err in checker: print err.word print err.suggest() correct = raw_input("provide 0-index int of correct word or i to ignore, e to edit ") if correct == 'i': pass elif correct == 'e': suggest = raw_input("") err.replace(suggest) else: correct = int(correct) suggest = err.suggest()[correct] err.replace(suggest) corrected_text.append(checker.get_text()) 
0
source

All Articles