-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_corr_res.py
28 lines (22 loc) · 1 KB
/
merge_corr_res.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
from collections import defaultdict
func_candi = defaultdict(set)
import json
def json_pretty_dump(obj, filename):
with open(filename, "w") as fw:
json.dump(obj,fw, sort_keys=True, indent=4, separators=(",", ": "), ensure_ascii=False)
import os
for file in os.listdir("../mid-data/func_candi_tuple_lst"):
if file.endswith(".txt"):
print(file)
with open(os.path.join("../mid-data/func_candi_tuple_lst", file), "r") as rf:
for line in rf:
func, tri_tuple_lst = line.strip().split(":")
for tri_tuple_str in tri_tuple_lst.split('\t'):
func_candi[func].add(tri_tuple_str)
#print(len(func_candi))
func_candi_json = {func:[] for func in func_candi}
for func, tri_tuple_set in func_candi.items():
for tri_tuple_str in tri_tuple_set:
[candi, lag, corr_rate] = tri_tuple_str.split(',')
func_candi_json[func].append((candi, int(lag), float(corr_rate)))
json_pretty_dump(func_candi_json, "../mid-data/func_candi.json")