
- Python - Text Processing
- Python - Text Processing Introduction
- Python - Text Processing Environment
- Python - String Immutability
- Python - Sorting Lines
- Python - Reformatting Paragraphs
- Python - Counting Token in Paragraphs
- Python - Binary ASCII Conversion
- Python - Strings as Files
- Python - Backward File Reading
- Python - Filter Duplicate Words
- Python - Extract Emails from Text
- Python - Extract URL from Text
- Python - Pretty Print
- Python - Text Processing State Machine
- Python - Capitalize and Translate
- Python - Tokenization
- Python - Remove Stopwords
- Python - Synonyms and Antonyms
- Python - Text Translation
- Python - Word Replacement
- Python - Spelling Check
- Python - WordNet Interface
- Python - Corpora Access
- Python - Tagging Words
- Python - Chunks and Chinks
- Python - Chunk Classification
- Python - Text Classification
- Python - Bigrams
- Python - Process PDF
- Python - Process Word Document
- Python - Reading RSS feed
- Python - Sentiment Analysis
- Python - Search and Match
- Python - Text Munging
- Python - Text wrapping
- Python - Frequency Distribution
- Python - Text Summarization
- Python - Stemming Algorithms
- Python - Constrained Search
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - WordNet Interface
WordNet is a dictionary of English, similar to a traditional thesaurus NLTK includes the English WordNet. We can use it as a reference for getting the meaning of words, usage example and definition. A collection of similar words is called lemmas. The words in WordNet are organized and nodes and edges where the nodes represent the word text and the edges represent the relations between the words. below we will see how we can use the WordNet module.
All Lemmas
from nltk.corpus import wordnet as wn res=wn.synset('locomotive.n.01').lemma_names() print res
When we run the above program, we get the following output −
[u'locomotive', u'engine', u'locomotive_engine', u'railway_locomotive']
Word Definition
The dictionary definition of a word can be obtained by using the definition function. It describes the meaning of the word as we can find in a normal dictionary.
from nltk.corpus import wordnet as wn resdef = wn.synset('ocean.n.01').definition() print resdef
When we run the above program, we get the following output −
a large body of water constituting a principal part of the hydrosphere
Usage Examples
We can get the example sentences showing some usage examples of the words using the exmaples() function.
from nltk.corpus import wordnet as wn res_exm = wn.synset('good.n.01').examples() print res_exm
When we run the above program we get the following output −
['for your own good', "what's the good of worrying?"]
Opposite Words
Get All the opposite words by using the antonym function.
from nltk.corpus import wordnet as wn # get all the antonyms res_a = wn.lemma('horizontal.a.01.horizontal').antonyms() print res_a
When we run the above program we get the following output −
[Lemma('inclined.a.02.inclined'), Lemma('vertical.a.01.vertical')]