python - 带有补充自定义词典的拼写校正器
问题描述
在 python 中,允许使用外部字典的拼写检查的最佳系统是什么?例如,我见过使用外部词典替换默认英语词典的软件包。但我希望外部字典补充现有的拼写检查。例如,如果我有奇怪的抽象单词(dsdfw
, peloe
, punj
),我希望拼写检查器能够将它们识别为英语单词,以便进行拼写纠正。
This is na exapmle of a setence using pelloe
应该成为
This is an example of a sentence using peloe
解决方案
正如我在评论中所说,一个不错的选择是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)
我希望它有所帮助。
推荐阅读
- python - 每隔几秒钟从 python 中的 SQL 获取新数据的问题
- android - 在移动应用上存储 SAML 断言并将它们用于用户会话
- javascript - 在 React 中获取在线当前时间
- react-native - 使用 useState 反应原生表单
- r - 如何删除包含超过 2000 个 NA 值的所有列?
- angular - Angular - 迭代来自 Google Books API 的响应对象
- javascript - 使用单个坐标变量在 Google Maps JavaScript API 中选择中心
- r - 如何在R highcharter中反转多个y轴?
- javascript - 如何找到特定的数组属性 ejs
- c# - C#多文本框的一个事件