MCPcopy Create free account
hub / github.com/alibaba/euler / gen_graph_json

Function gen_graph_json

tf_euler/python/dataset/multigraph_util.py:68–101  ·  view source on GitHub ↗
(edge_list, indicator_list, graph_labels, node_labels)

Source from the content-addressed store, hash-verified

66
67
68def gen_graph_json(edge_list, indicator_list, graph_labels, node_labels):
69 graph = {}
70 graph['nodes'] = []
71 graph['edges'] = []
72 print("Total nodes: {}.".format(len(node_labels)))
73 for i in range(len(node_labels)):
74 node_id = i
75 node_label = [node_labels[i]]
76 node_graph_label = [graph_labels[indicator_list[i]]]
77 graph_indicator = str(indicator_list[i])
78 features = [{'name': 'f1',
79 'type': 'sparse',
80 'value': node_label},
81 {'name': 'label',
82 'type': 'dense',
83 'value': node_graph_label},
84 {'name': 'graph_label',
85 'type': 'binary',
86 'value': graph_indicator}]
87 node = {'id': node_id,
88 'type': node_labels[i],
89 'weight': 1,
90 'features': features}
91 graph['nodes'].append(node)
92 for one_edge in edge_list:
93 src = one_edge[0]
94 dst = one_edge[1]
95 edge = {'src': src,
96 'dst': dst,
97 'type': 0,
98 'weight': 1,
99 'features': []}
100 graph['edges'].append(edge)
101 return json.dumps(graph)
102

Callers 1

convert2jsonMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected