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

Method convert2json

tf_euler/python/dataset/reddit.py:64–97  ·  view source on GitHub ↗
(self, convert_dir, out_dir)

Source from the content-addressed store, hash-verified

62 reddit_zip.extractall(out_dir)
63
64 def convert2json(self, convert_dir, out_dir):
65 prefix = os.path.join(convert_dir, 'reddit')
66 G, feats, id_map, walks, class_map = load_data(prefix)
67 out_test = open(self.id_file, 'w')
68 with open(out_dir, 'w') as out:
69 buf = {}
70 buf["nodes"] = []
71 buf["edges"] = []
72 for node_id in tqdm.tqdm(G.nodes()):
73 node_buf = {}
74 idx = id_map[node_id]
75 node_buf['id'] = idx
76 node_buf['type'] = get_node_type(G.node[node_id])
77 if node_buf['type'] == 'test':
78 out_test.write(str(idx) + '\n')
79 node_buf['weight'] = len(G[node_id])
80 node_buf['features'] = [{}, {}]
81 node_buf['features'][0]['name'] = 'label'
82 node_buf['features'][0]['type'] = 'dense'
83 node_buf['features'][0]['value'] = [class_map[node_id]]
84 node_buf['features'][1]['name'] = 'feature'
85 node_buf['features'][1]['type'] = 'dense'
86 node_buf['features'][1]['value'] = list(feats[idx])
87 buf["nodes"].append(node_buf)
88 for dst_id in G[node_id]:
89 ebuf = {"src": idx,
90 "dst": id_map[dst_id],
91 "type": get_edge_type(G[node_id][dst_id]),
92 "weight": 1,
93 "features": []
94 }
95 buf["edges"].append(ebuf)
96 out.write(json.dumps(buf))
97 out_test.close()

Callers

nothing calls this directly

Calls 6

load_dataFunction · 0.85
get_node_typeFunction · 0.85
get_edge_typeFunction · 0.85
nodesMethod · 0.80
writeMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected