File size: 1,147 Bytes
f5b1acc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# test_build_and_visualize_graph.py

import os
import sys
import json
import networkx as nx

# Add the path to access agn_service
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
from app.services.agn_service.load_graph import load_graph
from app.services.agn_service.build_graph_from_index import build_graph_from_index
from app.services.agn_service.visualize_graph import visualize_graph

# Define paths
index_file_path = "graphs/index.json"  # Path to index.json file
output_image = "test_graph_visualization.png"

# Load index data
def load_index_data(file_path):
    with open(file_path, "r") as file:
        return json.load(file)

# Main execution
if __name__ == "__main__":
    # Step 1: Load index data from index.json
    data = load_index_data(index_file_path)
    
    # Step 2: Build the graph using the data loaded from index.json
    G = build_graph_from_index(data)
    
    # Step 3: Generate and save the graph visualization
    if G:
        visualize_graph(G, output_file=output_image)
        print(f"Graph visualization generated and saved as {output_image}")
    else:
        print("Failed to build graph.")