-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_typo.py
More file actions
70 lines (54 loc) · 1.81 KB
/
fix_typo.py
File metadata and controls
70 lines (54 loc) · 1.81 KB
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
#!/usr/bin/env python3
"""
Simple script to fix monogr title typo in MEI files
"""
import glob
from lxml import etree
def fix_typo_in_file(file_path):
"""Fix the typo in a single MEI file"""
try:
# Parse XML
tree = etree.parse(file_path)
root = tree.getroot()
# Find monogr/title element
namespaces = {"mei": "http://www.music-encoding.org/ns/mei"}
monogr_titles = root.xpath(
"//mei:monogr/mei:title", namespaces=namespaces
)
if not monogr_titles:
return False, "No monogr/title found"
title = monogr_titles[0]
if title.text and "kustliche vnerweisung" in title.text:
# Fix typo
title.text = title.text.replace(
"kustliche vnerweisung", "kunstliche vnderweisung"
)
# Save
tree.write(
file_path,
encoding="UTF-8",
xml_declaration=True,
pretty_print=True,
)
return True, "Fixed typo"
return False, "No typo found"
except Exception as e:
return False, f"Error: {e}"
def main():
# Process all MEI files, excluding the "converted" folder
mei_files = glob.glob("**/*.mei", recursive=True)
mei_files = [f for f in mei_files if not f.startswith("converted/")]
print(f"Processing {len(mei_files)} MEI files (excluding converted folder)")
fixed = 0
for file_path in mei_files:
success, message = fix_typo_in_file(file_path)
if success:
fixed += 1
elif (
"No typo found" not in message
and "No monogr/title found" not in message
):
print(f"✗ {file_path}: {message}")
print(f"\nFixed {fixed} files total")
if __name__ == "__main__":
main()