forked from udieckmann/Kielipankki-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvrt-simple-mend
executable file
·56 lines (42 loc) · 1.49 KB
/
vrt-simple-mend
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
#! /usr/bin/env python3
# -*- mode: Python; -*-
from vrtargslib import trans_args, trans_main
def parsearguments():
description = '''
Mend torn sentences by simply removing sen.ten.ce tags and
sentence-tag pairs within sen.ten.ce, with no adjustment to
tokens.
'''
parser = trans_args(description = description)
args = parser.parse_args()
args.prog = parser.prog
return args
def main(args, ins, ous):
def issome(line): return not line.isspace()
keep = True
look = False
for line in filter(issome, ins):
# outside <sen.ten.ce>, keep everything;
# inside <sen.ten.ce>, drop sentence tags
# but look for a first sentence start tag;
# at </sen.ten.ce> close the <sentence>
# (unless still looking for it to start)
if line.startswith(('<sen.ten.ce>', '<sen.ten.ce ')):
keep = False
look = True
continue
if line.startswith('</sen.ten.ce>'):
look or print('</sentence>', file = ous)
keep = True
look = False
continue
if line.startswith(('<sentence>', '<sentence ')):
(keep or look) and print(line, end = '', file = ous)
if look: look = False
continue
if line.startswith('</sentence>'):
keep and print(line, end = '', file = ous)
continue
print(line, end = '', file = ous)
if __name__ == '__main__':
trans_main(parsearguments(), main)