可以访问英语词典的 Python 模块,包括单词的定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21395011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python module with access to english dictionaries including definitions of words
提问by Sadik
I am looking for a python module that helps me get the definition(s) from an english dictionary for a word.
我正在寻找一个 python 模块,它可以帮助我从英语词典中获取单词的定义。
There is of course enchant, which helps me check if the word exists in the English language, but it does not provide definitions of them (at least I don't see anything like that in the docs)
当然有enchant,它可以帮助我检查英语中是否存在该词,但它没有提供它们的定义(至少我在文档中没有看到类似的内容)
There is also WordNet, which is accessible with NLTK. It has definitions and even sample sentences, but WordNet does not contain all English words. Common words like "how", "I", "You", "should", "could"... are not part of WordNet.
还有 WordNet,可通过 NLTK 访问。它有定义甚至例句,但 WordNet 并不包含所有英语单词。诸如“如何”、“我”、“你”、“应该”、“可以”等常用词不属于 WordNet。
Is there any python module that gives access to a full english dictionary including definitions of words?
是否有任何 python 模块可以访问完整的英语词典,包括单词的定义?
采纳答案by Fox Wilson
Wordnikseems to have quite a nice API, and a nice-looking Python moduletoo. It has definitions, example sentences, etc. so you should be covered. It does also have common words like "how", "should", and "could."
Wordnik似乎有一个很好的 API,还有一个漂亮的 Python 模块。它有定义、例句等,所以你应该被覆盖。它也有一些常用词,如“如何”、“应该”和“可以”。
回答by jayelm
The python NLTKhas a WordNetinterface which is exactly what you're looking for.
http://www.nltk.org/howto/wordnet.html
pythonNLTK有一个WordNet接口,这正是你要找的。
http://www.nltk.org/howto/wordnet.html
Edit: OP did not specify his request for common words, thus ruling out WordNet, until after I posted this answer. Since this answer has upvotes anyways, I'll leave it here.
编辑:OP 没有指定他对常用词的要求,因此排除了 WordNet,直到我发布了这个答案。由于无论如何这个答案都有赞成票,我将把它留在这里。
回答by Korbonits
Note that while WordNet does not have all English words, what about the Oxford English Dictionary? (http://developer.oxforddictionaries.com/). Depending on the scope of your project, it could be a killer API.
请注意,虽然 WordNet 没有所有英语单词,但牛津英语词典呢?(http://developer.oxforddictionaries.com/)。根据您的项目范围,它可能是一个杀手级 API。
Have you tried looking at Grady Ward's Moby? [link] (http://icon.shef.ac.uk/Moby/).
你有没有试过看格雷迪沃德的白鲸?[链接](http://icon.shef.ac.uk/Moby/)。
You could add it as a lexicon in NLTK (see notes on "Loading your own corpus" in Section 2.1).
您可以将其添加为 NLTK 中的词典(请参阅第 2.1 节中有关“加载您自己的语料库”的注释)。
from nltk.corpus import PlaintextCorpusReader
corpus_root = '/usr/share/dict'
wordlists = PlaintextCorpusReader(corpus_root, '.*')
Or:
或者:
from nltk.corpus import BracketParseCorpusReader
corpus_root = r"C:\corpora\penntreebank\parsed\mrg\wsj"
file_pattern = r".*/wsj_.*\.mrg"
ptb = BracketParseCorpusReader(corpus_root, file_pattern)
回答by DhruvPathak
Instead of a module, you can rely other offline/online sources like xml,json,api etc.
您可以依赖其他离线/在线资源,如 xml、json、api 等,而不是模块。
https://github.com/adambom/dictionary[json file]
http://dictionary-api.cambridge.org[REST api]
http://glosbe.com/a-api[REST api]
http://www.ibiblio.org/webster/[XML, open source]

