我可以从 NTLK 语料库中标记的普林斯顿 WN 感觉中获得感觉偏移:
[in]:'dog.n.01'
>>> from nltk.corpus import wordnet as wn
>>> ss = wn.synset('dog.n.01')
>>> offset = str(ss.offset).zfill(8)+"-"+ss.pos
>>> print offset
[out]:'02084071-n'
该偏移量类似于http://casta-net.jp/~kuribayashi/cgi-bin/wn-multi.cgi?synset=02084071-n&lang=eng中使用的约定
我如何在不遍历整个 wordnet 语料库的情况下进行反向操作?在哪里:
[in]: '02084071-n'
[out]: 'dog.n.01' or Synset('dog.n.01')
我可以这样做,但它太长了,冗余周期也太多了:
[in]: '02084071-n'
in_offset, in_pos = "02084071-n".split("-")
from nltk.corpus import wordnet as wn
nltk_ss = [i for i in wn.all_synsets() if i.offset == int(in_offset) and i.pos == in_pos][0]
print nltk_ss
[out]: Synset('dog.n.01')