From fc53951661a665a067a92787c4387da625e4943f Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Wed, 2 Jul 2025 09:42:50 +0800 Subject: [PATCH] 'commit' --- dsRag/Neo4j/N4_KG_Graph.py | 33 ++++++++++++++++++-------------- dsRag/Neo4j/knowledge_graph.html | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dsRag/Neo4j/N4_KG_Graph.py b/dsRag/Neo4j/N4_KG_Graph.py index a6fea6a5..220f87bb 100644 --- a/dsRag/Neo4j/N4_KG_Graph.py +++ b/dsRag/Neo4j/N4_KG_Graph.py @@ -7,10 +7,10 @@ from Config import Config # 连接Neo4j graph = Graph(Config.NEO4J_URI, auth=Config.NEO4J_AUTH) -# 查询所有节点和关系 +# 修改后的查询语句,使用INCLUDES关系类型 query = """ -MATCH (n)-[r]->(m) -RETURN n, r, m +MATCH p=()-[r:INCLUDES]->() +RETURN p LIMIT 250 """ 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: - net.add_node(item['n'].identity, - label=item['n']['name'], - title=item['n'].get('description', ''), - group=item['n'].labels[0]) - net.add_node(item['m'].identity, - label=item['m']['name'], - title=item['m'].get('description', ''), - group=item['m'].labels[0]) - net.add_edge(item['n'].identity, - item['m'].identity, - title=type(item['r']).__name__) + # 提取起始节点 + start_node = item['p'].start_node + # 提取结束节点 + end_node = item['p'].end_node + + net.add_node(start_node.identity, + label=start_node['name'], + title=start_node.get('description', ''), + group=list(start_node.labels)[0]) + net.add_node(end_node.identity, + 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文件 with open("knowledge_graph.html", "w", encoding='utf-8') as f: diff --git a/dsRag/Neo4j/knowledge_graph.html b/dsRag/Neo4j/knowledge_graph.html index 5c58d1da..17a32584 100644 --- a/dsRag/Neo4j/knowledge_graph.html +++ b/dsRag/Neo4j/knowledge_graph.html @@ -302,8 +302,8 @@ function highlightFilter(filter) { // parsing and collecting nodes and edges from the python - nodes = new vis.DataSet([]); - edges = new vis.DataSet([]); + nodes = new vis.DataSet([{"group": "Topic", "id": 395, "label": "\u6570\u7684\u8ba4\u8bc6", "shape": "dot", "title": "\u5173\u4e8e\u6570\u7684\u57fa\u672c\u6982\u5ff5\u548c\u6027\u8d28"}, {"group": "Subtopic", "id": 379, "label": "\u8d1f\u6570", "shape": "dot", "title": "\u8d1f\u6570\u662f\u4e0e\u81ea\u7136\u6570\u6570\u91cf\u76f8\u7b49\u4f46\u610f\u4e49\u76f8\u53cd\u7684\u6570"}, {"group": "Topic", "id": 396, "label": "\u6570\u7684\u8fd0\u7b97", "shape": "dot", "title": "\u5173\u4e8e\u6570\u7684\u8fd0\u7b97\u89c4\u5219\u548c\u65b9\u6cd5"}, {"group": "Subtopic", "id": 381, "label": "\u65b9\u7a0b\u7684\u672c\u8d28", "shape": "dot", "title": "\u65b9\u7a0b\u7528\u5b57\u6bcd\u8868\u793a\u672a\u77e5\u91cf\uff0c\u8bb2\u8ff0\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u7b49\u91cf\u5173\u7cfb"}, {"group": "Subtopic", "id": 368, "label": "\u4f30\u7b97", "shape": "dot", "title": "\u4f30\u7b97\u662f\u57fa\u4e8e\u6570\u91cf\u5173\u7cfb\u7684\u8fd0\u7b97"}, {"group": "Topic", "id": 394, "label": "\u56fe\u5f62\u4e0e\u51e0\u4f55", "shape": "dot", "title": "\u5173\u4e8e\u56fe\u5f62\u4e0e\u51e0\u4f55\u7684\u57fa\u672c\u6982\u5ff5\u548c\u6027\u8d28"}, {"group": "Subtopic", "id": 372, "label": "\u5e73\u79fb\u3001\u65cb\u8f6c\u3001\u8f74\u5bf9\u79f0", "shape": "dot", "title": "\u56fe\u5f62\u7684\u8fd0\u52a8\u5305\u62ec\u5e73\u79fb\u3001\u65cb\u8f6c\u3001\u8f74\u5bf9\u79f0"}, {"group": "Topic", "id": 397, "label": "\u7edf\u8ba1\u4e0e\u6982\u7387", "shape": "dot", "title": "\u5173\u4e8e\u7edf\u8ba1\u4e0e\u6982\u7387\u7684\u57fa\u672c\u6982\u5ff5\u548c\u65b9\u6cd5"}, {"group": "Subtopic", "id": 391, "label": "\u6982\u7387", "shape": "dot", "title": "\u6982\u7387\u662f\u968f\u673a\u4e8b\u4ef6\u53d1\u751f\u7684\u5c5e\u6027"}, {"group": "Subtopic", "id": 382, "label": "\u9664\u6cd5\u8fd0\u7b97", "shape": "dot", "title": "\u9664\u6cd5\u662f\u4e58\u6cd5\u7684\u9006\u8fd0\u7b97"}, {"group": "Subtopic", "id": 384, "label": "\u56fe\u5f62\u7684\u8ba4\u8bc6\u4e0e\u5206\u7c7b", "shape": "dot", "title": "\u56fe\u5f62\u7684\u8ba4\u8bc6\u9700\u4ece\u7acb\u4f53\u56fe\u5f62\u62bd\u8c61\u51fa\u70b9\u3001\u7ebf\u3001\u9762\u3001\u4f53\u3001\u89d2\u7b49\u6982\u5ff5"}, {"group": "Entity", "id": 393, "label": "\u5c0f\u5b66\u6570\u5b66\u6559\u5b66\u4e2d\u7684\u82e5\u5e72\u95ee\u9898", "shape": "dot", "title": "\u5c0f\u5b66\u6570\u5b66\u6559\u5b66\u7684\u6838\u5fc3\u5185\u5bb9"}, {"group": "Subtopic", "id": 375, "label": "\u4e58\u6cd5\u8fd0\u7b97", "shape": "dot", "title": "\u81ea\u7136\u6570\u96c6\u5408\u4e0a\u4e58\u6cd5\u662f\u52a0\u6cd5\u7684\u7b80\u4fbf\u8fd0\u7b97"}, {"group": "Subtopic", "id": 378, "label": "\u7a7a\u95f4\u89c2\u5ff5\u4e0e\u51e0\u4f55\u76f4\u89c2", "shape": "dot", "title": "\u7a7a\u95f4\u89c2\u5ff5\u662f\u7a7a\u95f4\u60f3\u8c61\u529b\uff0c\u51e0\u4f55\u76f4\u89c2\u662f\u76f4\u63a5\u5224\u65ad\u80fd\u529b"}, {"group": "Subtopic", "id": 370, "label": "\u7edf\u8ba1\u56fe", "shape": "dot", "title": "\u4e09\u79cd\u7edf\u8ba1\u56fe\u5404\u6709\u5171\u6027\u548c\u5dee\u5f02\uff0c\u7528\u4e8e\u76f4\u89c2\u8868\u8ff0\u6570\u636e"}, {"group": "Subtopic", "id": 366, "label": "\u5c0f\u6570", "shape": "dot", "title": "\u5c0f\u6570\u5efa\u7acb\u5728\u5341\u8fdb\u5236\u57fa\u7840\u4e0a"}, {"group": "Subtopic", "id": 387, "label": "\u52a0\u6cd5\u8fd0\u7b97", "shape": "dot", "title": "\u52a0\u6cd5\u8fd0\u7b97\u7684\u89e3\u91ca\u57fa\u4e8e\u5bf9\u5e94\u7684\u65b9\u6cd5\u548c\u5b9a\u4e49\u7684\u65b9\u6cd5"}, {"group": "Subtopic", "id": 369, "label": "\u53d1\u73b0\u95ee\u9898\u4e0e\u63d0\u51fa\u95ee\u9898", "shape": "dot", "title": "\u53d1\u73b0\u95ee\u9898\u4e0e\u63d0\u51fa\u95ee\u9898\u4f53\u73b0\u521b\u65b0\u610f\u8bc6"}, {"group": "Subtopic", "id": 385, "label": "\u81ea\u7136\u6570", "shape": "dot", "title": "\u81ea\u7136\u6570\u662f\u5bf9\u6570\u91cf\u7684\u62bd\u8c61"}, {"group": "Topic", "id": 398, "label": "\u9644\u5f55\u5185\u5bb9", "shape": "dot", "title": "\u5c0f\u5b66\u6570\u5b66\u76f8\u5173\u8bdd\u9898\u548c\u6559\u5b66\u8bbe\u8ba1"}, {"group": "Subtopic", "id": 377, "label": "\u76f8\u5173\u6559\u5b66\u8bbe\u8ba1", "shape": "dot", "title": "\u5c0f\u5b66\u6570\u5b66\u6559\u5b66\u8bbe\u8ba1\u793a\u4f8b"}, {"group": "Subtopic", "id": 374, "label": "\u7b26\u53f7\u610f\u8bc6", "shape": "dot", "title": "\u7b26\u53f7\u610f\u8bc6\u6d89\u53ca\u7528\u5b57\u6bcd\u8868\u793a\u6570\u548c\u57fa\u4e8e\u7b26\u53f7\u7684\u8fd0\u7b97"}, {"group": "Subtopic", "id": 388, "label": "\u6df7\u5408\u8fd0\u7b97", "shape": "dot", "title": "\u6df7\u5408\u8fd0\u7b97\u9075\u5faa\u5148\u4e58\u9664\u540e\u52a0\u51cf\u7684\u6cd5\u5219"}, {"group": "Subtopic", "id": 392, "label": "\u957f\u5ea6\u3001\u9762\u79ef\u3001\u4f53\u79ef", "shape": "dot", "title": "\u957f\u5ea6\u3001\u9762\u79ef\u3001\u4f53\u79ef\u662f\u5bf9\u4e00\u7ef4\u3001\u4e8c\u7ef4\u3001\u4e09\u7ef4\u7a7a\u95f4\u7269\u4f53\u7684\u5ea6\u91cf"}, {"group": "Subtopic", "id": 383, "label": "\u5e73\u5747\u6570", "shape": "dot", "title": "\u5e73\u5747\u6570\u662f\u7edf\u8ba1\u5b66\u4e2d\u7684\u91cd\u8981\u6982\u5ff5"}, {"group": "Subtopic", "id": 376, "label": "\u6570\u636e\u7684\u968f\u673a\u6027", "shape": "dot", "title": "\u6570\u636e\u7684\u968f\u673a\u6027\u4e0e\u4e0d\u786e\u5b9a\u6027\u533a\u522b"}, {"group": "Subtopic", "id": 373, "label": "\u6570\u611f", "shape": "dot", "title": "\u5173\u4e8e\u6570\u4e0e\u6570\u91cf\u3001\u6570\u91cf\u5173\u7cfb\u3001\u8fd0\u7b97\u7ed3\u679c\u4f30\u8ba1\u7684\u611f\u609f"}, {"group": "Subtopic", "id": 367, "label": "\u51cf\u6cd5\u8fd0\u7b97", "shape": "dot", "title": "\u51cf\u6cd5\u662f\u52a0\u6cd5\u7684\u9006\u8fd0\u7b97"}, {"group": "Subtopic", "id": 390, "label": "\u6570\u636e\u5206\u6790\u89c2\u5ff5", "shape": "dot", "title": "\u7edf\u8ba1\u5b66\u4ee5\u6570\u636e\u4e3a\u57fa\u7840\uff0c\u5f3a\u8c03\u6570\u636e\u5206\u6790\u89c2\u5ff5"}, {"group": "Subtopic", "id": 386, "label": "\u5206\u6570", "shape": "dot", "title": "\u5206\u6570\u672c\u8eab\u662f\u6570\uff0c\u8868\u793a\u6574\u4f53\u4e0e\u7b49\u5206\u5173\u7cfb\u6216\u6bd4\u4f8b\u5173\u7cfb"}, {"group": "Subtopic", "id": 389, "label": "\u6a21\u578b", "shape": "dot", "title": "\u6a21\u578b\u662f\u6570\u5b66\u4e0e\u73b0\u5b9e\u4e16\u754c\u7684\u6865\u6881"}, {"group": "Subtopic", "id": 380, "label": "\u6570\u91cf\u4e0e\u6570\u7684\u672c\u8d28", "shape": "dot", "title": "\u6570\u91cf\u662f\u5bf9\u73b0\u5b9e\u751f\u6d3b\u4e2d\u4e8b\u7269\u91cf\u7684\u62bd\u8c61"}, {"group": "Subtopic", "id": 371, "label": "\u82e5\u5e72\u8bdd\u9898", "shape": "dot", "title": "\u4e0e\u5c0f\u5b66\u6570\u5b66\u76f8\u5173\u7684\u82e5\u5e72\u8bdd\u9898"}]); + edges = new vis.DataSet([{"from": 395, "title": "INCLUDES", "to": 379}, {"from": 396, "title": "INCLUDES", "to": 381}, {"from": 396, "title": "INCLUDES", "to": 368}, {"from": 394, "title": "INCLUDES", "to": 372}, {"from": 397, "title": "INCLUDES", "to": 391}, {"from": 396, "title": "INCLUDES", "to": 382}, {"from": 394, "title": "INCLUDES", "to": 384}, {"from": 393, "title": "INCLUDES", "to": 396}, {"from": 396, "title": "INCLUDES", "to": 375}, {"from": 394, "title": "INCLUDES", "to": 378}, {"from": 397, "title": "INCLUDES", "to": 370}, {"from": 395, "title": "INCLUDES", "to": 366}, {"from": 396, "title": "INCLUDES", "to": 387}, {"from": 396, "title": "INCLUDES", "to": 369}, {"from": 395, "title": "INCLUDES", "to": 385}, {"from": 393, "title": "INCLUDES", "to": 397}, {"from": 393, "title": "INCLUDES", "to": 398}, {"from": 398, "title": "INCLUDES", "to": 377}, {"from": 396, "title": "INCLUDES", "to": 374}, {"from": 393, "title": "INCLUDES", "to": 394}, {"from": 396, "title": "INCLUDES", "to": 388}, {"from": 394, "title": "INCLUDES", "to": 392}, {"from": 397, "title": "INCLUDES", "to": 383}, {"from": 393, "title": "INCLUDES", "to": 395}, {"from": 397, "title": "INCLUDES", "to": 376}, {"from": 395, "title": "INCLUDES", "to": 373}, {"from": 396, "title": "INCLUDES", "to": 367}, {"from": 397, "title": "INCLUDES", "to": 390}, {"from": 395, "title": "INCLUDES", "to": 386}, {"from": 396, "title": "INCLUDES", "to": 389}, {"from": 395, "title": "INCLUDES", "to": 380}, {"from": 398, "title": "INCLUDES", "to": 371}]); nodeColors = {}; allNodes = nodes.get({ returnType: "Object" });