如何使用Python检查单词是否为英语单词? [英] How to check if a word is an English word with Python?

查看:506
本文介绍了如何使用Python检查单词是否为英语单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查Python程序中英语词典中是否有单词.

I want to check in a Python program if a word is in the English dictionary.

我相信可以使用nltk wordnet界面,但是我不知道如何将其用于如此简单的任务.

I believe nltk wordnet interface might be the way to go but I have no clue how to use it for such a simple task.

def is_english_word(word):
    pass # how to I implement is_english_word?

is_english_word(token.lower())

将来,我可能想检查单词的单数形式是否在字典中(例如,属性->属性->英文单词).我将如何实现?

In the future, I might want to check if the singular form of a word is in the dictionary (e.g., properties -> property -> english word). How would I achieve that?

推荐答案

要获得(更多)强大的功能和灵活性,请使用专用的拼写检查库,例如 PyEnchant .有一个教程,或者您可以直接潜入:

For (much) more power and flexibility, use a dedicated spellchecking library like PyEnchant. There's a tutorial, or you could just dive straight in:

>>> import enchant
>>> d = enchant.Dict("en_US")
>>> d.check("Hello")
True
>>> d.check("Helo")
False
>>> d.suggest("Helo")
['He lo', 'He-lo', 'Hello', 'Helot', 'Help', 'Halo', 'Hell', 'Held', 'Helm', 'Hero', "He'll"]
>>>

PyEnchant带有一些词典(en_GB,en_US,de_DE,fr_FR),但可以使用任何

PyEnchant comes with a few dictionaries (en_GB, en_US, de_DE, fr_FR), but can use any of the OpenOffice ones if you want more languages.

似乎有一个名为 inflect 的多元化图书馆,但我不知道不管有什么好处.

There appears to be a pluralisation library called inflect, but I've no idea whether it's any good.

这篇关于如何使用Python检查单词是否为英语单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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