-
Notifications
You must be signed in to change notification settings - Fork 5
/
convert.py
61 lines (56 loc) · 1.75 KB
/
convert.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
import re
import glob
import sys
#Mise en place de la nouvelle terminologie segmOnto dans les labels
Zone = {
"Main": "MainZone",
"Default": "MainZone",
"MainZone": "MainZone",
"DropCapital": "DropCapitalZone",
"RunningTitle": "RunningTitleZone",
"Margin": "MarginTextZone",
"Numbering": "NumberingZone",
"Signatures" : "QuireMarksZone",
"Damage" : "DamageZone",
"Decoration" : "GraphicZone",
"Figure" : "GraphicZone",
"MusicNotation" : "MusicZone",
"Seal" : "SealZone",
"Stamp" : "StampZone",
"Table" : "TableZone",
"Title" : "TitlePageZone",
'DropCapitalLine' : "DropCapitalZone",
}
Line = {
'Rubric': "HeadingLine",
'Default': "DefaultLine",
'Main': "DefaultLine",
'DropCapital' : "DropCapitalLine",
'DropCapitalLine' : "DropCapitalLine",
'MusicLine' : "MusicLine",
'Numbering' : "DefaultLine",
'Interlinear' : "InterlinearLine"
}
regex = re.compile(r'LABEL="(\w+)"(\s+)DESCRIPTION="([ \w]+)"')
def replace(match):
label, space, desc = match.groups()
if desc.startswith("block type"):
if desc.endswith("Zone"):
print(f"Ignoring {label}")
return f"""LABEL="{label}"{space}DESCRIPTION="{desc}\""""
desc = f"block type {Zone[label]}"
label = Zone[label]
#data.append(label)
else:
if desc.endswith("Line"):
print(f"Ignoring {label}")
return f"""LABEL="{label}"{space}DESCRIPTION="{desc}\""""
desc = f"line type {Line[label]}"
label = Line[label]
return f"""LABEL="{label}"{space}DESCRIPTION="{desc}\""""
for file in sys.argv[1:]:
with open(file) as f:
xml = f.read()
xml = regex.sub(replace, xml)
with open(file, "w") as f:
f.write(xml)