0


毕业设计——基于医疗大数据及neo4j构建知识图谱实现智慧医疗问诊系统

本项目采用python语言开发,基于医疗领域基础数据,通过图数据库neo4j构建医疗知识图谱,最终实现医疗问诊等功能。

一、引言
随着信息技术在医疗领域的不断深入应用,利用知识图谱实现医疗诊断问答功能成为了提升医疗服务效率和质量的重要手段。它能够帮助医护人员快速获取准确的诊断信息,也能辅助患者更好地了解自身健康状况。
二、基本架构
知识获取层

从多种医疗数据源收集信息,如医学文献、病历、临床指南等。这些数据源包含了丰富的医学知识,包括疾病症状、诊断方法、治疗方案等。
通过数据抽取技术,将非结构化和半结构化的医疗数据转化为结构化的数据形式,以便后续构建知识图谱。
知识图谱构建层
对抽取到的结构化数据进行知识融合,处理不同来源数据中可能存在的重复、冲突等问题,形成统一的知识表示。
利用图数据库(如 Neo4j 等)来存储知识图谱,其中节点表示医疗实体(如疾病、症状、药物等),边表示实体之间的关系(如疾病与症状的关联、药物与疾病的治疗关系等)。
问答处理层
接收用户的医疗诊断相关问题,对问题进行自然语言处理,包括词法分析、句法分析、语义理解等,将自然语言问题转化为能够在知识图谱中进行查询的形式。
根据转化后的查询语句在知识图谱中进行搜索和匹配,找到与问题相关的知识节点和关系路径,从而获取答案。
答案呈现层
将从知识图谱中获取到的答案进行整理和格式化,以清晰、易懂的方式呈现给用户,比如以文本描述、图表等形式展示疾病的诊断要点、治疗建议等。
三、相关技术
自然语言处理技术

词法分析:对输入的医疗诊断问题进行分词、词性标注等操作,例如将 “我最近经常头痛,可能是什么疾病?” 拆分成 “我”“最近”“经常”“头痛”“可能”“是”“什么”“疾病” 等词语,并标注出它们的词性。常用工具如 jieba 等。
句法分析:分析句子的语法结构,确定词语之间的依存关系,有助于理解问题的语义。例如,确定 “头痛” 在句子中是谓语动词 “是” 的主语等。
语义理解:通过词向量、深度学习模型(如 Transformer 架构的 BERT 等)来理解词语和句子的语义,将自然语言问题映射到知识图谱的语义空间中,以便准确查询相关知识。
知识抽取技术
实体抽取:从医疗文本中识别出重要的医疗实体,如疾病名称(如感冒、肺炎等)、症状(如发热、咳嗽等)、药物名称(如阿莫西林、布洛芬等)等。可以采用基于规则、机器学习(如支持向量机、条件随机场等)或深度学习(如命名实体识别的神经网络模型)的方法。
关系抽取:确定医疗实体之间的关系,比如某种疾病会导致哪些症状、某种药物能治疗哪种疾病等。关系抽取方法同样包括基于规则、机器学习和深度学习等多种途径。
知识融合技术
当整合来自不同数据源的医疗知识时,需要处理知识的重复、冲突等问题。可以采用基于相似度计算的方法来识别相似的知识片段,然后通过一定的规则或算法(如加权平均等)来融合这些知识,确保知识图谱中知识的一致性和准确性。
图数据库技术
图数据库(如 Neo4j、OrientDB 等)专门用于存储和管理知识图谱这种以图结构表示的数据。它具有高效的图查询能力,能够快速根据节点和边的关系在知识图谱中找到所需的知识路径,支持复杂的查询操作,适合医疗诊断问答中频繁的知识检索需求。
四、挑战与展望
数据质量挑战

医疗数据来源广泛,质量参差不齐,存在数据不完整、不准确、表述不规范等问题,这会影响知识图谱的构建质量和问答效果。需要加强数据清洗和预处理工作。
知识更新挑战
医学领域知识不断更新,新的疾病、治疗方法等不断涌现,知识图谱需要及时更新以反映最新的医学进展。但更新过程可能涉及到复杂的知识融合和验证工作。
语义理解挑战
医疗诊断问题往往具有复杂性和专业性,自然语言处理技术在准确理解其语义方面仍存在一定困难,尤其是对于一些模糊、隐含的表述。需要进一步提升语义理解模型的性能。
展望未来,随着人工智能技术的不断发展,特别是深度学习在自然语言处理和知识图谱领域的进一步深入应用,有望提升医疗诊断问答功能的准确性和实用性。同时,加强跨学科合作,促进医学专家、计算机科学家等共同参与知识图谱的构建和完善,也将推动这一领域的发展。

实现部分源码:

#!/usr/bin/env python3# coding: utf-8from py2neo import Graph

classAnswerSearching:def__init__(self):
        self.graph = Graph("http://localhost:7474", username="neo4j", password="123456789")
        self.top_num =10defquestion_parser(self, data):"""
        主要是根据不同的实体和意图构造cypher查询语句
        :param data: {"Disease":[], "Alias":[], "Symptom":[], "Complication":[]}
        :return:
        """
        sqls =[]if data:for intent in data["intentions"]:
                sql_ ={}
                sql_["intention"]= intent
                sql =[]if data.get("Disease"):
                   sql = self.transfor_to_sql("Disease", data["Disease"], intent)elif data.get("Alias"):
                    sql = self.transfor_to_sql("Alias", data["Alias"], intent)elif data.get("Symptom"):
                    sql = self.transfor_to_sql("Symptom", data["Symptom"], intent)elif data.get("Complication"):
                    sql = self.transfor_to_sql("Complication", data["Complication"], intent)if sql:
                    sql_['sql']= sql
                    sqls.append(sql_)return sqls

    deftransfor_to_sql(self, label, entities, intent):"""
        将问题转变为cypher查询语句
        :param label:实体标签
        :param entities:实体列表
        :param intent:查询意图
        :return:cypher查询语句
        """ifnot entities:return[]
        sql =[]# 查询症状if intent =="query_symptom"and label =="Disease":
            sql =["MATCH (d:Disease)-[:HAS_SYMPTOM]->(s) WHERE d.name='{0}' RETURN d.name,s.name".format(e)for e in entities]if intent =="query_symptom"and label =="Alias":
            sql =["MATCH (a:Alias)<-[:ALIAS_IS]-(d:Disease)-[:HAS_SYMPTOM]->(s) WHERE a.name='{0}' return " \
                   "d.name,s.name".format(e)for e in entities]# 查询治疗方法if intent =="query_cureway"and label =="Disease":
            sql =["MATCH (d:Disease)-[:HAS_DRUG]->(n) WHERE d.name='{0}' return d.name,d.treatment," \
                   "n.name".format(e)for e in entities]if intent =="query_cureway"and label =="Alias":
            sql =["MATCH (n)<-[:HAS_DRUG]-(d:Disease)-[]->(a:Alias) WHERE a.name='{0}' " \
                   "return d.name, d.treatment, n.name".format(e)for e in entities]if intent =="query_cureway"and label =="Symptom":
            sql =["MATCH (n)<-[:HAS_DRUG]-(d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' " \
                   "return d.name,d.treatment, n.name".format(e)for e in entities]if intent =="query_cureway"and label =="Complication":
            sql =["MATCH (n)<-[:HAS_DRUG]-(d:Disease)-[]->(c:Complication) WHERE c.name='{0}' " \
                   "return d.name,d.treatment, n.name".format(e)for e in entities]# 查询治疗周期if intent =="query_period"and label =="Disease":
            sql =["MATCH (d:Disease) WHERE d.name='{0}' return d.name,d.period".format(e)for e in entities]if intent =="query_period"and label =="Alias":
            sql =["MATCH (d:Disease)-[]->(a:Alias) WHERE a.name='{0}' return d.name,d.period".format(e)for e in entities]if intent =="query_period"and label =="Symptom":
            sql =["MATCH (d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' return d.name,d.period".format(e)for e in entities]if intent =="query_period"and label =="Complication":
            sql =["MATCH (d:Disease)-[]->(c:Complication) WHERE c.name='{0}' return d.name," \
                   "d.period".format(e)for e in entities]# 查询治愈率if intent =="query_rate"and label =="Disease":
            sql =["MATCH (d:Disease) WHERE d.name='{0}' return d.name,d.rate".format(e)for e in entities]if intent =="query_rate"and label =="Alias":
            sql =["MATCH (d:Disease)-[]->(a:Alias) WHERE a.name='{0}' return d.name,d.rate".format(e)for e in entities]if intent =="query_rate"and label =="Symptom":
            sql =["MATCH (d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' return d.name,d.rate".format(e)for e in entities]if intent =="query_rate"and label =="Complication":
            sql =["MATCH (d:Disease)-[]->(c:Complication) WHERE c.name='{0}' return d.name," \
                   "d.rate".format(e)for e in entities]# 查询检查项目if intent =="query_checklist"and label =="Disease":
            sql =["MATCH (d:Disease) WHERE d.name='{0}' return d.name,d.checklist".format(e)for e in entities]if intent =="query_checklist"and label =="Alias":
            sql =["MATCH (d:Disease)-[]->(a:Alias) WHERE a.name='{0}' return d.name,d.checklist".format(e)for e in entities]if intent =="query_checklist"and label =="Symptom":
            sql =["MATCH (d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' return d.name," \
                   "d.checklist".format(e)for e in entities]if intent =="query_checklist"and label =="Complication":
            sql =["MATCH (d:Disease)-[]->(c:Complication) WHERE c.name='{0}' return d.name," \
                   "d.checklist".format(e)for e in entities]# 查询科室if intent =="query_department"and label =="Disease":
            sql =["MATCH (d:Disease)-[:DEPARTMENT_IS]->(n) WHERE d.name='{0}' return d.name," \
                   "n.name".format(e)for e in entities]if intent =="query_department"and label =="Alias":
            sql =["MATCH (n)<-[:DEPARTMENT_IS]-(d:Disease)-[:ALIAS_IS]->(a:Alias) WHERE a.name='{0}' " \
                   "return d.name,n.name".format(e)for e in entities]if intent =="query_department"and label =="Symptom":
            sql =["MATCH (n)<-[:DEPARTMENT_IS]-(d:Disease)-[:HAS_SYMPTOM]->(s:Symptom) WHERE s.name='{0}' " \
                   "return d.name,n.name".format(e)for e in entities]if intent =="query_department"and label =="Complication":
            sql =["MATCH (n)<-[:DEPARTMENT_IS]-(d:Disease)-[:HAS_COMPLICATION]->(c:Complication) WHERE " \
                   "c.name='{0}' return d.name,n.name".format(e)for e in entities]# 查询疾病if intent =="query_disease"and label =="Alias":
            sql =["MATCH (d:Disease)-[]->(s:Alias) WHERE s.name='{0}' return " \
                   "d.name".format(e)for e in entities]if intent =="query_disease"and label =="Symptom":
            sql =["MATCH (d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' return " \
                   "d.name".format(e)for e in entities]# 查询疾病描述if intent =="disease_describe"and label =="Alias":
            sql =["MATCH (d:Disease)-[]->(a:Alias) WHERE a.name='{0}' return d.name,d.age," \
                   "d.insurance,d.infection,d.checklist,d.period,d.rate,d.money".format(e)for e in entities]if intent =="disease_describe"and label =="Disease":
            sql =["MATCH (d:Disease) WHERE d.name='{0}' return d.name,d.age,d.insurance,d.infection," \
                   "d.checklist,d.period,d.rate,d.money".format(e)for e in entities]if intent =="disease_describe"and label =="Symptom":
            sql =["MATCH (d:Disease)-[]->(s:Symptom) WHERE s.name='{0}' return d.name,d.age," \
                   "d.insurance,d.infection,d.checklist,d.period,d.rate,d.money".format(e)for e in entities]if intent =="disease_describe"and label =="Complication":
            sql =["MATCH (d:Disease)-[]->(c:Complication) WHERE c.name='{0}' return d.name," \
                   "d.age,d.insurance,d.infection,d.checklist,d.period,d.rate,d.money".format(e)for e in entities]return sql

    defsearching(self, sqls):"""
        执行cypher查询,返回结果
        :param sqls:
        :return:str
        """
        final_answers =[]for sql_ in sqls:
            intent = sql_['intention']
            queries = sql_['sql']
            answers =[]for query in queries:
                ress = self.graph.run(query).data()
                answers += ress
            final_answer = self.answer_template(intent, answers)if final_answer:
                final_answers.append(final_answer)return final_answers

    defanswer_template(self, intent, answers):"""
        根据不同意图,返回不同模板的答案
        :param intent: 查询意图
        :param answers: 知识图谱查询结果
        :return: str
        """
        final_answer =""ifnot answers:return""# 查询症状if intent =="query_symptom":
            disease_dic ={}for data in answers:
                d = data['d.name']
                s = data['s.name']if d notin disease_dic:
                    disease_dic[d]=[s]else:
                    disease_dic[d].append(s)
            i =0for k, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 的症状有:{1}\n".format(k,','.join(list(set(v))))
                i +=1# 查询疾病if intent =="query_disease":
            disease_freq ={}for data in answers:
                d = data["d.name"]
                disease_freq[d]= disease_freq.get(d,0)+1
            n =len(disease_freq.keys())
            freq =sorted(disease_freq.items(), key=lambda x: x[1], reverse=True)for d, v in freq[:10]:
                final_answer +="疾病为 {0} 的概率为:{1}\n".format(d, v/10)# 查询治疗方法if intent =="query_cureway":
            disease_dic ={}for data in answers:
                disease = data['d.name']
                treat = data["d.treatment"]
                drug = data["n.name"]if disease notin disease_dic:
                    disease_dic[disease]=[treat, drug]else:
                    disease_dic[disease].append(drug)
            i =0for d, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 的治疗方法有:{1};可用药品包括:{2}\n".format(d, v[0],','.join(v[1:]))
                i +=1# 查询治愈周期if intent =="query_period":
            disease_dic ={}for data in answers:
                d = data['d.name']
                p = data['d.period']if d notin disease_dic:
                    disease_dic[d]=[p]else:
                    disease_dic[d].append(p)
            i =0for k, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 的治愈周期为:{1}\n".format(k,','.join(list(set(v))))
                i +=1# 查询治愈率if intent =="query_rate":
            disease_dic ={}for data in answers:
                d = data['d.name']
                r = data['d.rate']if d notin disease_dic:
                    disease_dic[d]=[r]else:
                    disease_dic[d].append(r)
            i =0for k, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 的治愈率为:{1}\n".format(k,','.join(list(set(v))))
                i +=1# 查询检查项目if intent =="query_checklist":
            disease_dic ={}for data in answers:
                d = data['d.name']
                r = data['d.checklist']if d notin disease_dic:
                    disease_dic[d]=[r]else:
                    disease_dic[d].append(r)
            i =0for k, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 的检查项目有:{1}\n".format(k,','.join(list(set(v))))
                i +=1# 查询科室if intent =="query_department":
            disease_dic ={}for data in answers:
                d = data['d.name']
                r = data['n.name']if d notin disease_dic:
                    disease_dic[d]=[r]else:
                    disease_dic[d].append(r)
            i =0for k, v in disease_dic.items():if i >=10:break
                final_answer +="疾病 {0} 所属科室有:{1}\n".format(k,','.join(list(set(v))))
                i +=1# 查询疾病描述if intent =="disease_describe":
            disease_infos ={}for data in answers:
                name = data['d.name']
                age = data['d.age']
                insurance = data['d.insurance']
                infection = data['d.infection']
                checklist = data['d.checklist']
                period = data['d.period']
                rate = data['d.rate']
                money = data['d.money']if name notin disease_infos:
                    disease_infos[name]=[age, insurance, infection, checklist, period, rate, money]else:
                    disease_infos[name].extend([age, insurance, infection, checklist, period, rate, money])
            i =0for k, v in disease_infos.items():if i >=10:break
                message ="疾病 {0} 的描述信息如下:\n发病人群:{1}\n医保:{2}\n传染性:{3}\n检查项目:{4}\n" \
                          "治愈周期:{5}\n治愈率:{6}\n费用:{7}\n"
                final_answer += message.format(k, v[0], v[1], v[2], v[3], v[4], v[5], v[6])
                i +=1return final_answer

基础界面展示:
在这里插入图片描述


本文转载自: https://blog.csdn.net/zy_dreamer/article/details/144203457
版权归原作者 白话机器学习 所有, 如有侵权,请联系我们删除。

“毕业设计——基于医疗大数据及neo4j构建知识图谱实现智慧医疗问诊系统”的评论:

还没有评论