-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchatbot_phase3.py
More file actions
297 lines (296 loc) · 10.7 KB
/
chatbot_phase3.py
File metadata and controls
297 lines (296 loc) · 10.7 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import re
from dataset import ans
from wedontwant import those_words
from greetings import greet
from actions import weird
from actions import not_sure
from doub import doubl
from doub import doublr
from doub import doubwords
import random
from actions import pact
from actions import nact
b=[]
my_list=[]
m=''
doub_list=[]
doubw=[]
foo = ['Moreover', 'Furthermore', 'Also', 'And']
counter=0
def check():
global b
global doub_list
global doubw
doubw=[]
doub_list=[]
for x in b:
if(doubwords.__contains__(x)):
doubw.append(x)
for x in doubw:
for y in doubw:
if(x!=y):
global m
m=x+' '+y
if(doubl.__contains__(m)):
doub_list.append(m)
return
def query(counter,type):
global b
if(type==1):
global my_list
c=my_list[counter]
#countpact=0
countnact=0
countns=0
#print('You mentioned '+c)
for x in b:
#if pact.__contains__(x):
#countpact+=1
if nact.__contains__(x):
countnact+=1
if not_sure.__contains__(x):
countns+=1
#if(pact>=1):
#print(ans[c])
if(countnact==0):
if(countns==0):
print(ans[c])
else:
print('Well why not??')
print('I can tell you all you need to know about '+c)
print('Do you want to know about it??')
flag=-1
temp=input().lower()
if(temp=='y' or temp=='y '):
flag=1
if(temp=='n' or temp=='n '):
flag=0
if(flag==-1):
count1=0
right=[x for x in re.split('\W',temp) if x]
for x in right:
if those_words.__contains__(x):
count1+=1
if count1>0:
print('Please don\'t abuse!!! We at JUET don\'t tolerate it!!')
return
if(right.__contains__('yes') or right.__contains__('yup')):
flag=1
if(right.__contains__('no') or right.__contains__('nope')):
flag=0
if(flag==0):
print('Maybe I misunderstood you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
elif(flag==1):
print(ans[c])
else:
print('Sorry I don\'t understand you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
else:
flag=-1
print('You mentioned '+c)
print('But I am not sure if you really want to know about it.')
print('Would you like to know about it??')
temp=input().lower()
if(temp=='y' or temp=='y '):
flag=1
if(temp=='n' or temp=='n '):
flag=0
if(flag==-1):
count1=0
right=[x for x in re.split('\W',temp) if x]
for x in right:
if those_words.__contains__(x):
count1+=1
if count1>0:
print('Please don\'t abuse!!! We at JUET don\'t tolerate it!!')
return
if(right.__contains__('yes') or right.__contains__('yup')):
flag=1
if(right.__contains__('no') or right.__contains__('nope')):
flag=0
if(flag==0):
print('Maybe I misunderstood you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
elif(flag==1):
print(ans[c])
else:
print('Sorry I don\'t understand you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
else:
global doub_list
c=doub_list[counter]
#countpact=0
countnact=0
countns=0
#print('You mentioned '+c)
for x in b:
#if pact.__contains__(x):
#countpact+=1
if nact.__contains__(x):
countnact+=1
if not_sure.__contains__(x):
countns+=1
#if(pact>=1):
#print(ans[c])
if(countnact==0):
if(countns==0):
print(doublr[c])
else:
print('Well why not??')
print('I can tell you all you need to know about '+c)
print('Do you want to know about it??')
flag=-1
temp=input().lower()
if(temp=='y' or temp=='y '):
flag=1
if(temp=='n' or temp=='n '):
flag=0
if(flag==-1):
count1=0
right=[x for x in re.split('\W',temp) if x]
for x in right:
if those_words.__contains__(x):
count1+=1
if count1>0:
print('Please don\'t abuse!!! We at JUET don\'t tolerate it!!')
return
if(right.__contains__('yes') or right.__contains__('yup')):
flag=1
if(right.__contains__('no') or right.__contains__('nope')):
flag=0
if(flag==0):
print('Maybe I misunderstood you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
elif(flag==1):
print(doublr[c])
else:
print('Sorry I don\'t understand you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
else:
flag=-1
print('You mentioned '+c)
print('But I am not sure if you really want to know about it.')
print('Would you like to know about it??')
temp=input().lower()
if(temp=='y' or temp=='y '):
flag=1
if(temp=='n' or temp=='n '):
flag=0
if(flag==-1):
count1=0
right=[x for x in re.split('\W',temp) if x]
for x in right:
if those_words.__contains__(x):
count1+=1
if count1>0:
print('Please don\'t abuse!!! We at JUET don\'t tolerate it!!')
return
if(right.__contains__('yes') or right.__contains__('yup')):
flag=1
if(right.__contains__('no') or right.__contains__('nope')):
flag=0
if(flag==0):
print('Maybe I misunderstood you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
elif(flag==1):
print(doublr[c])
else:
print('Sorry I don\'t understand you.\nFor this query you can contact the reception to get your answer. The number is: 9876543210')
return
def main_like():
a=input().lower()
#a=a+' '
if(a==''):
main_like()
return
global b
b=[x for x in re.split('\W',a) if x]
y=len(b)
for i in range(0,y):
if(i<y-1 and weird.__contains__(b[i]) and b[i+1]=='t'):
del b[i+1]
b[i]=b[i]+"'"+"t"
count1=0
for x in b:
if those_words.__contains__(x):
count1+=1
if count1==0:
chatbatter(b)
else:
print('Please don\'t abuse!!! We at JUET don\'t tolerate it!!')
return
def chatbatter(b):
count2=0
for x in b:
if greet.__contains__(x):
c=x
count2+=1
if count2!=0:
print(greet[c])
count=0
global my_list
my_list=[]
for x in b:
if ans.__contains__(x):
my_list.append(x)
my_list=list(set(my_list))
count=len(my_list)
global doub_list
global foo
check()
if (len(doub_list)>0):
yo=0
length=len(doub_list)
if(len(doub_list)==1):
query(yo,2)
else:
for x in doub_list:
if(yo!=0):
print(random.choice(foo)+',')
if(yo!=length-1):
query(yo,2)
yo+=1
if(count>0):
ohcomeon_list=[]
for y in doub_list:
p=y.split()
ohcomeon_list.append(p[0])
ohcomeon_list.append(p[1])
ohcomeon_list=list(set(ohcomeon_list))
hellno=[]
for x in my_list:
if(not ohcomeon_list.__contains__(x)):
hellno.append(x)
length=len(hellno)
yo=0
my_list=hellno
if(len(doub_list)>1):
if(len(hellno)):
print("Also,")
else:
print("Lastly,")
query(len(doub_list)-1,2)
for x in hellno:
if(yo==length-1):
print("Lastly,")
else:
print(random.choice(foo)+',')
query(yo,1)
yo+=1
elif count==1:
query(0,1)
elif count==0 and count2==0:
print("Sorry i don't understand you.\nYou can call the college reception to get your answer.\nThe number is: 9876543210.")
elif count2!=0:
print('You can ask me queries related to new admissions.\nI can also tell you about Faculty members and placements!!')
else:
for yo in range(0,count):
if(yo==count-1):
print("Lastly,")
elif(yo!=0):
print(random.choice(foo)+',')
query(yo,1)
return
print('======================= Welcome to JUET FAQ Service ========================')
print('========================= I am a Reception Bot!!! ==========================')
print("====================I'll be taking new admission queries====================")
print("==You can also ask me about courses offered, placement and faculty members==")
print('================== Please try to make meaningful Queries ===================')
print('============================ I am still learning ===========================')
print("How may I help you?")
while True:
main_like()