-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabelparser.py
More file actions
64 lines (48 loc) · 1.54 KB
/
labelparser.py
File metadata and controls
64 lines (48 loc) · 1.54 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
map = {}
map["Business"]= ["business"]
map["SciTech"] = ["science", "technology computing"]
map["Sports"] = ["sports"]
map["World"] = ["law govt poltics"]
map["Society and Culture"] = ["society"]
map["Science and Mathematics"] = ["science"]
map["Health"] = ["health fitness"]
map["Education and Reference"] = ["education"]
map["Computers and Internet"] = ["technology computing"]
map["Business and Finance"] = ["business"]
map["Entertainment and Music"] = ["arts entertainment"]
map["Family and Relationships"] = ["family parenting"]
map["Politics and Government"] = ["law govt politics"]
input1 = "News Classification DataSet.tsv"
file_in = open(input1, "r")
finalOut = []
firstline = file_in.readline()
for line in file_in:
separate = line.split("\t")
label = map[separate[1].rstrip()]
if(type(label) =='str'):
finalOut.append(separate[0] + '\t' + label)
else:
finalOut.append(separate[0] + '\t' + ','.join(label))
file_in.close()
fileout = open("news.tsv" , "w")
writeout = '\n'.join(finalOut)
fileout.write(firstline)
fileout.write(writeout)
fileout.close()
finalOut = []
input2 = "Yahoo QA Topic Classification.tsv"
file_in = open(input2, "r")
firstline = file_in.readline()
for line in file_in:
separate = line.split("\t")
label = map[separate[1].rstrip()]
if(type(label) =='str'):
finalOut.append(separate[0] + '\t' + label)
else:
finalOut.append(separate[0] + '\t' + ','.join(label))
file_in.close()
writeout = '\n'.join(finalOut)
fileout = open("yahoo.tsv" , "w")
fileout.write(firstline)
fileout.write(writeout)
fileout.close()