Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to retrieve wordnet synonyms #2978

Merged
merged 4 commits into from
Apr 13, 2022
Merged

Conversation

ekaf
Copy link
Contributor

@ekaf ekaf commented Apr 11, 2022

Users struggle to find the synonyms of a word (#2976) because the wordnet.py module still does not provide a convenient way to retrieve synonyms, although it claims to:
"Using synsets, helps find conceptual relationships between words such as hypernyms, hyponyms, synonyms, antonyms etc." (sic).

To remedy this deficiency, the present PR adds a function that returns a nested list with the synonyms of the different senses of a word in the given language. Collapsing the different senses into one big list is not recommendable, since the different senses are not mutual synonyms.

from nltk.corpus import wordnet as wn
print(wn.synonyms('car'))

[['automobile', 'machine', 'auto', 'motorcar'], ['railcar', 'railway_car', 'railroad_car'], ['gondola'], ['elevator_car'], ['cable_car']]

print(wn.synonyms('coche', lang='spa'))

[['vehículo', 'auto', 'carro', 'automóvil', 'máquina', 'turismo'], ['vagón', 'automotor'], ['vagón', 'vagón_de_pasajeros']]

@stevenbird
Copy link
Member

stevenbird commented Apr 12, 2022

Thanks @ekaf. Would you mind adding an example to https://github.com/nltk/nltk/blob/develop/nltk/test/wordnet.doctest please? To appear here: https://www.nltk.org/howto/wordnet.html

@stevenbird stevenbird self-assigned this Apr 12, 2022
@stevenbird stevenbird merged commit c7853e0 into nltk:develop Apr 13, 2022
@stevenbird
Copy link
Member

Thanks @ekaf!

@ekaf ekaf deleted the synonyms branch April 16, 2022 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants