解决方法
NLTK中没有内置方法,但可以尝试这样做:
from nltk.corpus import wordnet syns = list(wordnet.all_synsets()) offsets_list = [(s.offset(),s) for s in syns] offsets_dict = dict(offsets_list) offsets_dict[14204095] >>> Synset('heatstroke.n.01')
然后,您可以腌制字典,并在需要时加载它.
对于3.0之前的NLTK版本,请更换该行
offsets_list = [(s.offset(),s) for s in syns]
同
offsets_list = [(s.offset,s) for s in syns]