-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNLTK-WordNet.py
More file actions
36 lines (28 loc) · 940 Bytes
/
NLTK-WordNet.py
File metadata and controls
36 lines (28 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
#Created by Parth Patel, DBI @ University of Delaware, Newark, Delaware 19717
#Date created: 07/08/2018
## lemmas and synonyms in WordNet
import nltk
from nltk.corpus import wordnet
#### GET SYNSETS ######
syns = wordnet.synsets("cookbook")
print("all synonymes:",syns)
print("First one:",syns[0].name())
print("First one - lemmas",syns[0].lemmas()[0])
print(syns[0].examples())
#### GET SYNONYMS & ANTONYMS ######
synonyms = []
antonyms = []
for syn in wordnet.synsets('good'):
for lemma in syn.lemmas():
synonyms.append(lemma.name())
if lemma.antonyms():
antonyms.append(lemma.antonyms()[0].name())
print(antonyms.append(lemma.antonyms()[0].name()))
print(set(synonyms))
print(set(antonyms))
#### CHECK WORD SIMILARITY ######
ref= wordnet.synset('refernce.n.01')
bb = wordnet.synset('bibilography.n.01')
print(ref,bb)
print(ref.wup_similarity(bb)) ## Wu-Palmer semantic similarity