首页 > 解决方案 > 带有补充自定义词典的拼写校正器

问题描述

在 python 中,允许使用外部字典的拼写检查的最佳系统是什么?例如,我见过使用外部词典替换默认英语词典的软件包。但我希望外部字典补充现有的拼写检查。例如,如果我有奇怪的抽象单词(dsdfw, peloe, punj),我希望拼写检查器能够将它们识别为英语单词,以便进行拼写纠正。

This is na exapmle of a setence using pelloe

应该成为

This is an example of a sentence using peloe

标签: pythonnltkspell-checking

解决方案


正如我在评论中所说,一个不错的选择是enchant.

这是一个关于如何使用它为会话添加单词的示例:

import enchant

en_us = enchant.Dict('en_US')

en_us_weird_words = ['your', 'weird', 'words', 'list', 'here']

for word in en_us_weird_words:

    # add word to personal dictionary
    # en_us.add(word)

    # add word just for this session
    en_us.add_to_session(word)

pt_br = enchant.Dict('pt_BR')

pt_br_weird_words = ['outras', 'palavras', 'estranhas', 'aqui']

for word in pt_br_weird_words:

    # add word to personal dictionary
    # pt_br.add(word)

    # add word just for this session
    pt_br.add_to_session(word)

我希望它有所帮助。


推荐阅读