将文档传入chatgpt,生成对应的cypher语句
链接: https://pan.baidu.com/s/1Ny-ttbBSpqYEigwYiCWMeA?pwd=c7sc 提取码: c7sc
使用命令行安装对应的包
pip install neo4j
chatgpt生成出的txt文档中的内容如下:
MERGE (Node1:Entity {name: '原始舱单提运单信息'})
MERGE (Node2:Entity {name: '到达卸货地日期和时间'})
MERGE (Node1)-[:到达卸货地日期]->(Node2)
MERGE (Node1:Entity {name: '原始舱单提运单信息'})
MERGE (Node2:Entity {name: '中转港代码'})
MERGE (Node1)-[:中转地点代码]->(Node2)
python代码如下
from neo4j import GraphDatabase
# 连接到Neo4j数据库
uri = "bolt://localhost:7687" # 请更改为您的数据库地址
username = "xxxxx" # 请更改为您的用户名
password = "xxxxx" # 请更改为您的密码
driver = GraphDatabase.driver(uri, auth=(username, password))
# 读取Cypher查询文件
with open("./data/cypher_queries.txt", "r") as f:
queries = f.read().split("\n\n") # 假设每个查询之间有两个换行符
# 执行Cypher查询
with driver.session() as session:
for query in queries:
session.run(query)
# 关闭数据库连接
driver.close()