医疗知识图谱问答——文本分类解析

news2024/12/24 2:39:36

前言

        Neo4j的数据库构建完成后,现在就是要实现医疗知识的解答功能了。因为是初版,这里的问题解答不会涉及深度学习,目前只是一个条件查询的过程。而这个过程包括对问题的关键词拆解分类,然后提取词语和类型去图数据库查询,最后就是根据查询结果和问题类型组装语言完成回答,那么以下就是完成这个过程的全部代码流程了。

环境

        这里所需的环境除了前面提到的外,还需要ahocorasick库,用于从问题中提取关键词。另一个是colorama,用于给输出面板文字美化的库。

编码

1. 问答面板

from colorama import init,Fore,Style,Back
from classifier import Classifier
from parse import Parse
from answer import Answer

class ChatRobot:
    def __init__(self):
        init(autoreset=True)
        print("====================================")
        print(Back.BLUE+"欢迎进入智慧医疗问答面板!")
        print("====================================")

    def main(self, question):
        print("")

        default_answer = "您好,小北知识有限,暂时回答不上来,正在努力迭代中!"
        final_classify = Classifier().classify(question)
        parse_sql = Parse().main(final_classify)
        final_answer = Answer().main(parse_sql)

        if not final_answer:
            return default_answer

        return "\n\n".join(final_answer)

if __name__ == "__main__":
    robot = ChatRobot()
    while 1:
        print(" ")
        question = input("您问:")

        if "关闭" in question:
            print("")
            print("小北说:", "好的,已经关闭了哦,欢迎您下次提问~")
            break;

        answer = robot.main(question)

        print(Fore.LIGHTRED_EX+"小北答:", Fore.GREEN + answer)

2. 问题归类

import ahocorasick

class Classifier:
    def __init__(self):
        # print("开始初始化:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        self.checks_wds = [i.strip() for i in open("dict/checks.txt", encoding="utf-8", mode="r") if i.strip()]
        self.departments_wds = [i.strip() for i in open("dict/departments.txt", encoding="utf-8", mode="r") if i.strip()]
        self.diseases_wds = [i.strip() for i in open("dict/diseases.txt", encoding="utf-8", mode="r") if i.strip()]
        self.drugs_wds = [i.strip() for i in open("dict/drugs.txt", encoding="utf-8", mode="r") if i.strip()]
        self.foods_wds = [i.strip() for i in open("dict/foods.txt", encoding="utf-8", mode="r") if i.strip()]
        self.producers_wds = [i.strip() for i in open("dict/producers.txt", encoding="utf-8", mode="r") if i.strip()]
        self.symptoms_wds = [i.strip() for i in open("dict/symptoms.txt", encoding="utf-8", mode="r") if i.strip()]
        self.features_wds = set(self.checks_wds+self.departments_wds+self.diseases_wds+self.drugs_wds+self.foods_wds+self.producers_wds+self.symptoms_wds)
        self.deny_words = [name.strip() for name in open("dict/deny.txt", encoding="utf-8", mode="r") if name.strip()]

        # actree 从输入文本中提取出指定分词表中的词
        self.actree = self.build_actree(list(self.features_wds))

        # 给每个词创建类型词典(相当慢的操作)
        self.wds_dict = self.build_words_dict()
        # print("给每个词创建类型词典结束:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

        # 问句疑问词
        self.symptom_qwds = ['症状', '表征', '现象', '症候', '表现']
        self.cause_qwds = ['原因', '成因', '为什么', '怎么会', '怎样才', '咋样才', '怎样会', '如何会', '为啥', '为何', '如何才会', '怎么才会', '会导致',
                           '会造成']
        self.acompany_qwds = ['并发症', '并发', '一起发生', '一并发生', '一起出现', '一并出现', '一同发生', '一同出现', '伴随发生', '伴随', '共现']
        self.food_qwds = ['饮食', '饮用', '吃', '食', '伙食', '膳食', '喝', '菜', '忌口', '补品', '保健品', '食谱', '菜谱', '食用', '食物', '补品']
        self.drug_qwds = ['药', '药品', '用药', '胶囊', '口服液', '炎片']
        self.prevent_qwds = ['预防', '防范', '抵制', '抵御', '防止', '躲避', '逃避', '避开', '免得', '逃开', '避开', '避掉', '躲开', '躲掉', '绕开',
                             '怎样才能不', '怎么才能不', '咋样才能不', '咋才能不', '如何才能不',
                             '怎样才不', '怎么才不', '咋样才不', '咋才不', '如何才不',
                             '怎样才可以不', '怎么才可以不', '咋样才可以不', '咋才可以不', '如何可以不',
                             '怎样才可不', '怎么才可不', '咋样才可不', '咋才可不', '如何可不']
        self.lasttime_qwds = ['周期', '多久', '多长时间', '多少时间', '几天', '几年', '多少天', '多少小时', '几个小时', '多少年']
        self.cureway_qwds = ['怎么治疗', '如何医治', '怎么医治', '怎么治', '怎么医', '如何治', '医治方式', '疗法', '咋治', '怎么办', '咋办', '咋治']
        self.cureprob_qwds = ['多大概率能治好', '多大几率能治好', '治好希望大么', '几率', '几成', '比例', '可能性', '能治', '可治', '可以治', '可以医']
        self.easyget_qwds = ['易感人群', '容易感染', '易发人群', '什么人', '哪些人', '感染', '染上', '得上']
        self.check_qwds = ['检查', '检查项目', '查出', '检查', '测出', '试出']
        self.belong_qwds = ['属于什么科', '属于', '什么科', '科室']
        self.cure_qwds = ['治疗什么', '治啥', '治疗啥', '医治啥', '治愈啥', '主治啥', '主治什么', '有什么用', '有何用', '用处', '用途',
                          '有什么好处', '有什么益处', '有何益处', '用来', '用来做啥', '用来作甚', '需要', '要']

    '''构造actree,加速过滤'''
    def build_actree(self, wordlist):
        actree = ahocorasick.Automaton()
        for index, word in enumerate(wordlist):
            actree.add_word(word, (index, word))
        actree.make_automaton()
        return actree

    # 构建特征词属性
    def build_words_dict(self):
        words_dict = {}
        check_words = set(self.checks_wds)
        department_words = set(self.departments_wds)
        disease_words = set(self.diseases_wds)
        drug_words = set(self.drugs_wds)
        food_words = set(self.foods_wds)
        producer_words = set(self.producers_wds)
        symptom_words = set(self.symptoms_wds)

        for word in self.features_wds:
            words_dict[word] = []
            if word in check_words:
                words_dict[word].append("check")
            if word in department_words:
                words_dict[word].append("department")
            if word in disease_words:
                words_dict[word].append("disease")
            if word in drug_words:
                words_dict[word].append("drug")
            if word in food_words:
                words_dict[word].append("food")
            if word in producer_words:
                words_dict[word].append("producer")
            if word in symptom_words:
                words_dict[word].append("symptom")

        return words_dict

    # 根据输入返回问题类型
    def classify(self, sent):
        # 最终输入给解析器的字典
        data = {}
        region_words = []
        lists = self.actree.iter(sent)
        for ii in lists:
            cur_word = ii[1][1]
            region_words.append(cur_word)

        # {'职业黑变病': ['diseases'], '倒睫': ['diseases', 'symptom']}
        final_dict = {i_name: self.wds_dict.get(i_name) for i_name in region_words}

        data['args'] = final_dict
        question_type = "other"
        questions_type = []

        # ['diseases', 'diseases', 'symptom']
        type = []
        for i_type in final_dict.values():
            type += i_type

        # 判断type中是否有指定类型, 提出的问题是否包含指定的修饰词,给问题定类型
        # 1. 如提问词是否出现状态词语,那就是问某种疾病会出现什么症状
        if self.check_word_exist(self.symptom_qwds, sent) and ('disease' in type):
            question_type = "disease_symptom"
            questions_type.append(question_type)

        # 根据症状问疾病
        if self.check_word_exist(self.symptom_qwds, sent) and ('symptom' in type):
            question_type = "symptom_disease"
            questions_type.append(question_type)

        # 原因
        if self.check_word_exist(self.cause_qwds, sent) and ('disease' in type):
            question_type = 'disease_cause'
            questions_type.append(question_type)

        # 并发症
        if self.check_word_exist(self.acompany_qwds, sent) and ('disease' in type):
            question_type = 'disease_acompany'
            questions_type.append(question_type)

        # 推荐食品
        if self.check_word_exist(self.food_qwds, sent) and 'disease' in type:
            deny_status = self.check_word_exist(self.deny_words, sent)
            if deny_status:
                question_type = 'disease_not_food'
            else:
                question_type = 'disease_do_food'
            questions_type.append(question_type)

        # 已知食物找疾病
        if self.check_word_exist(self.food_qwds + self.cure_qwds, sent) and 'food' in type:
            deny_status = self.check_word_exist(self.deny_words, sent)
            if deny_status:
                question_type = 'food_not_disease'
            else:
                question_type = 'food_do_disease'
            questions_type.append(question_type)

        # 推荐药品
        if self.check_word_exist(self.drug_qwds, sent) and 'disease' in type:
            question_type = 'disease_drug'
            questions_type.append(question_type)

        # 药品治啥病
        if self.check_word_exist(self.cure_qwds, sent) and 'drug' in type:
            question_type = 'drug_disease'
            questions_type.append(question_type)

        # 疾病接受检查项目
        if self.check_word_exist(self.check_qwds, sent) and 'disease' in type:
            question_type = 'disease_check'
            questions_type.append(question_type)

        # 已知检查项目查相应疾病
        if self.check_word_exist(self.check_qwds + self.cure_qwds, sent) and 'check' in type:
            question_type = 'check_disease'
            questions_type.append(question_type)

        #  症状防御
        if self.check_word_exist(self.prevent_qwds, sent) and 'disease' in type:
            question_type = 'disease_prevent'
            questions_type.append(question_type)

        # 疾病医疗周期
        if self.check_word_exist(self.lasttime_qwds, sent) and 'disease' in type:
            question_type = 'disease_lasttime'
            questions_type.append(question_type)

        # 疾病治疗方式
        if self.check_word_exist(self.cureway_qwds, sent) and 'disease' in type:
            question_type = 'disease_cureway'
            questions_type.append(question_type)

        # 疾病治愈可能性
        if self.check_word_exist(self.cureprob_qwds, sent) and 'disease' in type:
            question_type = 'disease_cureprob'
            questions_type.append(question_type)

        # 疾病易感染人群
        if self.check_word_exist(self.easyget_qwds, sent) and 'disease' in type:
            question_type = 'disease_easyget'
            questions_type.append(question_type)

        # 若没有查到相关的外部查询信息,那么则将该疾病的描述信息返回
        if questions_type == [] and 'disease' in type:
            questions_type = ['disease_desc']

        # 若没有查到相关的外部查询信息,那么则将该疾病的描述信息返回
        if questions_type == [] and 'symptom' in type:
            questions_type = ['symptom_disease']

        # 将多个分类结果进行合并处理,组装成一个字典
        data['question_types'] = questions_type

        return data

    def check_word_exist(self, word_list, words):
        for item in word_list:
            if item in words:
                return True

        return False

3. 类型解析(查询组装)


class Parse:

    def main(self, classify):
        entity = classify['args']
        questions_type = classify['question_types']
        entity_dict = self.entity_transform(entity)

        sqls = []
        for question in questions_type:
            sql_dict = {}
            sql_dict["qustion_type"] = question
            sql_dict["sql"] = []
            sql = []
            if question == 'disease_symptom':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'symptom_disease':
                sql = self.sql_transfer(question, entity_dict.get('symptom'))

            elif question == 'disease_cause':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_acompany':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_not_food':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_do_food':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'food_not_disease':
                sql = self.sql_transfer(question, entity_dict.get('food'))

            elif question == 'food_do_disease':
                sql = self.sql_transfer(question, entity_dict.get('food'))

            elif question == 'disease_drug':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'drug_disease':
                sql = self.sql_transfer(question, entity_dict.get('drug'))

            elif question == 'disease_check':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'check_disease':
                sql = self.sql_transfer(question, entity_dict.get('check'))

            elif question == 'disease_prevent':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_lasttime':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_cureway':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_cureprob':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_easyget':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            elif question == 'disease_desc':
                sql = self.sql_transfer(question, entity_dict.get('disease'))

            if sql:
                sql_dict['sql'] = sql

                sqls.append(sql_dict)

        return sqls

    def sql_transfer(self, question_type, entities):
        # 查询语句
        sql = []
        # 查询疾病的原因
        if question_type == 'disease_cause':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.cause".format(i) for i in entities]

        # 查询疾病的防御措施
        elif question_type == 'disease_prevent':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.prevent".format(i) for i in entities]

        # 查询疾病的持续时间
        elif question_type == 'disease_lasttime':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.cure_lasttime".format(i) for i in entities]

        # 查询疾病的治愈概率
        elif question_type == 'disease_cureprob':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.cured_prob".format(i) for i in entities]

        # 查询疾病的治疗方式
        elif question_type == 'disease_cureway':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.cure_way".format(i) for i in entities]

        # 查询疾病的易发人群
        elif question_type == 'disease_easyget':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.easy_get".format(i) for i in entities]

        # 查询疾病的相关介绍
        elif question_type == 'disease_desc':
            sql = ["MATCH (m:Diseases) where m.name = '{0}' return m.name, m.desc".format(i) for i in entities]

        # 查询疾病有哪些症状
        elif question_type == 'disease_symptom':
            sql = [
                "MATCH (m:Diseases)-[r:has_symptoms]->(n:Symptoms) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]

        # 查询症状会导致哪些疾病
        elif question_type == 'symptom_disease':
            sql = [
                "MATCH (m:Diseases)-[r:has_symptoms]->(n:Symptoms) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]

        # 查询疾病的并发症
        elif question_type == 'disease_acompany':
            sql1 = [
                "MATCH (m:Diseases)-[r:acompany_with]->(n:Symptoms) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql2 = [
                "MATCH (m:Diseases)-[r:acompany_with]->(n:Symptoms) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql = sql1 + sql2
        # 查询疾病的忌口
        elif question_type == 'disease_not_food':
            sql = ["MATCH (m:Diseases)-[r:not_eat]->(n:Foods) where m.name = '{0}' return m.name, r.name, n.name".format(i)
                   for i in entities]

        # 查询疾病建议吃的东西
        elif question_type == 'disease_do_food':
            sql1 = [
                "MATCH (m:Diseases)-[r:do_eat]->(n:Foods) where m.name = '{0}' return m.name, r.name, n.name".format(i)
                for i in entities]
            sql2 = [
                "MATCH (m:Diseases)-[r:recomment_eat]->(n:Foods) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql = sql1 + sql2

        # 已知忌口查疾病
        elif question_type == 'food_not_disease':
            sql = ["MATCH (m:Diseases)-[r:not_eat]->(n:Foods) where n.name = '{0}' return m.name, r.name, n.name".format(i)
                   for i in entities]

        # 已知推荐查疾病
        elif question_type == 'food_do_disease':
            sql1 = [
                "MATCH (m:Diseases)-[r:do_eat]->(n:Foods) where n.name = '{0}' return m.name, r.name, n.name".format(i)
                for i in entities]
            sql2 = [
                "MATCH (m:Diseases)-[r:recomment_eat]->(n:Foods) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql = sql1 + sql2

        # 查询疾病常用药品-药品别名记得扩充
        elif question_type == 'disease_drug':
            sql1 = [
                "MATCH (m:Diseases)-[r:common_drug]->(n:Drugs) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql2 = [
                "MATCH (m:Diseases)-[r:recommand_drug]->(n:Drugs) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql = sql1 + sql2

        # 已知药品查询能够治疗的疾病
        elif question_type == 'drug_disease':
            sql1 = [
                "MATCH (m:Diseases)-[r:common_drug]->(n:Drugs) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql2 = [
                "MATCH (m:Diseases)-[r:recommand_drug]->(n:Drugs) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]
            sql = sql1 + sql2
        # 查询疾病应该进行的检查
        elif question_type == 'disease_check':
            sql = [
                "MATCH (m:Diseases)-[r:need_check]->(n:Checks) where m.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]

        # 已知检查查询疾病
        elif question_type == 'check_disease':
            sql = [
                "MATCH (m:Diseases)-[r:need_check]->(n:Checks) where n.name = '{0}' return m.name, r.name, n.name".format(
                    i) for i in entities]

        return sql

    def entity_transform(self, entity):
        entity_dict = {}
        for args, types in entity.items():
            for type in types:
                if type in entity_dict:
                    entity_dict[type] = [args]
                else:
                    entity_dict[type] = []
                    entity_dict[type].append(args)
        return entity_dict

4. 数据查询(回答组装)

from py2neo import Graph, Node

class Answer:
    def __init__(self):
        self.neo4j = Graph('bolt://localhost:7687', auth=('neo4j', 'beiqiaosu123456'))
        self.num_limit = 20

    def main(self, question_parse):
        answers_final = []
        for item in question_parse:
            question_type = item['qustion_type']
            sqls = item['sql']
            answer = []
            for sql in sqls:
                data = self.neo4j.run(sql)
                answer+=data.data()

            final_answer = self.answer_prettify(question_type, answer)
            if final_answer:
                answers_final.append(final_answer)

        return answers_final

    '''根据对应的qustion_type,调用相应的回复模板'''
    def answer_prettify(self, question_type, answers):
        final_answer = []
        if not answers:
            return ''
        if question_type == 'disease_symptom':
            desc = [i['n.name'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}的症状包括:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'symptom_disease':
            desc = [i['m.name'] for i in answers]
            subject = answers[0]['n.name']
            final_answer = '症状{0}可能染上的疾病有:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_cause':
            desc = [i['m.cause'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}可能的成因有:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_prevent':
            desc = [i['m.prevent'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}的预防措施包括:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_lasttime':
            desc = [i['m.cure_lasttime'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}治疗可能持续的周期为:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_cureway':
            desc = [';'.join(i['m.cure_way']) for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}可以尝试如下治疗:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_cureprob':
            desc = [i['m.cured_prob'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}治愈的概率为(仅供参考):{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_easyget':
            desc = [i['m.easy_get'] for i in answers]
            subject = answers[0]['m.name']

            final_answer = '{0}的易感人群包括:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_desc':
            desc = [i['m.desc'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0},熟悉一下:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == '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}的症状包括:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_not_food':
            desc = [i['n.name'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}忌食的食物包括有:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_do_food':
            do_desc = [i['n.name'] for i in answers if i['r.name'] == '可以吃']
            recommand_desc = [i['n.name'] for i in answers if i['r.name'] == '推荐吃']
            subject = answers[0]['m.name']
            final_answer = '{0}宜食的食物包括有:{1}\n推荐食谱包括有:{2}'.format(subject, ';'.join(list(set(do_desc))[:self.num_limit]),
                                                                 ';'.join(list(set(recommand_desc))[:self.num_limit]))

        elif question_type == 'food_not_disease':
            desc = [i['m.name'] for i in answers]
            subject = answers[0]['n.name']
            final_answer = '患有{0}的人最好不要吃{1}'.format(';'.join(list(set(desc))[:self.num_limit]), subject)

        elif question_type == 'food_do_disease':
            desc = [i['m.name'] for i in answers]
            subject = answers[0]['n.name']
            final_answer = '患有{0}的人建议多试试{1}'.format(';'.join(list(set(desc))[:self.num_limit]), subject)

        elif question_type == 'disease_drug':
            desc = [i['n.name'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}通常的使用的药品包括:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'drug_disease':
            desc = [i['m.name'] for i in answers]
            subject = answers[0]['n.name']
            final_answer = '{0}主治的疾病有{1},可以试试'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'disease_check':
            desc = [i['n.name'] for i in answers]
            subject = answers[0]['m.name']
            final_answer = '{0}通常可以通过以下方式检查出来:{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        elif question_type == 'check_disease':
            desc = [i['m.name'] for i in answers]
            subject = answers[0]['n.name']
            final_answer = '通常可以通过{0}检查出来的疾病有{1}'.format(subject, ';'.join(list(set(desc))[:self.num_limit]))

        return final_answer

写在最后

        以上就是这个医疗知识问答机器人的全部代码了,从上面的问答里也能看出,回答得还是很生硬。因为这就只是一个程序化得思维导图,所以修改完善空间还是很大,这个就要后期用深度学习得方式对分类解析部分进行改动。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/828460.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

pytorch学习——如何构建一个神经网络——以手写数字识别为例

目录 一.概念介绍 1.1神经网络核心组件 1.2神经网络结构示意图 1.3使用pytorch构建神经网络的主要工具 二、实现手写数字识别 2.1环境 2.2主要步骤 2.3神经网络结构 2.4准备数据 2.4.1导入模块 2.4.2定义一些超参数 2.4.3下载数据并对数据进行预处理 2.4.4可视化数…

TSINGSEE青犀视频智能视频监控EasyCVR如何将实时监控视频流分享出去?

开源EasyDarwin视频监控平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,在视频监控播放上,TSINGSEE青犀视频安防监控平台可支持1、4、9、16个画面窗口播放,可同时播放多路视频流,…

【深度学习】Vision Transformer论文,ViT的一些见解《 一幅图像抵得上16x16个词:用于大规模图像识别的Transformer模型》

必看文章:https://blog.csdn.net/qq_37541097/article/details/118242600 论文名称: An Image Is Worth 16x16 Words: Transformers For Image Recognition At Scale 论文下载:https://arxiv.org/abs/2010.11929 官方代码:https:…

【微信小程序】保存多张图片到本地相册

<template><view class"container"><u-swiper :list"list" circular radius0 indicator indicatorModedot height950rpx></u-swiper><view class"btn btn2" click"saveFun">保存到相册</view><…

【MySQL】当前读和快照读

文章目录 当前读快照读 在学习 MVCC 多版本并发控制之前&#xff0c;必须先了解一下&#xff0c;什么是 MySQL InnoDB 下的 当前读和 快照读? 当前读 读取的是记录的最新版本&#xff0c;读取时还要保证其他并发事务不能修改当前记录&#xff0c;会对读取的记录进行加锁。对…

Rocky(centos) jar 注册成服务,能开机自启动

概述 涉及&#xff1a;1&#xff09;sh 无法直接运行java命令&#xff0c;可以软连&#xff0c;此处是直接路径 2&#xff09;sh脚本报一堆空格换行错误&#xff1a;需将转成unix标准格式&#xff1b; #切换到上传的脚本路径 dos2unix 脚本文件名.sh 2&#xff09;SELINUX …

Ubuntu18.04安装ROS

ROS 安装前的准备 &#xff08;1&#xff09;为了安装顺利使用国内下载源&#xff0c;&#xff08;我个人linux使用了代理&#xff09; 清华大学源 sudo sh -c ‘. /etc/lsb-release && echo “deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENA…

第四讲:利用ADO方式连接Access数据库

【分享成果&#xff0c;随喜正能量】最值得信赖的&#xff0c;其实是自己从孤独中得来的东西&#xff0c;而不是别人给予自己的东西。每个人都是一座孤岛&#xff0c;有些人一生都在想要逃离这座岛&#xff0c;有些人一生都在创造并丰富自己这座岛。。 《VBA数据库解决方案》教…

水环境地质3D可视化综合管理软件提高运维效率

谈起数字孪生技术&#xff0c;总让人兴奋不已&#xff0c;这种将物理实体的数字化模型与实际物理实体相结合、以虚控实的技术&#xff0c;是数字化转型和第四次工业革命的重要载体&#xff0c;那么在地质行业中&#xff0c;数字孪生有哪些应用场景? 在地质勘探中&#xff0c; …

潜在客户生成最实用指南,你还在等什么?

潜在客户是指对您的产品或服务表现出兴趣的人&#xff0c;它们提供个人识别信息&#xff0c;您的团队可以使用这些信息来跟进他们。随着越来越多的营销渠道涌现&#xff0c;接触新客户和开展有效的潜在客户生成活动变得越来越困难。赢得新的潜在客户听起来很困难&#xff0c;但…

【B/S手术麻醉系统源码】手术麻醉管理系统在临床中的应用

手术麻醉管理系统是临床麻醉工作中一个不容忽视的环节&#xff0c;麻醉医生必须对病人在麻醉手术过程中的情况与体征变化&#xff0c;采取的处理措施及术后随访等全过程作出及时、真实、确切的记录。麻醉记录不仅有助于确保临床麻醉准确&#xff0c;总结经验教训&#xff0c;提…

kcc呼叫中心语音转写功能

呼叫中心是客户和企业之间沟通的一个桥梁&#xff0c;也是客户服务和客户关系的一个重要组成部分。通过呼叫中心&#xff0c;企业可以建立起一个以客户为中心的服务模式&#xff0c;为客户提供高质量、高效率的服务&#xff0c;对于塑造企业形象&#xff0c;提高客户满意度&…

txt替换字符为换行

txt替换字符为换行 txt如何批量将同一个符号替换成换行符 2023-01-26 03:16:03 有时候看到网页有些排列的很整齐的文本想复制使用&#xff0c;可是复制下来放到txt后不分行&#xff0c;要么就是中间隔着一些公用的符号。那么我们怎么才能快速的让文本按原来的形式分行显示在…

一百三十九、Kettle——Linux安装Kettle8.2

一、目的 为了方便海豚调度kettle任务&#xff0c;在Linux上安装kettle 二、kettle版本与前提 版本&#xff1a;kettle8.2 pdi-ce-8.2.0.0-342 前提&#xff1a;Linux已经安装好jdk 三、安装步骤 &#xff08;一&#xff09;打开安装包所在地 [roothurys22 ~]# cd …

让SpringBoot不再需要Controller、Service、DAO、Mapper,卧槽!这款工具绝了

Dataway 是基于 DataQL 服务聚合能力&#xff0c;为应用提供的一个接口配置工具&#xff0c;使得使用者无需开发任何代码就配置一个满足需求的接口。整个接口配置、测试、冒烟、发布&#xff0c;一站式都通过 Dataway 提供的 UI 界面完成。UI 会以 Jar 包方式提供并集成到应用中…

小鹏遭遇“动荡”,自动驾驶副总裁吴新宙离职,现已完成团队过渡

根据最新消息&#xff0c;小鹏汽车的自动驾驶副总裁吴新宙宣布将加入全球GPU芯片巨头英伟达。吴新宙将成为该公司全球副总裁&#xff0c;直接向英伟达全球CEO黄仁勋汇报。小鹏汽车董事长何小鹏和吴新宙本人已在微博上确认该消息&#xff0c;并解释离职原因涉及家庭和多方面因素…

拿捏--->逻辑推断问题(猜凶手+猜名次)

文章目录 猜凶手问题题目描述算法思路代码实现 猜名次问题题目描述算法思路代码实现 猜凶手问题 题目描述 算法思路 代码实现 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() {char killer 0;for (killer A; killer < D; killer){if ((killer ! …

Rpc异步日志模块

Rpc异步日志模块作用 在一个大型分布式系统中&#xff0c;任何部署的分布式节点都可能发生崩溃&#xff0c;试想如果用普通的办法&#xff0c;即先排查哪个节点down掉了&#xff0c;找到down掉的节点后采取调试工具gdb调试该节点&#xff0c;进而排查宕机的原因。这中排查方法…

Redis的缓存、消息队列、计数器应用

目录 一、redis的应用场景 二、redis如何用于缓存 三、redis如何用于消息队列 四、redis如何用于计数器 一、redis的应用场景 Redis在实际应用中有广泛的应用场景&#xff0c;以下是一些常见的Redis应用场景&#xff1a; 缓存&#xff1a;Redis可以用作缓存层&#xff0c;…

高性能远程通信框架grpc基本使用

文章目录 一、了解grpc二、关于protobuf三、试玩grpc3.1整个工程目录3.2 proto文件编写3.3 使用maven protobuf插件转换.proto文件3.4 Grpc服务端业务实现类3.5 pom参考3.6 grpc client调用 一、了解grpc 谷歌开源远程进程调用框架&#xff0c;支持多语言系统间通信&#xff0…