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

前言

        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

写在最后

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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

软件架构师高级——3、数据库系统

• 数据库概述(★★★) 集中式数据库系统 •数据管理是集中的 •数据库系统的素有功能 (从形式的用户接口到DBMS核心) 者口集中在DBMS所在的计算机。 B/S结构 •客户端负责数据表示服务 •服务器主要负责数据库服务 •数据 和后端…

安全杂记 - 复现nodejs沙箱绕过

目录 一. 配置环境1.下载nodejs2.nodejs配置3.报错解决方法 二. nodej沙箱绕过1. vm模块2.使用this或引用类型来进行沙箱绕过 一. 配置环境 1.下载nodejs 官网:https://nodejs.org/en2.nodejs配置 安装nodejs的msi文件,默认配置一直下一步即可&#x…

任务15、MidJourney视频(Video)参数动态上线,制作惊艳动画短片

15.1 任务概述 本次任务将帮助你掌握Midjourney中的Video参数,并利用这些参数创作出令人惊艳的绘画作品。通过学习Video参数的基本概念和功能,以及案例的实际应用,你将学会如何正确设置和调整这些参数,从而达到你所期望的绘画效果。最终,你将运用所学知识,生成香奈儿模特…

【web逆向】全报文加密及其登录流程的分析案例

aHR0cHM6Ly9oZWFsdGguZWxkZXIuY2NiLmNvbS9zaWduX2luLw 涉及加密库jsencrypt 定位加密点 先看加密的请求和响应: 全局搜索加密字段jsondata,这种非特定参数的一般一搜一个准,搜到就是断点。起初下的断点没停住,转而从调用栈单步…

arm交叉编译lmbench

一、下载lmbench www.bitmover.com/lmbench 官网下载,http://www.bitmover.com/lmbench/lmbench3.tar.gz 我没有下载下来,找的别人的百度云下载 链接: https://pan.baidu.com/s/1tGo1clCqY-jQPN8G1eWSsg 提取码: f6jd 二、修改makefile 修改三个文件…

maven install命令:将包安装在本地仓库,供本地的其它工程或者模块依赖

说明 有时候,自己本地的maven工程依赖于本地的其它工程,或者manven工程中的一个模块依赖于另外的模块,可以执行maven的install命令,将被依赖的包安装在maven本地仓库。 示例 一个工程包含几个模块,模块之间存在依赖…

【网络基础实战之路】设计网络划分的实战详解

系列文章传送门: 【网络基础实战之路】设计网络划分的实战详解 【网络基础实战之路】一文弄懂TCP的三次握手与四次断开 【网络基础实战之路】基于MGRE多点协议的实战详解 【网络基础实战之路】基于OSPF协议建立两个MGRE网络的实验详解 PS:本要求基于…

8.6 day07 休息+剑指offer

文章目录 06从尾到头打印链表03数组中重复的数字04二维数组中的查找05 替换空格06重建二叉树背英语单词,看了二十页 06从尾到头打印链表 从尾到头遍历链表 方法一就是用栈来辅助,栈的结构是先进后出的,将链表中的元素加入到栈中去&#xff0…

ACL访问控制列表

ACL介绍 acl: 访问控制列表 步骤: 创建一个访问控制规则调用这个规则 ACL的分类和标识 ACL的匹配顺序以及匹配结果 拓扑图 配置 # 首先通过三层交换的实验做一次 ....## 检测ip地址 display ip interface brief## 在交换机2上做配置 [S2]acl name test ?IN…

【Pycharm2022.2.1】python编辑器最新版安装教程(包含2017-2022的所有版本win/mac/linux)

前言 嗨喽~大家好呀,这里是魔王呐 ❤ ~! 永久安装 Pycharm(2017-2022的win/mac/linux所有版本)/ IntelliJ IDEA也可以, 按照本文教程所写的,具体步骤跟着下面的图文教程一步一步来就行,一分钟即可搞定,过…

【ShaderToy中图形效果转译到UnityShaderlab案例分享,实现2D层层叠叠半透明泡泡_Bubbles】

Shader"ShaderToy/Bubbles" {Properties{}SubShader{Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct ap

Pycharm连接服务器

前提:必须为pycharm专业版才能连接到服务器 以下为pycharm2023专业版 一、连接 系统环境 虚拟环境(前提:已安装anaconda) (1) anaconda环境 (2) 自己创建的虚拟环境 这里为envs下的spotr 二、查看连接情况 选择自动上传

Codejock Skin Framework Visual C++ MFC Crack

Codejock Skin Framework Visual C MFC Crack Codejock Visual CMFC皮肤框架为Windows开发人员提供了一种高度复杂的应用程序皮肤框架技术,该技术是在考虑Windows主题(视觉样式)的情况下开发的。只需几行代码就可以实现一个完全主题化的应用程序。 功能概述 Codejoc…

【css】css实现字母大小写转换

text-transform 属性用于指定文本中的大写和小写字母。 uppercase&#xff1a;将字母转为大写lowercase&#xff1a;将字母转为小写capitalize&#xff1a;将每个单词首字母转为大写 代码&#xff1a; <style> p.uppercase {text-transform: uppercase; }p.lowercase …

Android学习之路(1) App工程的项目结构

一、App工程的项目结构 1.项目下面有两个分类 一个是app(代表app模块)&#xff0c;另一个是Gradle Scripts。其中app下面又有3个子目录&#xff0c;其功能说明如下&#xff1a; manifests 子目录下面只有一个XML文件&#xff0c;即AndroidManifest.xmljava子目录&#xff0c;…

Verilator仿真环境搭建

Verilator简介与使用_Hwang_shuo的博客-CSDN博客 Verilator是一种开源的Verilog/SystemVerilog仿真器&#xff0c;可用于编译代码以及代码在线检查&#xff0c;Verilator能够读取Verilog或者SystemVerilog文件&#xff0c;并进行lint checks(基于lint工具的语法检测)&#xff…

uniapp使用阿里图标

效果图&#xff1a; 前言 随着uniApp的深入人心&#xff0c;我司也陆续做了几个使用uniapp做的移动端跨平台软件&#xff0c;在学习使用的过程中深切的感受到了其功能强大和便捷&#xff0c;今日就如何在uniapp项目中使用阿里字体图标的问题为大家献上我的一点心得&#xff0…

HCIP IPV6

一、IPV6升级特点联系和区别 IPV4--->IPV6 1、全球单播地址 ---- IPV4地址下的公有地址 V6下没nat 2、可聚合性&#xff08;IANA组织对全球的地址进行合理分配&#xff09; 3、多宿主---一个物理接口可以同时拥有多个不同网段的IPV6地址&#xff1b;但不同接口不能在…

神码ai伪原创工具【php源码】

大家好&#xff0c;小编为大家解答python炫酷烟花表白源代码的问题。很多人还不知道html代码烟花特效python&#xff0c;现在让我们一起来看看吧&#xff01; 火车头采集ai伪原创插件截图&#xff1a; 目录 前言 环境准备 代码编写 效果展示 前言 Python实现浪漫的烟花特效 现在…

一 关于idea如何在svn进行项目下载并运行成功

安装svn客户端 如图 安装时请选择该选项&#xff08;Will be installed on local hard drive&#xff09;并选择自己想要安装的目录路径 如图 svn安装成功 如图 注意 安装完成后&#xff0c;使用svn进行一次checkout的项目导出完成以上五步时&…