-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMatchLabels.py
More file actions
68 lines (49 loc) · 1.51 KB
/
Copy pathMatchLabels.py
File metadata and controls
68 lines (49 loc) · 1.51 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Copyright (c) 2016 Vidhya, Nandini
#Following code is available for use under MIT license. Please see the LICENSE file for details.
import os
rootdir = os.getcwd()
newdir = os.path.join(rootdir,'featurefiles')
data_file = open(os.path.join(newdir,'out_1.txt'),'r')
unprocessed_data = data_file.readlines()
labels ={}
features ={}
for line in unprocessed_data:
feature_vector = []
split_line = line.split(' ')
for element in split_line[1:-1]:
feature_vector.append(str(element))
track_id = split_line[0]
features[track_id] = feature_vector
data_file.close()
label_file = open(os.path.join(newdir,'label_1.txt'),'r')
label_data = label_file.readlines()
for line in label_data:
split_line = line.split('\t')
track_id = split_line[0]
#print (track_id)
if track_id in features:
labels[split_line[0]] = split_line[1].split('\n')[0]
delKey = []
for key in features:
if key not in labels:
#print key
delKey.append(key)
for key in delKey:
del features[key]
fout = open(os.path.join(newdir,'out_2.txt'), 'w+')
labelout = open(os.path.join(newdir,'labelout.txt'), 'w+')
for key in features:
line = key
lab = key
feature = features[key]
for s in feature:
line+= " %s" %str(s)
line+="\n"
fout.write(line)
label = labels[key]
lab+= "\t" +label
lab+= "\n"
labelout.write(lab)
#print feature, label
fout.close()
labelout.close()