fetch_definition

fetch_definition

Module that fetches the definition, synonyms and antonyms of a given word using WordNet.

Functions

Name Description
fetch_definition Fetch definitions, synonyms, and antonyms of a word using WordNet.

fetch_definition

fetch_definition.fetch_definition(
    word,
    pos=None,
    top_n=1,
    max_synonyms=10,
    include_examples=False,
    return_type='str',
)

Fetch definitions, synonyms, and antonyms of a word using WordNet.

Parameters

Name Type Description Default
word str The word to look up. required
pos (n, v, a, r) Part of speech filter: noun (n), verb (v), adjective (a), adverb (r). If None, returns results for all parts of speech. Default is None. "n","v","a","r"
top_n int Number of top-ranked senses to include. 1
max_synonyms int Max number of synonyms to show (combined across returned senses). 10
include_examples bool If True, include example sentences when available. False
return_type str Format for returned results (currently supports “str”). "str"

Returns

Name Type Description
str Formatted string of word definition, senses, synonyms, and antonyms.

Raises

Name Type Description
LookupError If WordNet resource is not available.
TypeError If word is not a string.
ValueError If word is empty or pos is not valid.

Examples

>>> fetch_definition("happy")
Word: happy
Sense 1 (a): feeling or showing pleasure or contentment
Synonyms: cheerful, gay, glad, joyful, joyous, lighthearted, pleased
Antonyms: sad, unhappy
>>> fetch_definition("run", pos="v", top_n=2)
Word: run
Sense 1 (v): move fast by using one's legs
Sense 2 (v): flee; take to one's heels; cut and run
Synonyms: bolt, dash, escape, flow, gallop, go, hurry, jog, move, operate
Antonyms: None found