-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_conversion_id_final.py
142 lines (129 loc) · 2.98 KB
/
csv_conversion_id_final.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
# coding: utf-8
# In[101]:
import string
import sys
def csv_conversion(csv):
with open(csv, "r") as ins:
lines = ins.readlines()
array = []
for line in lines:
array.append(line)
# print(array)
list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
list6 = []
for i in array:
str1 = i.split("\t")
list1 += str1[::2]
list2 += str1[1::2]
for i in list1:
j = i.split("_", 1)
list3.append(j)
# print(list2)
# print(list3)
list7 = []
for i in list3:
list5.append(i[0])
i.remove(i[0])
list6.append((i))
# print(list5)
# print(list3)
c = 0
x = 0
list8 = []
# print(list5)
y = 0
for i in list6:
eng = []
z = int(list5[y])
for j in i:
if "_"in j:
eng = j.split("_")
if len(eng) != 0:
eng[0] = "("+eng[0]
eng[len(eng)-1] = eng[len(eng)-1]+")"
for k in range(len(eng)):
list7.insert(x, eng[k])
x += 1
list8.append(z)
z = z+1
y = y+1
else:
list7.insert(x, i[0])
x += 1
list8.append(z)
y = y+1
# print(list7)
# print(list8)
dict1 = {}
dict2 = {}
dict2 = dict(zip(list8, list7))
# print(list2)
# print(dict2)
# return dict1
hindi = []
hindi1 = []
for i in list2:
c = 0
for j in i:
if j == ":":
c = c+1
if c > 1:
hindi1 = i.split(" ")
# print(hindi1)
for k in hindi1:
hindi.append(k)
else:
hindi.append(i)
# print(hindi)
hwords = []
hwords1 = []
ewords = []
for i in hindi:
str1 = i.split(":")
ewords += str1[::2]
hwords1 += str1[1::2]
for i in hwords1:
i = i.strip("\n")
hwords.append(i)
dict1 = dict(zip(list8, hwords))
# print(dict1)
# print(dict2)
str1=str(dict1)
str2=str(dict2)
print(dict1)
print(dict2)
ll=[]; kk=[]
for k,v in sorted(dict2.items()):
ll.append(v)
final={}
print('+++++++++++++++++++++++++++++++++++++')
for i,j in zip(sorted(dict1.items()),ll):
#tmp = i[1].strip("\n").strip('?')
tmp = i[1].strip("\n").strip(' ').strip('?')
#print(tmp)
neq = tmp
if '(' in j:
#print(")))",j)
neq='('+tmp
#print(neq)
if ')' in j:
neq=tmp+')'
#print(i[0],neq)
final[i[0]]=neq
kk.append(neq)
kk.insert(0,"K_enhanced")
csv_final= ",".join(kk)
return csv_final
input_dict = sys.argv[1]
csv_final = csv_conversion(input_dict)
print(csv_final)
'''with open(output_dict, "w") as out:
out.write(output1)
with open(output_dict1, "w") as out1:
out1.write(output2)'''
# csv_conversion()