Search code examples
pythonpython-3.xnltkwordnet

Get the word from a WordNet synset


Given a synset like this:

Synset("pascal_celery.n.01")

I want to get the word(s) it represents:

"pascal celery"

Currently, I'm doing this:

synset.name().split(".")[0]

but this doesn't convert underscores into spaces.

Is there an inbuilt way of doing this?


Solution

  • According to the source code of the Synset class there is no method to return exactly what you want.

    You will probably have to rely on plain old Python replace:

    synset.name().split(".")[0].replace('_',' ')