2014-06-13 1 views

Répondre

1

Je ne pense pas qu'il existe un moyen clair d'obtenir ce dont vous avez besoin à moins que vous ne puissiez le définir plus concrètement. Par exemple:

>>> from nltk.corpus import wordnet as wn 
>>> blue = wn.synsets('blue')[0] 
>>> cat = wn.synsets('cat')[0] 
>>> blue.definition() 
u'blue color or pigment; resembling the color of the clear sky in the daytime' 
>>> cat.definition() 
u'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats' 

Parfois, vous avez de la chance et monter un ou deux niveaux des hyperonymes:

>>> blue.hypernyms() 
[Synset('chromatic_color.n.01')] 
>>> blue.hypernyms()[0].hypernyms() 
[Synset('color.n.01')] 

Parfois, il faut aller beaucoup niveau les hyperonymes pour obtenir ce que vous voulez.

>>> cat.hypernyms() 
[Synset('feline.n.01')] 
>>> cat.hypernyms()[0].hypernyms() 
[Synset('carnivore.n.01')] 
>>> cat.hypernyms()[0].hypernyms()[0].hypernyms() 
[Synset('placental.n.01')] 
>>> cat.hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms() 
[Synset('mammal.n.01')] 
>>> cat.hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms() 
[Synset('vertebrate.n.01')] 
>>> cat.hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms() 
[Synset('chordate.n.01')] 
>>> cat.hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms()[0].hypernyms() 
[Synset('animal.n.01')] 

et obtenir au plus haut niveau le plus hypernym est logique pas grand-chose:

>>> blue.root_hypernyms() 
[Synset('entity.n.01')] 
>>> cat.root_hypernyms() 
[Synset('entity.n.01')] 

Parfois, il est tout simplement pas hypernym pour vous d'aller à:

>>> happy = wn.synsets('happy')[0] 
>>> happy.definition() 
u'enjoying or showing or marked by joy or pleasure' 
>>> happy.hypernyms() 
[] 
>>> happy.root_hypernyms() 
[Synset('happy.a.01')] 
Questions connexes