当前位置:网站首页>[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part5 end): information retrieval and result assembly
[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part5 end): information retrieval and result assembly
2022-07-25 16:52:00 【Coriander Chrysanthemum】
Preface article :
- 【 Knowledge map 】 Practice chapter —— Practice of question answering system based on medical knowledge map (Part1): Project introduction and environmental preparation
- 【 Knowledge map 】 Practice chapter —— Practice of question answering system based on medical knowledge map (Part2): Atlas data preparation and import
- 【 Knowledge map 】 Practice chapter —— Practice of question answering system based on medical knowledge map (Part3): Rule based problem classification
- 【 Knowledge map 】 Practice chapter —— Practice of question answering system based on medical knowledge map (Part4): Problem analysis and retrieval statement generation combined with problem classification
background
In the previous modules, we have completed the problem classification 、 Problem analysis and the generation of information retrieval statements required by the problem . Now let's string these modules , Then assemble the results .
Result assembly
Result assembly is to output corresponding results according to different types of problems , The specific implementation is as follows :
KGQAMedicine\answer_search\raw_answer_search.py
from utils.config import SysConfig
from py2neo import Graph
class RawAnswerSearcher(object):
def __init__(self):
self.graph = Graph(SysConfig.NEO4J_HOST + ":" + str(SysConfig.NEO4J_PORT), auth=(SysConfig.NEO4J_USER,
SysConfig.NEO4J_PASSWORD))
self.num_limit = 20
def search(self, sql_list: list):
final_answers = []
for sql in sql_list:
question_kind = sql['question_kind']
answers = []
for query in sql['sql']:
query_result = self.graph.run(query).data()
answers += query_result
final_answer = self._answer_standard(question_kind, answers)
if final_answer:
final_answers.append(final_answer)
return final_answers
def _answer_standard(self, question_kind, answers):
final_answer = []
if not answers:
return ''
if question_kind == 'disease_symptom':
desc = [i['n.name'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Symptoms include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'symptom_disease':
desc = [i['m.name'] for i in answers]
subject = answers[0]['n.name']
final_answer = ' symptoms {0} Possible diseases are :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_cause':
desc = [i['m.cause'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Possible causes are :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_prevent':
desc = [i['m.prevent'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Preventive measures include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_lasttime':
desc = [i['m.cure_lasttime'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} The possible duration of treatment is :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_cureway':
desc = [';'.join(i['m.cure_way']) for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Try the following treatment :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_cureprob':
desc = [i['m.cured_prob'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} The probability of cure is ( For reference only ):{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_easyget':
desc = [i['m.easy_get'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} The susceptible groups include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_desc':
desc = [i['m.desc'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0}, Be familiar with it. :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_acompany':
desc1 = [i['n.name'] for i in answers]
desc2 = [i['m.name'] for i in answers]
subject = answers[0]['m.name']
desc = [i for i in desc1 + desc2 if i != subject]
final_answer = '{0} Symptoms include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_not_food':
desc = [i['n.name'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Taboo foods include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_do_food':
do_desc = [i['n.name'] for i in answers if i['r.name'] == ' Suitable for eating ']
recommand_desc = [i['n.name'] for i in answers if i['r.name'] == ' Recommended recipes ']
subject = answers[0]['m.name']
final_answer = '{0} Edible foods include :{1}\n Recommended recipes include :{2}'.format(subject, ';'.join(list(set(do_desc))[:self.num_limit]),
';'.join(list(set(recommand_desc))[:self.num_limit]))
elif question_kind == 'food_not_disease':
desc = [i['m.name'] for i in answers]
subject = answers[0]['n.name']
final_answer = ' suffer from {0} You'd better not eat it {1}'.format(';'.join(list(set(desc))[:self.num_limit]), subject)
elif question_kind == 'food_do_disease':
desc = [i['m.name'] for i in answers]
subject = answers[0]['n.name']
final_answer = ' suffer from {0} People suggest trying more {1}'.format(';'.join(list(set(desc))[:self.num_limit]), subject)
elif question_kind == 'disease_drug':
desc = [i['n.name'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} Commonly used drugs include :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'drug_disease':
desc = [i['m.name'] for i in answers]
subject = answers[0]['n.name']
final_answer = '{0} The main diseases are {1}, You can try '.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'disease_check':
desc = [i['n.name'] for i in answers]
subject = answers[0]['m.name']
final_answer = '{0} It can usually be checked in the following ways :{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
elif question_kind == 'check_disease':
desc = [i['m.name'] for i in answers]
subject = answers[0]['n.name']
final_answer = ' Usually it can be done by {0} The diseases detected are {1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))
return final_answer
Module assembly and question and answer class construction
This module will pipline Assemble the modules in . As follows :
KGQAMedicine\chatbot.py
from question_classify.rule_question_classify import RuleQuestionClassifier
from question_parser.rule_question_parser import RuleQuestionParser
from answer_search.raw_answer_search import RawAnswerSearcher
class ChatBot(object):
def __init__(self):
self.classifier = RuleQuestionClassifier()
self.parser = RuleQuestionParser()
self.answer_generate = RawAnswerSearcher()
self.common_answer = " Hello! , I'm kopi Ziju's medical personal assistant , I hope I can answer for you . If the answer is not satisfactory , Can pass :https://github.com/Htring Contact me . I wish you good health , Stay away from me !"
def answer(self, question):
question_classify = self.classifier.classify(question)
if not question_classify:
return self.common_answer
res_sql = self.parser.parser(question_classify)
final_answers = self.answer_generate.search(res_sql)
if not final_answers:
return self.common_answer
else:
return "\n".join(final_answers)
if __name__ == '__main__':
chat_bot = ChatBot()
while True:
question = input(" user :")
answer = chat_bot.answer(question)
print(" Coreopsis :", answer)
Effect display :
summary
In general , This project uses knowledge maps QA Some of the processes are introduced quite clearly , But in the process of completing the question and answer, the technology is relatively old , But the effect is still good . The source code has been put into my github On :https://github.com/Htring/KGQAMedicine, If you are interested, you can download and run it , There is operation introduction on it .
In order to further improve the effect, many new technologies can be introduced . For example, the problem classification method based on deep learning can be introduced in the problem classification link , During problem analysis , Deep learning based NER Entity recognition method and further entity alignment , There is no further development here .
besides , The construction of knowledge map needs to be combined with business needs , That is, when receiving the business and analyzing the existing data, then building a business based schema, Then build the knowledge map through the related technology of natural language processing . In the original project , Use crawler to crawl data , It can also be used NLP Relevant basis , Optimize the extracted data and so on .
Xiongguan road is like iron , Now we are going to start again . Just getting started , A new start . In the future, we will add more content based on deep learning algorithm to the construction of knowledge map , Application etc. .
边栏推荐
- Hcip notes 11 days
- Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?
- [target detection] yolov5 Runtong visdrone data set
- unity 最好用热更方案卧龙 wolong
- 聊聊如何用 Redis 实现分布式锁?
- 测试框架-unittest-测试套件、结果输出到文件
- Chain game development ready-made version chain game system development detailed principle chain game source code delivery
- jenkins的Role-based Authorization Strategy安装配置
- 【南京航空航天大学】考研初试复试资料分享
- ReBudget:通过运行时重新分配预算的方法,在基于市场的多核资源分配中权衡效率与公平性
猜你喜欢

【目标检测】TPH-YOLOv5:基于transformer的改进yolov5的无人机目标检测

mindoc制作思维导图

Fudan University emba2022 graduation season - graduation does not forget the original intention and glory to embark on the journey again

Birui data joins Alibaba cloud polardb open source database community

ReBudget:通过运行时重新分配预算的方法,在基于市场的多核资源分配中权衡效率与公平性

3D语义分割——PVD

Rebudget: balance efficiency and fairness in market-based multi-core resource allocation by reallocating the budget at run time

中国芯片自给率大幅提升,导致外国芯片库存高企而损失惨重,美国芯片可谓捧起石头砸自己的脚...

如何使用 4EVERLAND CLI 在 IPFS 上部署应用程序

Multi tenant software development architecture
随机推荐
华泰vip账户证券开户安全吗
从数字化到智能运维:有哪些价值,又有哪些挑战?
在华为昇腾Ascend910上复现swin_transformer
[cloud co creation] explore how gaussdb helps ICBC create core financial data
Jenkins' file parameters can be used to upload files
[redis] redis installation
Enterprise live broadcast: witness focused products, praise and embrace ecology
7.依赖注入
How to deploy applications on IPFs using 4everland cli
企业直播风起:目睹聚焦产品,微赞拥抱生态
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part3):基于规则的问题分类
【目标检测】YOLOv5跑通VisDrone数据集
复旦大学EMBA2022毕业季丨毕业不忘初心 荣耀再上征程
Fudan University emba2022 graduation season - graduation does not forget the original intention and glory to embark on the journey again
Rebudget: balance efficiency and fairness in market-based multi-core resource allocation by reallocating the budget at run time
基于redis6.2.4的redis cluster部署
[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart
GTX1080Ti 光纤HDMI干扰出现闪屏1080Ti 闪屏解决方法
win10如何删除微软拼音输入法
WPF 实现用户头像选择器