Reputation: 11060
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?
Upvotes: 1
Views: 1780
Reputation: 11321
I'm a little late to the party here, but for posterity, I think you're looking for the .lemmas()
and .lemma_names()
methods on synsets.
from nltk.corpus import wordnet as wn
dog = wn.synsets('dog')[0]
dog.lemma_names()
>>>['dog', 'domestic_dog', 'Canis_familiaris']
From there, you can replace underscores with spaces, and you'll get what you need.
Upvotes: 1
Reputation: 52000
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('_',' ')
Upvotes: 4