-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpymallet.py
49 lines (39 loc) · 1 KB
/
pymallet.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
40
41
42
43
44
45
46
47
48
import subprocess, os
import csv
#Call the mallet script
subprocess.call("./callmallet.sh")
txt_file = r"../outputs/composition.txt"
csv_file = r"../outputs/composition.csv"
other_csv = r"../outputs/test_composition.csv"
#Convert .txt to appropriate .csv
in_txt = csv.reader(open(txt_file, "rb"), delimiter = '\t')
out_csv = csv.writer(open(csv_file, 'wb'))
other_out = csv.writer(open(other_csv, 'wb'))
'''
for row in in_txt:
arr = [0] * 100
row[0] = arr [0]
for i in range(1,200):
if i%2 != 0:
continue
else:
arr[row[i]/2] = row[i-1]
other_out.csv.writerow(arr)
'''
next(in_txt, None)
for row in in_txt:
arr = [0] * 52
column_src = 0
column_dst = 0
file_info = row[1].split("_")
arr[0] = file_info[2].split("/")[5]
arr[1] = file_info[4] + " " + file_info[5].split(".")[0]
for word in row[1:]:
column_src = column_src + 1
if column_src%2 == 0:
column_dst = word
else:
arr[int(column_dst)+2] = word
#arr.append("\n")
other_out.writerow(arr)
os.remove("../outputs/composition.txt")