Andrea Kunzle
Andrea Kunzle

Reputation: 11

Attribute Error for Wordnet: AttributeError: module 'nltk_data.corpora.wordnet' has no attribute 'synset'

'See if you can print all the synset definitions of the lemma dog.'

So for this exercise, I'm told to run the code and download nltk, and then look up all the synset definitions of the lemma 'dog.'

The download runs, and it says 'true,' therefore, nltk was downloaded.

However, when I want to import wordnet from nltk_data.corpora (the nltk folder corpus), I can import it, but the attribute 'synset' from the wordnet dictionary outputs: 'AttributeError.'

In what way can I bring the output of synsets for the lemma 'dog'?

## help found on https://www.nltk.org/howto/wordnet.html

import nltk_data
from nltk_data.corpora import wordnet as wn
dog = wn.synset('dog.n.01')

Image of code error, view the full exercise description

Upvotes: 1

Views: 749

Answers (1)

Sam Greenberg
Sam Greenberg

Reputation: 134

  1. If you want all the synsets for the word "dog", use wn.synsets([word]) instead of wn.synset([wn name]).
  2. Instead of assigning the output to a variable, try just letting the output go to stdout. That way you can see what you have. If you want some fun expansion, the "definition()" function is cute. (I like that #0 is the canine, #1 is a woman, and #2 is a man. :) )

wn.synsets('dog')

[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]

[syn.definition() for syn in wn.synsets('dog')]

['a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds', 'a dull unattractive unpleasant girl or woman', 'informal term for a man', 'someone who is morally reprehensible', 'a smooth-textured sausage of minced beef or pork usually smoked; often served on a bread roll', 'a hinged catch that fits into a notch of a ratchet to move a wheel forward or prevent it from moving backward', 'metal supports for logs in a fireplace', 'go after with the intent to catch']

Upvotes: 0

Related Questions