Python:从偏移量输入中检索 WordNet 上位词

Python: Retrieving WordNet hypernyms from offset input

我知道如何获取单词的上位词,像这样:

word = 'girlfriend'
word_synsets = wn.synsets(word)[0]

hypernyms = word_synsets.hypernym_paths()[0]

for element in hypernyms:
    print element


Synset('entity.n.01')
Synset('physical_entity.n.01')
Synset('causal_agent.n.01')
Synset('person.n.01')
Synset('friend.n.01')
Synset('girlfriend.n.01')

我的问题是,如果我想搜索 offsethypernym,我该如何更改当前代码?

例如,给定偏移量01234567-n,输出其上位词。上位词可以像我的示例那样以 synset 形式输出,或者(最好)以 offset 形式输出。谢谢。

这是来自 pywsd that's originally from http://moin.delph-in.net/SemCor

的一个可爱的函数
def offset_to_synset(offset):
    """ 
    Look up a synset given offset-pos 
    (Thanks for @FBond, see http://moin.delph-in.net/SemCor)
    >>> synset = offset_to_synset('02614387-v')
    >>> print '%08d-%s' % (synset.offset, synset.pos)
    >>> print synset, synset.definition
    02614387-v
    Synset('live.v.02') lead a certain kind of life; live in a certain style
    """
    return wn._synset_from_pos_and_offset(str(offset[-1:]), int(offset[:8]))