-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
executable file
·290 lines (259 loc) · 9.53 KB
/
main.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
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
from pyswip import Prolog
import time
import json
def prolog_query(query_string):
prolog = Prolog()
prolog.consult("knowledge.pl")
results = []
for res in prolog.query(query_string):
results.append(res)
return results
def ask_question(query_string):
answers = prolog_query(query_string)
return answers
def make_json(data):
json_str = ""
for c in data:
if c == "'":
json_str += '"'
continue
json_str += c
return json_str
def say_answers(prefix, suffix, question_i, answers_i):
for ansi in answers_i:
ansi = make_json(str(ansi))
obj = json.loads(str(ansi))
print(obj[question_i])
text = prefix + " " + obj[question_i] + " " + suffix
print(">>>> ", text)
print(
"Hi, I'm here to tell you about jahangirnagar university. \
what do you want to know about jahangirnagar university?"
)
flg = True
while flg:
# Q/A
print("\n\n")
asked_question = str(input("what is in your mind: ")).lower()
if (
"name of the university" in asked_question
or "university name" in asked_question
):
# Q: what is the name of the university?
question = "UniversityName"
query = "name(" + question + ")."
answers = ask_question(query)
say_answers("The name of the university ", "", question, answers)
elif (
"introduction" in asked_question
or "about ju" in asked_question
or "about jahangirnagar university" in asked_question
):
# Q: what is jahangirnagar university?
question = "Introduction"
query = "introduction('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers("", "", question, answers)
elif (
"history of ju" in asked_question
or "history of jahangirnagar university" in asked_question
):
# Q: history of jahangirnagar university.
question = "History"
query = "history('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers("Brief history: ", "", question, answers)
elif (
"location of jahangirnagar university" in asked_question
or "situated" in asked_question
):
# Q: where is jahangirnagar university?
question = "Loction"
query = "location('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers("", "", question, answers)
elif "area of jahangirnagar university" in asked_question:
# Q: where is jahangirnagar university?
question = "Area"
query = "area('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"total area of jahangirnagar university is about ", "", question, answers
)
elif (
"current" in asked_question
or "present" in asked_question
or "now" in asked_question
) and ("vice chancellor" in asked_question or "vc" in asked_question):
# Q: who is the current vice_chancellor of jahangirnagar university?
question = "Vice_chancellor"
query = "vice_chancellor('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"The current vice chancellor of jahangirnagar university is ",
"",
question,
answers,
)
elif (
"number of faculties" in asked_question
or "how many faculties" in asked_question
and asked_question.find("faculty of") == -1
):
# Q how many faculties are in jahangirnagr university
question = "Number_of_faculties"
query = "number_of_faculties('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"There are ", "faculties in jahangirnagar university", question, answers
)
elif (
"number of departments" in asked_question
or "how many departments" in asked_question
):
# Q how many departments are in jahangirnagr university
question = "Number_of_departments"
query = "number_of_departments('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"There are ", "departments in jahangirnagar university", question, answers
)
elif (
"number of institutes" in asked_question
or "how many institutes" in asked_question
):
# Q how many institutes are in jahangirnagr university
question = "Number_of_institutes"
query = "number_of_institutes('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"There are ", "institutes in jahangirnagar university", question, answers
)
elif (
"names of the faculties" in asked_question
or "what are the faculties" in asked_question
):
# Q what are the faculties in jahangirnagar university
question = "Facultiy"
query = "faculties('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"there are 6 faculties are in jahangirnagar university, they are, ",
"",
question,
answers,
)
elif (
"names of the departments" in asked_question
or "what are the departments" in asked_question
) and "under the faculty of" in asked_question:
# Q what are the names departments in faculty of X?
faculties = [
"faculty of mathematical and physical science",
"faculty of biological science",
"faculty of social science",
"faculty of arts and humanities",
"faculty of business studies",
"faculty of law",
]
id = -1
for i in range(6):
if faculties[i] in asked_question:
id = i
break
if id != -1:
print(faculties[id])
question = "Departments"
query = (
"departments_under_faculty('jahangirnagar university', '"
+ faculties[id]
+ "',"
+ question
+ ")."
)
answers = ask_question(query)
print(">>>>> ", "the departments under " + faculties[id] + " are, ")
say_answers("", "", question, answers)
else:
print(">>>>> ", "sorry, there is no such faculty.")
elif (
"names of the departments" in asked_question
or "what are the departments" in asked_question
):
# Q what are the departments in jahangirnagar university
question = "Departments"
query = "departments('jahangirnagar university', " + question + ")."
answers = ask_question(query)
say_answers(
"there are 34 departments in jahangirnagar university, they are, ",
"",
question,
answers,
)
elif (
"about department of cse" in asked_question
or "about cse" in asked_question
or "about computer science and engineering" in asked_question
or "about department of computer science and engineering" in asked_question
):
# Q what you know about dept of CSE jahangirnagar university
question = "Cse"
query = (
"about_department_of_computer_science_and_engineering(\
'jahangirnagar university', "
+ question
+ ")."
)
answers = ask_question(query)
say_answers("", "", question, answers)
elif (
"chairman of department of cse" in asked_question
or "chairman of cse" in asked_question
or "chairman of computer science and engineering" in asked_question
or "chairman of department of computer science and engineering"
in asked_question
):
# Q who is the chairman of dept of CSE JU?
question = "Chairman"
query = (
"chairman_of_cse('department of computer science and engineering', "
+ question
+ ")."
)
answers = ask_question(query)
say_answers(
"",
"is the chairman of department of computer science and engineering",
question,
answers,
)
elif (
"who are the developers of this project" in asked_question
or "who developed" in asked_question
or "who created" in asked_question
):
# Q who developed this program?
question = "Developers"
query = "developers(" + question + ")."
answers = ask_question(query)
print(
">>>>> ",
"This project is supervised by professor doctor mohammad shorif uddin.",
)
say_answers("the developers are", "", question, answers)
elif "stop" in asked_question or "exit" in asked_question:
print(">>>>> ", "thank you, hope you have enjoyed the session")
break
else:
if asked_question != "-----------------":
confirmation = str(
input(
"Sorry, this is out of my knowledge. whould you like to continue? "
)
).lower()
if "no" in confirmation or "nope" in confirmation or "stop" in confirmation:
print(">>>>> ", "thank you, hope you have enjoyed the session")
break
else:
continue
time.sleep(2)