-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvert_grouper.py
34 lines (31 loc) · 1.08 KB
/
advert_grouper.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
31
32
33
34
import argparse
import json_parser as jp
# maps each label to the corresponding list of advert numbers
def group(labels):
groups = {}
for advert, label in labels.items():
if label == 'damage':
label = 'wasted'
elif label == '0':
label = 'clean'
elif label != 'unknown':
label = 'repaired'
if label not in groups:
groups[label] = [advert]
else:
groups[label].append(advert)
return groups
if __name__ == '__main__':
# parse program arguments
parser = argparse.ArgumentParser()
parser.add_argument('--path', type=str, help="Input json file path")
parser.add_argument('--target', type=str, default='paint', help="Target variable to group the adverts")
args = parser.parse_args()
# parse advert labels group the adverts by the specified target variable
labels = jp.parse(args.path, args.target, 'field')
groups = group(labels)
for label, adverts in groups.items():
print(label)
for advert in adverts:
print(advert)
print()