修改属性图节点的层级结构,新增子父级关系

This commit is contained in:
wanyaokun
2024-09-24 17:11:20 +08:00
parent e0fc5381d8
commit aace9ce292
7 changed files with 494 additions and 188 deletions
+19 -1
View File
@@ -39,4 +39,22 @@ class RAGPropertyGraphStore(SimplePropertyGraphStore):
graph.nodes = kg_nodes
graph.relations = kg_relations
return cls(graph)
return cls(graph)
def save_networkx_graph(self, name: str = "kg.html") -> None:
"""Display the graph store, useful for debugging."""
import networkx as nx
G = nx.DiGraph()
for node in self.graph.nodes.values():
if isinstance(node,EntityNode):
G.add_node(node.id, label=node.name)
for triplet in self.graph.triplets:
G.add_edge(triplet[0], triplet[2], label=triplet[1])
# save to html file
from pyvis.network import Network
net = Network(notebook=False, directed=True)
net.from_nx(G)
net.write_html(name)