-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeywords.py
131 lines (107 loc) · 3.04 KB
/
keywords.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def keywords(TLEnv,TREnv,BLEnv,BREnv):
import drawBox
environment = []
for key in list(TLEnv.keys()):
environment.append(key)
for key in list(TREnv.keys()):
environment.append(key)
for key in list(BLEnv.keys()):
environment.append(key)
for key in list(BREnv.keys()):
environment.append(key)
print("environment=", environment)
import nltk
import wikipedia
nltk.download('stopwords')
nltk.download('wordnet')
question = "touch the plant that's the least nutritious"
#environment = ["basil", "lemon", "power plant"]
qTokens = [t for t in question.split()]
from nltk.corpus import stopwords
stopwords.words('english')
for token in qTokens:
if token in stopwords.words('english'):
qTokens.remove(token)
function = " "
functWords = ["most", "least", "more", "less", "big", "small", "backward", "backwards", "scrambled"]
commandWords = ["touch", "tap", "press"]
for token in qTokens:
if token in functWords:
function = token
qTokens.remove(token)
if token in commandWords:
qTokens.remove(token)
#print(qTokens)
#print("qTokens length = %d", len(qTokens))
from nltk.corpus import wordnet
synTokens = {}
for i in range(0, len(qTokens)):
token = qTokens[i]
synonyms = []
for syn in wordnet.synsets(token):
for lemma in syn.lemmas():
synonyms.append(lemma.name())
synTokens[token] = synonyms
#print(synTokens)
'''
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
stemmedTokens = []
for token in qTokens:
token = stemmer.stem(token)
stemmedTokens.append(token)
print(stemmedTokens)
'''
for obj in environment:
#print("obj=", obj)
score = 0
page = wikipedia.page(obj)
for token in synTokens:
if token in page.content:
score = score+1
#print("token=", token)
#print("score=", score)
if score == 0:
environment.remove(obj)
key = list(synTokens.keys())[-1]
scores = {}
for obj in environment:
#print("obj=", obj)
score = 0
page = wikipedia.page(obj)
for token in synTokens[key]:
if token in page.content:
score = score+1
#print("token=", token)
scores[score] = obj
#print("scores=", scores)
#print("function=", function)
def minimize(scores_dict):
lst = list(scores_dict.keys())
minVal = min(lst)
print("Min scored object =", scores_dict[minVal])
return minVal
vertices = []
if function in ["least", "less", "small"]:
minVal = minimize(scores)
'''
if minVal in TREnv.keys():
vertices = TREnv[minVal]
if minVal in TLEnv.keys():
vertices = TLEnv[minVal]
if minVal in BREnv.keys():
vertices = BREnv[minVal]
if minVal in BLEnv.keys():
vertices = BLEnv[minVal]
'''
vertices = BREnv['Flowerpot']
print("vertices", vertices)
vertices = vertices[0:2]
print("vertices", vertices)
drawBox.drawBox(vertices)
def maximize(scores_dict):
lst = list(scores_dict.keys())
maxVal = max(lst)
print("Max scored object =", scores_dict[maxVal])
if function in ["most", "more", "big"]:
maximize(scores)