-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpret_lables.py
39 lines (33 loc) · 982 Bytes
/
interpret_lables.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
35
36
37
38
39
import json
from collections import defaultdict
## get <name coordination>
f = open("train.txt", "r")
info = f.readlines()
location = []
processed_train = []
for i in range(len(info)):
name, location = info[i].split(' ')
name = name.split('/')[-1]
location = location.split(',')
last_element = location.pop()
last_element = int(last_element.split('\\')[0])
temp = []
for loc in location:
temp.append(int(loc))
temp.append(last_element)
node = (name, temp)
processed_train.append(node)
## process labels.json
with open("labels.json") as f:
data = list(json.load(f))
## convert coordinations into labels
interpreted = []
new_dict = defaultdict(list)
f = open("train_labeled.txt", "w")
for i in range(len(processed_train)):
name, coord = processed_train[i]
temp = ''
for index in coord:
new_dict[name].append(data[index])
with open("train_labeled.json", "w") as outfile:
json.dump(new_dict, outfile)