python - How to determine multiword A is a B in wordnet? -
i using nltk here post process classification labels(from imagenet) of model. instance, model might put label 'black bear' on image. how should determine if 'black bear' kind of 'animal'(animal's hyponym) using wordnet?
i tried this method tricking part when use code below synset of 'black bear', empty list! can't decide whether 'black bear' hyponym of 'animal'
from nltk.corpus import wordnet wn blackbear = wn.synsets('black bear')
is there solution problem? thanks!
for multiword expressions, use underscores instead of spaces, i.e.
>>> nltk.corpus import wordnet wn >>> wn.synsets('black bear') [] >>> wn.synsets('black_bear') [synset('asiatic_black_bear.n.01'), synset('american_black_bear.n.01')]
and hyper/hyponym determining hypernym or hyponym using wordnet nltk:
>>> bear = wn.synsets('bear', pos='n')[0] >>> bear.definition() u'massive plantigrade carnivorous or omnivorous mammals long shaggy coats , strong claws' >>> black_bear = wn.synsets('black_bear', pos='n')[0] >>> black_bear.definition() u'bear black coat living in central , eastern asia' >>> hypobear = set([i in bear.closure(lambda s:s.hyponyms())]) >>> hyperblackbear = set([i in black_bear.closure(lambda s:s.hypernyms())]) >>> black_bear in hypobear true >>> animal = wn.synsets('animal')[0] >>> animal.definition() u'a living organism characterized voluntary movement' >>> hypoanimal = set([i in animal.closure(lambda s:s.hyponyms())]) >>> black_bear in hypoanimal true >>> bear in hypoanimal true
but note wordnet has limited coverage on multi-word expressions (mwes).
Comments
Post a Comment