from textblob import Word
happy = Word('happy')
Word
class’s definitions
property returns a list of all the word’s definitions in the WordNet databasehappy.definitions
define
method that enables you to pass a part of speech as an argument so you can get definitions matching only that part of speechhappy.synsets
Synset
— a group of synonyms happy.a.01
:happy
is the original Word’s lemmatized forma
is the part of speech — a
for adjective, n
for noun, v
for verb, r
for adverb or s
for adjective satellite. 01
is the index number of the corresponding meaning in the WordNet databaseget_synsets
enables you to pass a part of speech to can get Synset
s for that part of speechlemmas
method that returns a list of Lemma
objects representing the synonymsLemma
’s name
method returns the synonymous word as a stringsynonyms = set()
for synset in happy.synsets:
for lemma in synset.lemmas():
synonyms.add(lemma.name())
synonyms
Lemma
has antonyms in the WordNet database, invoking the Lemma
’s antonyms
method returns a list of Lemma
s representing the antonymslemmas = happy.synsets[0].lemmas()
lemmas
Lemma
lemmas[0].antonyms()
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 5 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.