如何使用 PyEnchant 更正文本并自动返回更正后的文本 [英] How to correct text and return the corrected text automatically with PyEnchant
本文介绍了如何使用 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
如何让 c
在不使用 0
的情况下从 cmdlinechecker
手动返回更正后的文本?
How do I get c
to return the corrected text without using 0
manually from cmdlinechecker
?
程序应该运行包含未更正文本的字符串,更正它,并将其保存在一个变量中以导出到 MySQL 数据库中.
The program should run through the string containing the uncorrected text, correct it, and save it in a variable to export into a MySQL DB.
推荐答案
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
完全按照我打算让它工作的方式工作.添加过滤器并自动更正所有小文本,使您能够执行关键字搜索等...
Works exactly as I was intending to have it work. Add Filters and corrects all small text automatically enabling you to perform keyword searches etc...
我花了 13 小时才弄明白;(
Took me 13hrs to figure out ;(
这篇关于如何使用 PyEnchant 更正文本并自动返回更正后的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文