-
Notifications
You must be signed in to change notification settings - Fork 2
/
split.py
55 lines (49 loc) · 1.18 KB
/
split.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
import os
import re
output =[]
for j in range(22):
if j >9 :
with open('reut2-0'+str(j)+'.sgm','r') as f:
text=f.readlines()
else:
with open('reut2-00'+str(j)+'.sgm','r') as f:
text=f.readlines()
for x in text:
if 'LEWISSPLIT' in x:
test=x.split('LEWISSPLIT="')[1]
test=test.split('"')[0]
output.append(test)
f.close()
output=list(set(output))
print output
try:
os.makedirs('lewisplit')
for x in output:
os.makedirs('lewisplit/'+str(x))
except:
pass
dic={}
for x in output:
dic[x]=0
count=0
for j in range(22):
if j > 9 :
f = open('reut2-0'+str(j)+'.sgm', 'r')
else:
f= open('reut2-00'+str(j)+'.sgm', 'r')
lines=f.read()
lines=re.split('<BODY>|</BODY>',lines)
for i in range(len(lines)):
print count
count=count+1
if i%2==1:
continue
if i==len(lines)-1:
break
test = lines[i].split('LEWISSPLIT="')[1]
test = test.split('"')[0]
t=open('lewisplit/'+test+'/'+str(dic[test])+'.txt','wb')
t.write(lines[i+1])
dic[test]+=1
t.close()
f.close()