|
|
|
@ -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']}")
|
|
|
|
|
print(f"反应方程式: {record['equation']}")
|