WordNet introduction

1.是一个英语词典。 2.查找一个词的意思,同义词,反义词。


In [1]:
from nltk.corpus import wordnet

In [12]:
syns = wordnet.synsets("good")

In [24]:
print(syns[8].lemmas()[0].name())
print(syns[0].definition())
print(syns[1].definition())
print(syns[2].definition())
print(syns[0].lemmas()[0].name())


beneficial
benefit
moral excellence or admirableness
that which is pleasing or valuable or useful
good
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-3d5f4aa38336> in <module>()
      4 print(syns[2].definition())
      5 print(syns[0].lemmas()[0].name())
----> 6 print(syns.lemmas())

AttributeError: 'list' object has no attribute 'lemmas'

In [11]:
print(syns[0].definition())
print(syns[0].examples())
print(syns[0])


a series of steps to be carried out or goals to be accomplished
['they drew up a six-step plan', 'they discussed plans for a new bond issue']
Synset('plan.n.01')

In [26]:
synonyms=[]
antonyms=[]
for syn in wordnet.synsets("good"):
    for l in syn.lemmas():
        synonyms.append(l.name())
        if l.antonyms():
            antonyms.append(l.antonyms()[0].name())

print(set(synonyms))
print(set(antonyms))


{'salutary', 'well', 'honorable', 'proficient', 'soundly', 'trade_good', 'expert', 'dependable', 'dear', 'skilful', 'beneficial', 'commodity', 'right', 'safe', 'respectable', 'near', 'serious', 'ripe', 'full', 'adept', 'sound', 'upright', 'honest', 'goodness', 'just', 'estimable', 'skillful', 'good', 'effective', 'undecomposed', 'unspoiled', 'unspoilt', 'in_effect', 'practiced', 'thoroughly', 'secure', 'in_force'}
{'ill', 'bad', 'evil', 'badness', 'evilness'}

In [ ]: