-
Notifications
You must be signed in to change notification settings - Fork 2
/
chatbot_graph.py
33 lines (27 loc) · 1.08 KB
/
chatbot_graph.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
from question_classifier import *
from question_parser import *
from answer_search import *
'''问答类'''
class ChatBotGraph:
def __init__(self):
self.classifier = QuestionClassifier()
self.parser = QuestionPaser()
self.searcher = AnswerSearcher()
def chat_main(self, sent):
unkown_answer = '您的这个问题我还不知道哦,请您换个问法试试吧!'
res_classify = self.classifier.classify(sent)
if not res_classify:
return unkown_answer
res_sql = self.parser.parser_main(res_classify)
final_answers = self.searcher.search_main(res_sql)
if not final_answers:
return unkown_answer
else:
return '\n'.join(final_answers)
if __name__ == '__main__':
handler = ChatBotGraph()
print('您好,我是心卫士医药智能助理,希望可以帮到您。本问答系统仅供参考,请谨遵医嘱。祝您身体棒棒!')
while 1:
question = input('用户:')
answer = handler.chat_main(question)
print('心卫士:', answer)