如何获取同义词集的所有属性?

发布于 2024-11-19 23:04:15 字数 448 浏览 9 评论 0原文

请给我一个示例,其中包含单词的 synset 的所有属性 我只知道这个属性: namelemma_namesdefinition

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏辞 2024-11-26 23:04:15

使用 dir() 内置函数口译员。

这是一个示例:

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']

您可以向 dir() 提供任何对象 获取其属性的列表

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.

萧瑟寒风 2024-11-26 23:04:15

您可以查看 WordNet 术语表 - 它们列出了相当多的属性。它可以在这里找到:WordNet Glossary

如果我正确理解你的问题,像这样的东西也可能有效。 'nyms' 这里列出了 synset 可以具有的所有属性,try-catch 将处理 synset 不具有任何此类属性的任何情况。

有些属性仅适用于引理,不适用于同义词集,因此您可以使用相同的代码,但将同义词集替换为引理,以获得反义词、derivationally_related_forms 和 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文