簡體   English   中英

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的一個可愛功能,該功能最初來自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]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM