forked from liberion1994/AA18_Project_Bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWriter.py
22 lines (18 loc) · 759 Bytes
/
Writer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# coding: utf-8
from Graph import Graph
import json
class Writer:
'''将match goal.json的Graph对象储存为json文件'''
@staticmethod
def graphToJson(graph, path):
newdict = {}
newdict["relations"] = []
newdict["objects"] = [{"id": i, "type": graph.getVertexType(i)} for i in graph.getAllVertex()]
for fromVertex in graph.getAllVertex():
for toVertex in graph.getAllVertex():
arr = graph.getEdges(fromVertex, toVertex)
if len(arr) > 0:
for edgeType in arr:
newdict["relations"].append({"type": edgeType, "source": fromVertex, "target": toVertex})
with open(path, "w") as f:
json.dump(newdict, f)