-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa_data.py
30 lines (28 loc) · 1.05 KB
/
qa_data.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
import xlrd
import codecs
data = xlrd.open_workbook('knowledge/qa.xlsx')
sheet2 = data.sheet_by_index(0)
cols0 = sheet2.col_values(0)
cols1 = sheet2.col_values(1)
cols2 = sheet2.col_values(2)
n=0
line_seen=set()
with codecs.open('qa_data.txt','w',encoding='utf8') as f1, codecs.open('my_data.txt','w',encoding='utf8') as f2:
for i in range(sheet2.nrows):
if cols1[i] != '':
if cols0[i] not in line_seen:
line_seen.add(cols0[i])
n+=1
f1.write(cols0[i]+'|&|'+cols1[i])
f1.write('\n')
f2.write('text,intent,'+'slot'+str(n))
f2.write('\n')
a2=cols2[i]
f2.write(cols0[i] + '|intent' + str(n) + '|' + a2.replace(' ',','))
f2.write('\n')
else:
if cols0[i] not in line_seen:
line_seen.add(cols0[i])
a2=cols2[i]
f2.write(cols0[i] + '|intent' + str(n) + '|' + a2.replace(' ',','))
f2.write('\n')