WordNet本来是一个电子版英语词典。后来在NLP的发展下,为NLP提供了很多英语料支持。
>>> import nltk
>>> nltk.download('wordnet')
>>> from nltk.corpus import wordnet as wn
>>> wn.synsets('dog') # 查一个单词的一系列属性
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'),
Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]
>>> wn.synsets('dog', pos=wn.VERB) # 规定词性
[Synset('chase.v.01')]
>>> print(wn.synset('dog.n.01').definition()) # 完整定义
a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds
>>> dog = wn.synset('dog.n.01')
>>> cat = wn.synset('cat.n.01')
>>> dog.path_similarity(cat) # 两个单词相似度
0.2...
wn.synset_from_pos_and_offset('n', int(wnid[1:]))