-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.py
46 lines (35 loc) · 966 Bytes
/
task.py
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
37
38
39
40
41
42
43
44
45
46
"""
Created on Sat May 22 22:58:17 2021
@author: ALAA
"""
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet
cat = 'cat.n.01'
dog = 'dog.n.01'
entity = 'entity.n.01'
def getWord(k,w):
for syn in w:
for hyper in syn.hypernyms():
if (hyper.name() == cat):
return k + " is a cat"
elif (hyper.name()==dog):
return k + " is a dog"
else:
for i in hyper.hypernyms():
if (i.name() == cat):
return k + " is a cat"
elif (i.name()==dog):
return k + " is a dog"
return k + " is not a dog or a cat"
w = input("enter word: ")
a = wordnet.synsets(w)
print (getWord(w, a))
"""
getWord('working_dog')
getWord('king')
getWord('domestic_cat')
getWord('poodle')
getWord('leonberg')
getWord('puppy')
"""