forked from Arm-Sl/Masterial-Rules-Extractions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idx_to_features.py
30 lines (26 loc) · 1.07 KB
/
idx_to_features.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
29
30
import json
import argparse
def idx_to_feature(rules, features, save_dir):
with open(rules) as json_file:
with open(features) as feature_names:
res = list()
data = json.load(json_file)
names = json.load(feature_names)
names = names["feature_names"]
for rule in data:
t = dict()
for idx in rule:
if(idx!="label"):
t[names[int(idx)]] = rule[idx]
else:
t[idx] = rule[idx]
res.append(t)
with open(save_dir, 'w') as f:
json.dump(res, f, indent=2)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="idx to features", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("--rules", type=str, default=None)
parser.add_argument("--features" , type=str, default=None)
parser.add_argument("--save-dir", type=str, default=None)
args = parser.parse_args()
idx_to_feature(args.rules, args.features, args.save_dir)