python - 使用 symspellpy 的拼写检查器
问题描述
我想制作一个拼写检查器,如果有任何错误,它可以更正用户输入。我使用 symspellpy 和海关数据库作为字典
from symspellpy import SymSpell
sym_spell = SymSpell()
corpus_path = 'D:\Pursuit soft\dict\words2.txt'
sym_spell.create_dictionary(corpus_path)
print(sym_spell.words)
现在当我使用以下代码时
from symspellpy import SymSpell, Verbosity
input_term='cmments'
suggestions = sym_spell.lookup(input_term, Verbosity.CLOSEST,
max_edit_distance=2, include_unknown=True)
for suggestion in suggestions:
print(suggestion)
结果是:“cmments”变成了“comments, 1, 8”..这是正确的..但我只是单词而不是距离和频率..如何只提取单词?
解决方案
lookup 的返回值是一个SuggestItem
s 的列表。您可以通过以下方式获得建议的术语:
print(suggestion.term)
推荐阅读
- javascript - 将默认数据表转换为服务器端渲染 - laravel
- laravel - Spatie 权限与另一个模型和 jwt 与用户不起作用
- java - 如何让 EditText 过滤负数和正数之间的数字
- laravel - 如何在 Laravel 日志中显示用户数据(使用 sanctum auth)
- python - 为什么扩展 docker-airflow 映像,使我的调度程序容器不健康?
- matrix - 如何同情行列式列表
- javascript - 在某些设备(VueJS、iOS / Android)上未触发模糊事件
- python - 需要 Python 正则表达式帮助,多行正则表达式
- laravel - 如何删除超过一小时的公共存储文件?
- arrays - 如何迭代数组以获取下一个元素(2个数组)