gpt4 book ai didi

python - 拼写错误 - Pyenchant

转载 作者:太空宇宙 更新时间:2023-11-04 02:35:02 26 4
gpt4 key购买 nike

我尝试使用 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."

最佳答案

您只需要进行替换,包括 **misspelledword** 部分。

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("**%s** %s" % (err.word, sug)) # Look here
Spellchecked = chkr.get_text()
print Spellchecked

关于python - 拼写错误 - Pyenchant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48123861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com