Christos Hayward
Christos Hayward

Reputation: 5993

How, with Python / the NLTK / Wordnet, can avoid a nondescript error message?

I am periodically getting AttributeError: 'Synset' object has no attribute 'lower'. My code, all in one file, is generating the error:

Synset('book.n.01')
[Synset('book.n.01')]
Traceback (most recent call last):
  File "./map", line 124, in <module>
    print print_nodes(word)
  File "./map", line 98, in print_nodes
    result.append(print_nodes(synonym), indentation_level + 2 *
  File "./map", line 88, in print_nodes
    synonyms = wordnet.synsets(root)
  File "/usr/local/lib/python2.7/site-packages/nltk/corpus/reader/wordnet.py", line 1416, in synsets
    lemma = lemma.lower()
AttributeError: 'Synset' object has no attribute 'lower'

The initial value appears to be what I intended, Synset('book.n.01'). When it runs, it seems to be running once thought for the neighbors Wordnet pulls up, but that is a separate issue.

What is the issue triggering a 'Synset' object has no attribute 'lower', and how can I fix it?

Upvotes: 1

Views: 330

Answers (1)

alexis
alexis

Reputation: 50200

I'm not sure what your code really looks like or what you are trying to do, but the nltk wordnet howto shows how to create a synset if you already know its identifier:

>>> from nltk.corpus.reader import wordnet as wn
>>> book = wn.synset("book.n.01")
>>> book
Synset('book.n.01')
>>> book.examples()
['I am reading a good book on economics']

If this doesn't clear things up for you, please edit your question and add some actual python code that creates the synset that gives you problems.

Upvotes: 4

Related Questions