Python:检查单词拼写是否正确

发布于 2024-10-08 19:07:28 字数 1435 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-10-15 19:07:28

有两种可能的方法:

  1. 拥有自己的文件,其中包含所有
    有效的话。将文件加载到
    设置并比较每个单词看看
    它是否存在于其中(集合中的单词)
  2. (更好的方法)使用 PyEnchant,一个拼写检查库Python

PyEnchant 现在没有积极维护。

Two possible ways of doing it:

  1. Have your own file which has all the
    valid words. Load the file into a
    set and compare each word to see
    whether it exists in it (word in set)
  2. (The better way) Use PyEnchant, a spell checking library for Python

PyEnchant is not actively maintained now.

捶死心动 2024-10-15 19:07:28

我一直在寻找相同的功能,并努力寻找可在 64 位 Windows 中运行的现有库。 PyEnchant 虽然是一个很棒的库,但目前尚未激活并且无法在 64 位下运行。我发现的其他库在 Windows 中不起作用。

我终于找到了一个解决方案,我希望其他人会发现它有价值。

解决方案...

  • 使用 nltk
  • 从 nltk.corpus.brown 中提取单词列表
  • 将单词列表转换为集合(以便高效搜索)
  • 使用 in 关键字确定您的字符串是否在集合中

from nltk.corpus import brown
word_list = brown.words()
word_set = set(word_list)

# Check if word is in set
"looked" in word_set  # Returns True
"hurrr" in word_set  # Returns False

使用计时器检查,您会发现几乎不需要时间来搜索集合。对 1,000 个单词的测试花费了 0.004 秒。

I was looking for the same functionality and struggled to find an existing library that works in Windows, 64 bit. PyEnchant, although a great library, isn't currently active and doesn't work in 64 bit. Other libraries I found didn't work in Windows.

I finally found a solution that I hope others will find valuable.

The solution...

  • Use nltk
  • Extract the word list from nltk.corpus.brown
  • Convert the word list to a set (for efficient searching)
  • Use the in keyword to determine if your string is in the set

from nltk.corpus import brown
word_list = brown.words()
word_set = set(word_list)

# Check if word is in set
"looked" in word_set  # Returns True
"hurrr" in word_set  # Returns False

Use a timer check and you'll see this takes virtually no time to search the set. A test on 1,000 words took 0.004 seconds.

2024-10-15 19:07:28

我个人使用: http://textblob.readthedocs.io/en/dev/
这是一个活跃的项目,根据网站介绍:

拼写纠正基于 Peter Norvig 的“如何编写拼写纠正器”[1],并在模式库中实现。准确率约为 70%

I personally used: http://textblob.readthedocs.io/en/dev/
It is an active project and according to the website:

Spelling correction is based on Peter Norvig’s “How to Write a Spelling Corrector”[1] as implemented in the pattern library. It is about 70% accurate

始终不够爱げ你 2024-10-15 19:07:28

Yahoo 通过 YQL 提供拼写检查 API

它非常简单,您每天可以获得 5000 个查询/IP 地址用于非商业用途(免费)

Yahoo provides spell checking API through YQL.

Its pretty simple and you get 5000 queries/ip address/day for non-commercial use (FREE)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文