Add visualization methods

This commit is contained in:
LarFii
2024-10-20 23:08:26 +08:00
parent 6b9430221e
commit bcd81e3a50
5 changed files with 308 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
import networkx as nx
from pyvis.network import Network
import random
# Load the GraphML file
G = nx.read_graphml('./dickens/graph_chunk_entity_relation.graphml')
# Create a Pyvis network
net = Network(notebook=True)
# Convert NetworkX graph to Pyvis network
net.from_nx(G)
# Add colors to nodes
for node in net.nodes:
node['color'] = "#{:06x}".format(random.randint(0, 0xFFFFFF))
# Save and display the network
net.show('knowledge_graph.html')