From 6ae9fd4d6e2501d3bdc16667a2d0847c0d234e17 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Tue, 1 Jul 2025 16:06:57 +0800 Subject: [PATCH] 'commit' --- dsRag/Neo4j/TestNeo4j2.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dsRag/Neo4j/TestNeo4j2.py b/dsRag/Neo4j/TestNeo4j2.py index e5f9dfb1..c416bb7f 100644 --- a/dsRag/Neo4j/TestNeo4j2.py +++ b/dsRag/Neo4j/TestNeo4j2.py @@ -3,6 +3,11 @@ from py2neo import Graph, Node, Relationship # 1. 连接Neo4j数据库 graph = Graph("bolt://localhost:7687", auth=("neo4j", "DsideaL147258369")) +# 清空数据库 +graph.delete_all() +print("数据库已清空") + + # 2. 创建化学物质节点 (三种反应物+一种生成物) reactant_A = Node("Chemical", name="铁", formula="Fe") reactant_B = Node("Chemical", name="氧气", formula="O2") @@ -17,12 +22,12 @@ reaction = Node("Reaction", ) # 4. 建立反应物与反应的关系(带计量系数属性) -rel_A = Relationship(reactant_A, "PARTICIPATES_IN", reaction, coefficient=4) -rel_B = Relationship(reactant_B, "PARTICIPATES_IN", reaction, coefficient=3) -rel_C = Relationship(reactant_C, "PARTICIPATES_IN", reaction, coefficient=6) +rel_A = Relationship(reactant_A, "参与反应", reaction, coefficient=4) +rel_B = Relationship(reactant_B, "参与反应", reaction, coefficient=3) +rel_C = Relationship(reactant_C, "参与反应", reaction, coefficient=6) # 5. 建立反应与生成物的关系 -rel_product = Relationship(reaction, "PRODUCES", product, yield_rate="98%") +rel_product = Relationship(reaction, "生成", product, yield_rate="98%") # 6. 将节点和关系提交到数据库 graph.create(reactant_A) @@ -44,4 +49,4 @@ result = graph.run(query) for record in result: print(f"化学物质: {record['chemical']}, 计量系数: {record['coefficient']}") -print(f"反应方程式: {record['equation']}") \ No newline at end of file + print(f"反应方程式: {record['equation']}") \ No newline at end of file