问题
I am looking for a python module that helps me get the definition(s) from an english dictionary for a word.
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)
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.
Is there any python module that gives access to a full english dictionary including definitions of words?
回答1:
Wordnik seems to have quite a nice API, and a nice-looking Python module too. It has definitions, example sentences, etc. so you should be covered. It does also have common words like "how", "should", and "could."
回答2:
Instead of a module, you can rely other offline/online sources like xml,json,api etc.
https://github.com/adambom/dictionary [json file]
http://dictionary-api.cambridge.org [REST api]
http://glosbe.com/a-api [REST api]
http://developer.oxforddictionaries.com/developer-resources/api-reference-guide/intro-using-the-oxford-dictionaries-api/ [REST api]
http://www.ibiblio.org/webster/ [XML, open source]
回答3:
What about this. You'll need to write your own parser, but that should be fairly trivial given how the data is formatted.
回答4:
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.
Have you tried looking at Grady Ward's Moby? [link] (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).
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)
回答5:
The python NLTK has a WordNet
interface which is exactly what you're looking for.
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.
来源:https://stackoverflow.com/questions/21395011/python-module-with-access-to-english-dictionaries-including-definitions-of-words