我知道如何获得大量的词语,比如:
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')我的问题是,如果我想搜索hypernym of a offset,我将如何更改当前的代码?
例如,给定偏移量01234567-n,就会输出它的超限。可以像我的示例那样以synset形式输出超级数列,或者(最好是)作为offset表单输出。谢谢。
发布于 2016-02-22 20:34:21
这里有一个来自pywsd的可爱的函数,它来自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]))https://stackoverflow.com/questions/35562609
复制相似问题