-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
63 lines (51 loc) · 1.79 KB
/
test.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
from subject import Subject
import numpy as np
import os
def speak(msg):
print('\tawesomebot\t> ' + msg)
def load_files(subject_type):
topics = {}
for filename in os.listdir(subject_type):
if '.txt' in filename:
filename = filename.replace('.txt', '')
path = subject_type + '/' + filename + '.txt'
topics[filename] = Subject(filename, subject_type)
return topics
subjects = {}
subjects_list = []
''' SUBJECT IMPORT '''
# Load all conditions and medicines looping into conditions/medicines folders
#conditions = load_files('conditions')
#medicines = load_files('medicines')
#subjects = {**conditions, **medicines}
test = load_files('test')
subjects = {**test}
''' SUBJECT IMPORT '''
for subject in subjects:
subjects_list.append(subject)
flag = True
speak('Hello, I\'m awesomebot, ask me anything about medecines or conditions!')
curr_subject = ''
while flag == True:
user_response = input('\tuser\t\t> ')
user_response = user_response.lower()
stop_search = False
for word in user_response.split(' '):
for subject in subjects_list:
if word == subject.split(' ')[0]:
if subject != curr_subject:
curr_subject = subject
print('\t[DEBUG]\t\t> new subject :' + curr_subject)
stop_search = True
break
if stop_search == True:
break
if 'bye' not in user_response:
if curr_subject == '':
speak('On what medicine or condition do you want to talk about ?')
else:
speak(subjects[curr_subject].response(user_response))
subjects[curr_subject].sent_tokens.remove(user_response)
else:
flag = False
speak('Take care !')