-
Notifications
You must be signed in to change notification settings - Fork 2
/
trimTei.py
119 lines (98 loc) · 2.5 KB
/
trimTei.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import sys
from lib import REPO, VERSION_SRC, parseArgs, trim
from trimTei0 import (
corpusPre as a0,
trimVolume as v0,
trimDocBefore as b0,
trimDocPrep as d0,
trimPage as t0,
processPage as p0,
trimDocPost as e0,
corpusPost as c0,
)
from trimTei1 import (
corpusPre as a1,
trimVolume as v1,
trimDocBefore as b1,
trimDocPrep as d1,
trimPage as t1,
processPage as p1,
trimDocPost as e1,
corpusPost as c1,
)
from trimTei2 import (
corpusPre as a2,
trimVolume as v2,
trimDocBefore as b2,
trimDocPrep as d2,
trimPage as t2,
processPage as p2,
trimDocPost as e2,
corpusPost as c2,
)
from trimTei3 import (
corpusPre as a3,
trimVolume as v3,
trimDocBefore as b3,
trimDocPrep as d3,
trimPage as t3,
processPage as p3,
trimDocPost as e3,
corpusPost as c3,
)
corpusPre = [a0, a1, a2, a3]
trimVolume = [v0, v1, v2, v3]
trimDocBefore = [b0, b1, b2, b3]
trimDocPrep = [d0, d1, d2, d3]
trimPage = [t0, t1, t2, t3]
processPage = [p0, p1, p2, p3]
trimDocPost = [e0, e1, e2, e3]
corpusPost = [c0, c1, c2, c3]
HELP = f"""
Convert TEI source to simplified pseudo TEI,
stage {{stage}} (must be 0 .. {len(trimPage) - 1}).
python3 trimTei.py {{stage}} [volume] [page] [--help]
--help: print this text amd exit
volume: only process this volume; default: all volumes
page : only process letter that starts at this page; default: all letters
"""
def main():
args = [] if len(sys.argv) == 1 else list(sys.argv[1:])
if "--help" in args:
print(HELP.format(stage="?"))
return True
if len(args) == 0:
print("Specify a stage!")
print(HELP.format(stage="?"))
return False
stage = args.pop(0)
if stage.isdigit():
stage = int(stage)
else:
print(f"{stage} is not a number!")
print(HELP.format(stage=stage))
return False
if stage >= len(trimPage):
print(HELP.format(stage=stage))
return False
(good, vol, lid, kwargs, pargs) = parseArgs(args)
if not good:
return False
print(f"TEI trimmer stage {stage} for {REPO}")
print(f"TEI source version = {VERSION_SRC}")
return trim(
stage,
vol,
lid,
corpusPre[stage],
trimVolume[stage],
trimDocBefore[stage],
trimDocPrep[stage],
trimPage[stage],
processPage[stage],
trimDocPost[stage],
corpusPost[stage],
*pargs,
**kwargs,
)
sys.exit(0 if main() else 1)