2018-10-04 17:15:27 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# coding: utf-8
|
|
|
|
|
# File: chatbot_graph.py
|
|
|
|
|
# Author: lhy<lhy_in_blcu@126.com,https://huangyong.github.io>
|
|
|
|
|
# Date: 18-10-4
|
|
|
|
|
|
2018-10-04 23:28:23 +08:00
|
|
|
|
from question_classifier import *
|
|
|
|
|
from question_parser import *
|
2018-10-05 12:12:19 +08:00
|
|
|
|
from answer_search import *
|
2018-10-04 23:28:23 +08:00
|
|
|
|
|
2018-10-05 17:20:22 +08:00
|
|
|
|
'''问答类'''
|
2018-10-04 17:15:27 +08:00
|
|
|
|
class ChatBotGraph:
|
|
|
|
|
def __init__(self):
|
2018-10-04 23:28:23 +08:00
|
|
|
|
self.classifier = QuestionClassifier()
|
|
|
|
|
self.parser = QuestionPaser()
|
2018-10-05 12:12:19 +08:00
|
|
|
|
self.searcher = AnswerSearcher()
|
2018-10-04 23:28:23 +08:00
|
|
|
|
|
|
|
|
|
def chat_main(self, sent):
|
2018-10-05 17:20:22 +08:00
|
|
|
|
answer = '您好,我是小勇医药智能助理,希望可以帮到您。如果没答上来,可联系https://liuhuanyong.github.io/。祝您身体棒棒!'
|
2018-10-04 23:28:23 +08:00
|
|
|
|
res_classify = self.classifier.classify(sent)
|
|
|
|
|
if not res_classify:
|
2018-10-05 17:20:22 +08:00
|
|
|
|
return answer
|
2018-10-05 12:12:19 +08:00
|
|
|
|
res_sql = self.parser.parser_main(res_classify)
|
2018-10-05 17:20:22 +08:00
|
|
|
|
final_answers = self.searcher.search_main(res_sql)
|
|
|
|
|
if not final_answers:
|
|
|
|
|
return answer
|
|
|
|
|
else:
|
|
|
|
|
return '\n'.join(final_answers)
|
2018-10-04 23:28:23 +08:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
handler = ChatBotGraph()
|
2018-10-05 12:12:19 +08:00
|
|
|
|
while 1:
|
2018-10-05 17:20:22 +08:00
|
|
|
|
question = input('user:')
|
|
|
|
|
answer = handler.chat_main(question)
|
|
|
|
|
print('RoBot:', answer)
|
2018-10-05 12:12:19 +08:00
|
|
|
|
|