import re
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship
from langchain_core.documents import Document

from langchain_community.graphs import Neo4jGraph
from langchain_core.documents import Document
import os
os.environ["NEO4J_URI"] = "bolt://192.168.0.46:57687"
os.environ["NEO4J_USERNAME"] = "neo4j"
os.environ["NEO4J_PASSWORD"] = "zdht123@"

graph = Neo4jGraph(refresh_schema=False)


#清空数据库内容
graph.query("MATCH (n) DETACH DELETE n")



#查询某个节点的相关节点
# selectsql = """
# MATCH (e:__Entity__ {id: "进气系统"})-[r]-(related)
# RETURN related, type(r) AS relationship_type
# """
# results = graph.query(selectsql)
# #
# # # 打印结果
# print(f"共找到 {len(results)} 个关联节点：\n")
# for i, record in enumerate(results, 1):
#     related_node = record["related"]
#     rel_type = record["relationship_type"]

#     # 提取 related 节点的 id（或其他属性）
#     node_id = related_node.get("id", "N/A")
#     labels = related_node.get("labels", [])  # 注意：LangChain 返回的节点可能包含 labels

#     print(f"{i}. 关联节点 ID: {node_id}")
#     print(f"   标签: {labels}")
#     print(f"   关系类型: {rel_type}")
#     print(f"   完整节点数据: {related_node}")
#     print("-" * 50)
