-
Notifications
You must be signed in to change notification settings - Fork 0
/
cor.py
116 lines (96 loc) · 3.77 KB
/
cor.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
from colorama import init, Fore, Style
import re
class CleanGABC:
def __init__(slef):
init(autoreset=True)
def color_text(self, filegabc):
with open(filegabc, "r", encoding="utf-8") as file:
content = file.read()
content = content.replace("%%", Fore.GREEN + "%%")
word_list = [
"name:",
"gabc-copyright:",
"score-copyright:",
"office-part:",
"occasion:",
"meter:",
"commentary:",
"arranger:",
"author:",
"date:",
"manuscript:",
"manuscript-reference:",
"manuscript-storage-place:",
"book:",
"language:",
"transcriber:",
"transcription-date:",
"mode:",
"user-notes:",
"annotation:",
";",
]
for word in word_list:
if word in content:
content = content.replace(
word, Style.BRIGHT + Fore.YELLOW + word + Fore.RESET
)
pos = content.find("%%")
if pos != -1:
before = content[: pos + 2]
after = content[pos + 2 :]
result = []
in_parentheses = False
in_cran = False
in_para_spe = False
for i in range(len(after)):
char = after[i]
if char in r".*+?'^${}!§|_[]":
result.append(Fore.RED + char + Fore.RESET)
elif char == "(":
if i + 1 < len(after) and after[i + 1] in r",;:":
result.append(Fore.YELLOW + char + Fore.RESET)
in_para_spe = True
else:
in_parentheses = True
result.append(Fore.CYAN + char + Fore.RESET)
elif char == ")":
if i - 1 >= 0 and after[i - 1] in r",;:":
result.append(Fore.YELLOW + char + Fore.RESET)
in_para_spe = False
else:
in_parentheses = False
result.append(Fore.CYAN + char + Fore.RESET)
elif in_para_spe:
result.append(Fore.YELLOW + char + Fore.RESET)
elif in_parentheses:
if char in r"0123456789":
result.append(Fore.GREEN + char + Fore.RESET)
else:
result.append(Fore.CYAN + char + Fore.RESET)
elif char == "<":
in_cran = True
result.append(Fore.YELLOW + char + Fore.RESET)
elif char == ">":
in_cran = False
result.append(Fore.YELLOW + char + Fore.RESET)
elif in_cran:
result.append(Fore.YELLOW + char + Fore.RESET)
elif char == "\n":
result.append(char)
else:
result.append(Fore.MAGENTA + char + Fore.RESET)
content = before + "".join(result)
print(content)
def insert_line_breaks(self, input_file, output_file):
with open(input_file, "r", encoding="utf-8") as file:
content = file.read()
print(content)
break_after_char = ["(;)", "(:)", "(::)", "(,)"]
for char in break_after_char:
content = content.replace(
char, char + "\n"
)
with open(output_file, "w", encoding="utf-8") as file:
result =file.write(content)
return output_file