拼写错误 - Pyenchant [英] Spelling mistakes - Pyenchant

查看:43
本文介绍了拼写错误 - Pyenchant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 python 库进行拼写检查、更正和替换.

I tried using python library for spell-check,correcting and replacing.

对于一些复杂的拼写更正,我需要有第二个意见,并查看替换的单词下划线或删除线.

For some complex spelling correction, I need to have a second opinion and to see replaced word underlined or strike through.

即使文件输出是rtf格式也没关系.如何解决?

Even if the file output is in rtf format, it is ok. How to solve it?

目前的努力.

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."

推荐答案

您只需要进行替换,包括**mispelledword** 部分.

You just need to do the replacement including the **misspelledword** part.

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

这篇关于拼写错误 - Pyenchant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆