QASystemOnMedicalKG/chatbot_graph.py

36 lines
933 B
Python
Raw Normal View History

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
import os
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-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):
answer = '对不起,小生愚钝,祝您身体健康!每天开开心心的....'
res_classify = self.classifier.classify(sent)
if not res_classify:
2018-10-05 12:12:19 +08:00
return
res_sql = self.parser.parser_main(res_classify)
print(res_sql)
self.searcher.search_main(res_sql)
2018-10-04 23:28:23 +08:00
if __name__ == '__main__':
handler = ChatBotGraph()
2018-10-05 12:12:19 +08:00
while 1:
question = input('enter an question to search:')
handler.chat_main(question)