我尝试使用 python 库进行拼写检查、更正和替换。
对于一些复杂的拼写更正,我需要有第二个意见,并看到被替换的单词下划线或删除线。
即使文件输出是rtf格式,也没问题。如何解决?
努力至今。
import enchant
from enchant.checker import SpellChecker
chkr = SpellChecker("en_UK","en_US")
spacedfile = "This is a setence. It has speeelinng mistake."
chkr.set_text(spacedfile)
for err in chkr:
sug = err.suggest()[0]
err.replace(sug)
Spellchecked = chkr.get_text()
print Spellchecked
输出:
This is a sentence. It has spelling mistake.
预期结果:
This is a **sntence** sentence. It has **speeelinng** spelling mistake."