Skip to content

Commit c773b2a

Browse files
committed
Amended Nodes-Edges to output graph.png
1 parent b494967 commit c773b2a

3 files changed

Lines changed: 133 additions & 15 deletions

File tree

Import-JSON.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import requests
22
import json
33

4-
# The raw URL of your JSON file
5-
RAW_URL = "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-by-id.json"
4+
url = "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/refs/heads/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-array.json" # replace with your remote JSON URL
65

7-
response = requests.get(RAW_URL)
8-
response.raise_for_status() # Checks for errors
6+
response = requests.get(url)
7+
data = response.json()
98

10-
# Load JSON data
11-
data = json.loads(response.text)
9+
# Handle if JSON is a list
10+
if isinstance(data, list):
11+
data = data[0]
1212

13-
# Now you can use 'data' as a Python dictionary or list
14-
print(data)
13+
workgroup = data.get("workgroup", "Unknown Workgroup")
14+
print(workgroup)
1515

16-
# Example: Access a specific meeting summary by ID, if your JSON structure is like { "123": {...}, ... }
17-
meeting_id = "123"
18-
if meeting_id in data:
19-
print("Meeting summary for ID 123:")
20-
print(data[meeting_id])
21-
else:
22-
print(f"No summary found for ID {meeting_id}")

Nodes-Edges.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import requests
2+
import networkx as nx
3+
import matplotlib.pyplot as plt
4+
5+
# === 1. Fetch remote JSON ===
6+
url = "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/refs/heads/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-array.json" # Replace with your URL
7+
response = requests.get(url)
8+
9+
if response.status_code != 200:
10+
raise Exception(f"Failed to fetch JSON. Status code: {response.status_code}")
11+
12+
data = response.json()
13+
14+
# === 2. Handle JSON as list or dict ===
15+
if isinstance(data, list):
16+
if len(data) == 0:
17+
raise Exception("JSON list is empty")
18+
data = data[0] # Use the first object
19+
20+
if not isinstance(data, dict):
21+
raise Exception("Unexpected JSON structure, expected dict or list of dicts")
22+
23+
# === 3. Helper function to safely get nested keys ===
24+
def safe_get(d, keys, default=None):
25+
"""
26+
Safely navigate nested dictionaries.
27+
keys: list of keys to traverse
28+
"""
29+
for key in keys:
30+
if isinstance(d, dict) and key in d:
31+
d = d[key]
32+
else:
33+
return default
34+
return d
35+
36+
# === 4. Create directed graph ===
37+
G = nx.DiGraph()
38+
39+
# Workgroup & Meeting
40+
workgroup = safe_get(data, ["workgroup"], "Unknown Workgroup")
41+
meeting_id = safe_get(data, ["workgroup_id"], "MeetingID_Unknown")
42+
meeting_info = safe_get(data, ["meetingInfo"], {})
43+
44+
G.add_node(workgroup, type="Workgroup")
45+
G.add_node(meeting_id, type="Meeting",
46+
date=meeting_info.get("date", ""),
47+
typeOfMeeting=meeting_info.get("typeOfMeeting", ""))
48+
G.add_edge(workgroup, meeting_id, relation="has_meeting")
49+
50+
# Host & Documenter
51+
host = meeting_info.get("host", "Unknown Host")
52+
documenter = meeting_info.get("documenter", "Unknown Documenter")
53+
for person in [host, documenter]:
54+
G.add_node(person, type="Person")
55+
G.add_edge(meeting_id, host, relation="hosted_by")
56+
G.add_edge(meeting_id, documenter, relation="documented_by")
57+
58+
# Attendees
59+
people_present = meeting_info.get("peoplePresent", "")
60+
for person in [p.strip() for p in people_present.split(",") if p.strip()]:
61+
G.add_node(person, type="Person")
62+
G.add_edge(meeting_id, person, relation="attended_by")
63+
64+
# Working Docs
65+
for doc in meeting_info.get("workingDocs", []):
66+
title = doc.get("title", "Untitled Document")
67+
link = doc.get("link", "")
68+
G.add_node(title, type="Document", link=link)
69+
G.add_edge(meeting_id, title, relation="references_doc")
70+
71+
# Agenda Items → ActionItems & DecisionItems
72+
for agenda in data.get("agendaItems", []):
73+
agenda_status = agenda.get("status", "unknown")
74+
agenda_id = f"Agenda_{agenda_status}"
75+
G.add_node(agenda_id, type="AgendaItem", status=agenda_status)
76+
G.add_edge(meeting_id, agenda_id, relation="has_agenda")
77+
78+
# ActionItems
79+
for action in agenda.get("actionItems", []):
80+
action_text = action.get("text", "Unnamed Action")
81+
action_id = action_text[:40] + "..." # shorten
82+
G.add_node(action_id, type="ActionItem", dueDate=action.get("dueDate", ""))
83+
G.add_edge(agenda_id, action_id, relation="has_actionItem")
84+
assignee = action.get("assignee")
85+
if assignee:
86+
G.add_node(assignee, type="Person")
87+
G.add_edge(action_id, assignee, relation="assigned_to")
88+
89+
# DecisionItems
90+
for decision in agenda.get("decisionItems", []):
91+
dec_text = decision.get("decision", "Unnamed Decision")
92+
dec_id = dec_text[:40] + "..."
93+
G.add_node(dec_id, type="DecisionItem",
94+
effect=decision.get("effect"),
95+
rationale=decision.get("rationale"))
96+
G.add_edge(agenda_id, dec_id, relation="has_decisionItem")
97+
98+
# Tags & Emotions
99+
tags = safe_get(data, ["tags"], {})
100+
for topic in tags.get("topicsCovered", "").split(","):
101+
topic = topic.strip()
102+
if topic:
103+
G.add_node(topic, type="Tag")
104+
G.add_edge(meeting_id, topic, relation="tagged_with")
105+
106+
for emotion in tags.get("emotions", "").split(","):
107+
emotion = emotion.strip()
108+
if emotion:
109+
G.add_node(emotion, type="Emotion")
110+
G.add_edge(meeting_id, emotion, relation="tagged_with")
111+
112+
# === 5. Visualize the graph ===
113+
plt.figure(figsize=(18, 12))
114+
pos = nx.spring_layout(G, seed=42)
115+
node_font_size = 8 # Configurable font size for node labels
116+
edge_font_size = node_font_size # Match edge label font size to node label font size
117+
118+
nx.draw(G, pos, with_labels=True, node_color="lightblue", node_size=2000, font_size=node_font_size)
119+
edge_labels = nx.get_edge_attributes(G, "relation")
120+
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=edge_font_size)
121+
plt.savefig("graph.png")
122+
print("Graph saved as graph.png")
123+
# To open in browser from terminal:
124+
# $BROWSER graph.png
125+

graph.png

388 KB
Loading

0 commit comments

Comments
 (0)