main
HuangHai 3 weeks ago
parent a1d5a91d71
commit fc53951661

@ -7,10 +7,10 @@ from Config import Config
# 连接Neo4j # 连接Neo4j
graph = Graph(Config.NEO4J_URI, auth=Config.NEO4J_AUTH) graph = Graph(Config.NEO4J_URI, auth=Config.NEO4J_AUTH)
# 查询所有节点和关系 # 修改后的查询语句使用INCLUDES关系类型
query = """ query = """
MATCH (n)-[r]->(m) MATCH p=()-[r:INCLUDES]->()
RETURN n, r, m RETURN p LIMIT 250
""" """
data = graph.run(query).data() data = graph.run(query).data()
@ -19,17 +19,22 @@ net = Network(height="750px", width="100%", notebook=True, cdn_resources='in_lin
# 添加节点和边 # 添加节点和边
for item in data: for item in data:
net.add_node(item['n'].identity, # 提取起始节点
label=item['n']['name'], start_node = item['p'].start_node
title=item['n'].get('description', ''), # 提取结束节点
group=item['n'].labels[0]) end_node = item['p'].end_node
net.add_node(item['m'].identity,
label=item['m']['name'], net.add_node(start_node.identity,
title=item['m'].get('description', ''), label=start_node['name'],
group=item['m'].labels[0]) title=start_node.get('description', ''),
net.add_edge(item['n'].identity, group=list(start_node.labels)[0])
item['m'].identity, net.add_node(end_node.identity,
title=type(item['r']).__name__) label=end_node['name'],
title=end_node.get('description', ''),
group=list(end_node.labels)[0])
net.add_edge(start_node.identity,
end_node.identity,
title="INCLUDES")
# 生成HTML文件 # 生成HTML文件
with open("knowledge_graph.html", "w", encoding='utf-8') as f: with open("knowledge_graph.html", "w", encoding='utf-8') as f:

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save