You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
955 B
35 lines
955 B
4 weeks ago
|
# conda activate rag
|
||
|
# pip install py2neo pyvis
|
||
|
from py2neo import Graph
|
||
|
from pyvis.network import Network
|
||
|
from Config import Config
|
||
|
|
||
|
# 连接Neo4j
|
||
|
graph = Graph(Config.NEO4J_URI, auth=Config.NEO4J_AUTH)
|
||
|
|
||
|
# 查询所有知识点节点和关系
|
||
|
query = """
|
||
|
MATCH (n:KnowledgePoint)-[r]->(m)
|
||
|
RETURN n, r, m
|
||
|
"""
|
||
|
data = graph.run(query).data()
|
||
|
|
||
|
# 创建网络图
|
||
|
net = Network(height="750px", width="100%", notebook=True)
|
||
|
|
||
|
# 添加节点和边
|
||
|
for item in data:
|
||
|
net.add_node(item['n'].identity,
|
||
|
label=item['n']['name'],
|
||
|
title=item['n'].get('description', ''))
|
||
|
net.add_node(item['m'].identity,
|
||
|
label=item['m']['name'],
|
||
|
title=item['m'].get('description', ''))
|
||
|
net.add_edge(item['n'].identity,
|
||
|
item['m'].identity,
|
||
|
title=type(item['r']).__name__)
|
||
|
|
||
|
# 生成HTML文件
|
||
|
net.show("knowledge_graph.html", notebook=False)
|
||
|
|