开发者

How do I Get All Attributes Of Synsets?

开发者_开发知识库

Please Give Me am example That have all of attribute of synset of a word i know only this attribute: name , lemma_names , definition

synsetsWord = ObjWn.synsets( 'Book' )
        i = 0 
        for senseWord in synsetsWord:
            synsetsWord[i] = senseWord.name
            print 'Sense Lema Name: ' , senseWord.lemma_names
            print 'Sense Definition : ' , senseWord.definition
            i = i + 1

thanks


Use the dir() built-in function in the interpreter.

Here is an example:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> help(itertools)

>>> dir(itertools.chain)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'from_iterable', 'next']

You can supply any object to dir() to get a list of its attributes.


You can check out the WordNet glossary for terms - they list quite a few of the attributes there. It can be found here: WordNet Glossary

If I understand your question correctly, something like this may also work. 'nyms' here lists all the attributes a synset can have and the try-catch will handle any cases where the synset doesn't have any attributes of that kind.

Some attributes are only applicable to lemmas, not synsets, so you can use the same code but replace synsets with lemmas to get attributes like antonyms, derivationally_related_forms, and pertainyms.

for synset in (wn.synsets('dog')):
        print synset
        nyms = ['hypernyms', 'hyponyms', 'meronyms', 'holonyms', 'part_meronyms', 'sisterm_terms', 'troponyms', 'inherited_hypernyms']
        for i in nyms:
            try:
                print getattr(synset, i)()
            except AttributeError as e: 
                print e
                pass
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜