目录
- 构建节点字典
- 构建Cypher CQL语句
- Test
这边只是为了测试,演示效果和思路,实际应用中,可以通过NLP构建CQL
接上一篇的问题分类
question = "请问最近看东西有时候清楚有时候不清楚是怎么回事"
# 最终输出
data = {'args': {'看东西有时候清楚有时候不清楚': ['symptom']}, 'question_types': ['symptom_disease']}
question = "干眼常用药有哪些"
# 最终输出
data = {'args': {'干眼': ['disease']}, 'question_types': ['disease_drug']}
question = "干眼哪些不能吃"
data = {'args': {'干眼': ['disease']}, 'question_types': ['disease_not_food']}
构建节点字典
目的,为了拼CQL,查出符合条件的节点详情
def build_nodedict(self, args):
"""
构建节点字典
:param args: {'看东西有时候清楚有时候不清楚': ['symptom']}
:return: 组装成 => {'symptom': '看东西有时候清楚有时候不清楚'}
"""
node_dict = {}
for arg, types in args.items():
for type in types:
if type not in node_dict:
node_dict[type] = [arg]
else:
node_dict[type].append(arg)
return node_dict
# 输入:
{'看东西有时候清楚有时候不清楚': ['symptom']}
# 输出:
{'symptom': ['看东西有时候清楚有时候不清楚']}
构建Cypher CQL语句
# 查询症状会导致哪些疾病
if question_type == 'symptom_disease':
sql = ["MATCH (m:Disease)-[r:has_symptom]->(n:Symptom) where n.name = '{0}' return m.name, r.name, n.name".format(i) for i in entities]
# 查询症状会导致哪些疾病
if question_type == 'symptom_disease':
sql = ["MATCH (m:Disease)-[r:has_symptom]->(n:Symptom) where n.name = '{0}' return m.name, r.name, n.name".format(i) for i in entities]
# 查询疾病常用药品-药品别名记得扩充
if que服务器托管网stion_type == 'disease_drug':
sql = ["MATCH (m:Disease)-[r:used_drugs]->(n:Drug) where m.name = '{0}' return m.name, r.name, n.name".format(i) for i in entities]
# 查询疾病的忌口
if question_type == 'disease_not_food':
sql = ["MATCH (m:Disease)-[r:noteat_foods]->(n:Foods) where m.name = '{0}' return m.name, r.name, n.name".format(i) for i in entities]
node_dict.get(‘symptom’)
Test
if __name__ == '__main__':
handler = QuestionPaser()
question_class = {'args': {'看东西有时候清楚有时候不清楚': ['symptom']}, 'question_types': ['symptom_disease']}
cql = handler.parser_main(question_class)
print(cql)
输出:
# 输入
question_class = {'args': {'看东西有时候清楚有时候不清楚': ['symptom']}, 'question_types': ['symptom_disease']}
# 输出
[{'question_type': 'symptom_disease', 'sql': ["MATCH (m:Disease)-[r:has_symptom]->(n:Symptom) where n.name = '看东西有时候清楚有时候不清楚' return m.name, r.name, n.name"]}]
# 输入:
question_class = {'args': {'干眼': ['disease']}, 'question_types': ['disease_drug']}
# 输出:
[{'question_type': 'disease_drug', 'sql': ["MATCH (m:Disease)-[r:used_drugs]->(n:Drug) where m.name = '干眼' return m.name, r.name, n.name"]}]
# 输入:
question_class = {'args': {'干眼': ['disease']}, 'question_types': ['disease_not_food']}
# 输出:
[{'question_type': 'disease_not_food', 'sql': ["MATCH (m:Disease)-[r:noteat_foods]->(n:Foods) where m.name = '干眼' return m.name, r.name, n.name"]}]
后面根据 生成的 CQL语句,查询出知识图谱中对应的数据,
源代码地址:https://gitee.com/VipSoft/VipQA
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管,服务器托管网 http://www.fwqtg.net
相关推荐: .net 温故知新【11】:Asp.Net Core WebAPI 入门使用及介绍
在Asp.Net Core 上面由于现在前后端分离已经是趋势,所以asp.net core MVC用的没有那么多,主要以WebApi作为学习目标。 一、创建一个WebApi项目 我使用的是VS2022, .Net 7版本。 在创建界面有几项配置: 配置Http…