“基于医疗知识图谱的问答系统”代码解析(二)

“基于医疗知识图谱的问答系统”代码解析(二)question_classifier.py --问题分类器代码解析“基于知识医疗图谱的问答系统”代码解析(一)#!/usr/bin/env python3# coding: utf-8# File: question_classifier.py# Author: lhy<lhy_in_blcu@126.com,https://huangyong.github.io># Date: 18-10-4# 导入操作系统接口模块imp
摘要由CSDN通过智能技术生成

“基于医疗知识图谱的问答系统”代码解析(二)

question_classifier.py --问题分类器代码解析

“基于知识医疗图谱的问答系统”代码解析(一)
“基于医疗知识图谱的问答系统”代码解析(三)
“基于医疗知识图谱的问答系统”代码解析(四)
“基于医疗知识图谱的问答系统”代码解析(五)

#!/usr/bin/env python3
# coding: utf-8
# File: question_classifier.py
# Author: lhy<lhy_in_blcu@126.com,https://huangyong.github.io>
# Date: 18-10-4

# 导入操作系统接口模块
import os
# ahocosick:自动机的意思
#  可实现自动批量匹配字符串的作用,即可一次返回该条字符串中命中的所有关键词
import ahocorasick

# 建立问题分类器的类
class QuestionClassifier:
    def __init__(self):
        # cur_dir 是当前目录 其中[:-1]可以达到返回上一层的效果
        cur_dir = '/'.join(os.path.abspath(__file__).split('/')[:-1])
        # 加载特征词路径
        self.disease_path = os.path.join(cur_dir, 'dict/disease.txt')
        self.department_path = os.path.join(cur_dir, 'dict/department.txt')
        self.check_path = os.path.join(cur_dir, 'dict/check.txt')
        self.drug_path = os.path.join(cur_dir, 'dict/drug.txt')
        self.food_path = os.path.join(cur_dir, 'dict/food.txt')
        self.producer_path = os.path.join(cur_dir, 'dict/producer.txt')
        self.symptom_path = os.path.join(cur_dir, 'dict/symptom.txt')
        self.deny_path = os.path.join(cur_dir, 'dict/deny.txt')
        # 加载特征词  这里encoding用的是‘utf-8’模式,不加的话,我的pycharm会报错
        self.disease_wds= [i.strip() for i in open(self.disease_path,encoding='utf-8') if i.strip()]
        self.department_wds= [i.strip() for i in open(self.department_path,encoding='utf-8') if i.strip()]
        self.check_wds= [i.strip() for i in open(self.check_path,encoding='utf-8') if i.strip()]
        self.drug_wds= [i.strip() for i in open(self.drug_path,encoding='utf-8') if i.strip()]
        self.food_wds= [i.strip() for i in open(self.food_path,encoding='utf-8') if i.strip()]
        self.producer_wds= [i.strip() for i in open(self.producer_path,encoding='utf-8') if i.strip()]
        self.symptom_wds= [i.strip() for i in open(self.symptom_path,encoding='utf-8') if i.strip()]
        self.region_words 
  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值