-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathdataset_aggragation.py
More file actions
31 lines (23 loc) · 998 Bytes
/
dataset_aggragation.py
File metadata and controls
31 lines (23 loc) · 998 Bytes
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
import networkx as nx
import os
def get_edge_list(file_name):
with open(file_name) as ifs:
lines = ifs.readlines()
edge_list = map(lambda line: map(int, line.strip().split()), filter(lambda ele: '#' not in ele, lines))
return edge_list
def get_undirected_graph_info(file_name):
my_edge_list = get_edge_list(file_name)
undirected_graph = nx.Graph()
undirected_graph.add_edges_from(my_edge_list)
file_info = file_name.split(os.sep)[-1].split('_')[0]
str_list = [file_info, 'nodes num:' + str(undirected_graph.number_of_nodes()), 'edges num:'
+ str(undirected_graph.number_of_edges())]
print ' | '.join(str_list)
def get_dir_info(dir_name):
my_walk = os.walk(dir_name)
my_root, sub_root_list, file_list = list(my_walk)[0]
path_list = map(lambda ele: my_root + os.sep + ele, file_list)
for my_path in path_list:
get_undirected_graph_info(my_path)
if __name__ == '__main__':
get_dir_info('../Datasets')