-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsummarize_graph_data.py
46 lines (35 loc) · 1.41 KB
/
summarize_graph_data.py
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
37
38
39
40
41
42
43
44
45
46
# Read from graphData.json
import json
from summarize import generate_summary
def main():
# Get cached from attendees.json
with open("attendees.json", "r") as f:
attendees = json.load(f)
# parse as dict
attendees = dict(attendees)
with open("graphData.json", "r") as f:
graph_data = json.load(f)
nodes = graph_data["nodes"]
links = graph_data["links"]
# Process the new nodes by changing the response using summarize.py
for i, node in enumerate(nodes):
# get node id
node_name = node["data"]["name"]
node_id = node["id"]
print(
f"({i+1}/{len(nodes)}) Processing node: {node_name}")
response = node["data"]["response"]
# If response already exists in attendees.json skip don't recompute
if node_id in attendees:
print(
f"Node {node_id}: {node_name} already exists in attendees.json")
new_response = attendees[node_id]
else:
new_response = generate_summary(response)
node["data"]["response"] = new_response
node["data"]["originalResponse"] = response
# Write the new graph data to a new file
with open("summarizedGraphData.json", "w") as f:
json.dump({"nodes": nodes, "links": links}, f)
if __name__ == '__main__':
main()