-
Notifications
You must be signed in to change notification settings - Fork 5
/
vislcg3-to-conllx-input.py
63 lines (61 loc) · 1.5 KB
/
vislcg3-to-conllx-input.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
import sys, re;
rword = re.compile('"<(.+)>"');
rbase = re.compile('"(.+)"');
rcateg = re.compile(' ([_A-Za-z0-9]+)');
toknum = 0;
buffer = '';
for line in sys.stdin.readlines(): #{
if line.strip() == '': #{
toknum = toknum + 1;
if buffer != '': #{
# toknum = toknum + 1;
buffer = buffer.split('\n');
ord = rword.findall(buffer[0])[0].replace(' ', '·');
lem = rbase.findall(buffer[1])[0].replace(' ', '·');
categs = rcateg.findall(buffer[1]);
pos = '_'
if len(categs) > 0: #{
pos = categs[0];
#}
msd = '_';
if len(categs) > 1: #{
msd = '';
for i in categs[1:]: #{
msd = msd + i.strip() + '|';
#}
msd = msd.strip('|');
#}
print('%d\t%s\t%s\t_\t%s\t%s' % (toknum, ord, lem, pos, msd));
# print(toknum, buffer, file=sys.stderr);
#}
toknum = 0;
buffer = '';
print('');
elif line[0] == '"': #{
if buffer != '': #{
toknum = toknum + 1;
buffer = buffer.split('\n');
ord = rword.findall(buffer[0])[0].replace(' ', '·');
lem = rbase.findall(buffer[1])[0].replace(' ', '·');
categs = rcateg.findall(buffer[1]);
pos = '_'
if len(categs) > 0: #{
pos = categs[0];
#}
msd = '_';
if len(categs) > 1: #{
msd = '';
for i in categs[1:]: #{
msd = msd + i.strip() + '|';
#}
msd = msd.strip('|');
#}
print('%d\t%s\t%s\t_\t%s\t%s' % (toknum, ord, lem, pos, msd));
# print(toknum, buffer, file=sys.stderr);
#}
buffer = '';
buffer = buffer + line;
elif line[0] == '\t': #{
buffer = buffer + line;
#}
#}