examine_data.csv
建议值用“”引起来。避免中间有,号造成误识别
检查
"膝关节核磁"
"眼睛酸胀"
"视力"
"砂眼"
"辨色力"
"角膜"
"眼底"
参考 创建药品 节点。
import logging
from utils.neo4j_provider import driver
import pandas as pd
logging.root.setLevel(logging.INFO)
# 并生成 CQL
def generate_cql() -> str:
cql = """
CREATE (examine1:Examine {name: "膝关节核磁"}),
(examine2:Examine {name: "眼睛酸胀"}),
"""
df = pd.read_csv('examine_data.csv')
symptoms = []
for each in df['检查']:
symptoms.extend(each.split(',')) # 按,号分割成数组,并将每行数据到一个队列里面
symptoms = set(symptoms) # 去除重复项
# 拼接 CQL
cql = ""
for idx, item in enumerate(symptoms):
cql += """(examine%s:Examine {name: "%s"}),\r\n""" \
% (idx, item)
return "CREATE %s" % (cql.rstrip(",\r\n")) # 删除最后一个节点的 逗号
# 执行写的命令
def execute_write(cql):
with driver.session() as session:
session.execute_write(execute_cql, cql)
driver.close()
# 执行 CQL 语句
def execute_cql(tx, cql):
tx.run(cql)
# 清除 Examine 标签数据
def clear_data():
cql = "MATCH (n:Examine) DETACH DELETE n"
execute_write(cql)
if __name__ == "__main__":
clear_data()
cql = generate_cql()
print(cql)
execute_write(cql)