You can download this code by clicking the button below.
This code is now available for download.
This function takes a word as input and returns the definition of a random synset of that word from WordNet.
Technology Stack : nltk.corpus.wordnet, nltk.tokenize.word_tokenize
Code Type : Function
Code Difficulty : Intermediate
import random
from nltk.corpus import wordnet
from nltk.tokenize import word_tokenize
def random_wordnet_synset(word):
synsets = wordnet.synsets(word)
if synsets:
return random.choice(synsets).definition()
else:
return "No definition found for the word."