-
Notifications
You must be signed in to change notification settings - Fork 1
/
annotator.py
48 lines (44 loc) · 1.77 KB
/
annotator.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 sys
file1 = sys.argv[1]
with open(file1, 'r') as f:
lCount = 0
for line in f:
lCount += 1
if lCount > 100:
break
list_line = list(line)
# print(list_line)
present_word_length = 0
for i in range(len(list_line)):
if list_line[i] == '\n':
pass
elif list_line[i] == ' ':
with open('out.csv', 'a') as out:
st = list_line[i] + ',' + 'O' + '\n'
out.write(st)
out.close()
else:
if present_word_length == 0 and (list_line[i + 1] == ' ' or list_line[i + 1] == '\n'):
with open('out.csv', 'a') as out:
st = list_line[i] + ',' + 'S' + '\n'
out.write(st)
out.close()
elif present_word_length == 0 and list_line != ' ':
present_word_length += 1
with open('out.csv', 'a') as out:
st = list_line[i] + ',' + 'B' + '\n'
out.write(st)
out.close()
elif present_word_length != 0 and list_line[i + 1] != ' ':
present_word_length += 1
with open('out.csv', 'a') as out:
st = list_line[i] + ',' + 'I' + '\n'
out.write(st)
out.close()
elif present_word_length != 0 and (list_line[i + 1] == ' ' or list_line[i + 1] == '\n'):
present_word_length = 0
with open('out.csv', 'a') as out:
st = list_line[i] + ',' + 'E' + '\n'
out.write(st)
out.close()
f.close()