This commit is contained in:
ws3917 2025-05-14 13:19:01 +08:00
parent 018d647783
commit 5c3a2cb65a
6 changed files with 27479 additions and 40568 deletions

14
04.py
View File

@ -21,23 +21,27 @@ def restore_text(key, text, source_text):
def replace_newline(m): def replace_newline(m):
return "#" if "#" in original else "&" return "#" if "#" in original else "&"
text = re.sub(r"\\\n", replace_newline, text) text = re.sub(r"\n", replace_newline, text)
else: else:
text = text.replace("\\\n", "&") text = text.replace("\n", "&")
# 2. 恢复前缀控制符 z* 或标签 # 2. 恢复前缀控制符 z* 或标签
match_prefix = re.match(r"^(\\[A-Za-z0-9]{2}\s*)+", source_text.get(key, "")) match_prefix = re.match(r"^(\\[A-Za-z0-9]{2}\s*)+", source_text.get(key, ""))
if match_prefix: if match_prefix:
text = match_prefix.group(0) + text text = match_prefix.group(0) + text
# 4. 标点前添加停顿符 ^1
def replacer(match):
puncts = match.group(1)
return puncts[:-1] + "^1" + puncts[-1]
text = re.sub(r"(?<!\^[0-9])([。!?\?!,\.]+)(?=\s*[\w&])", replacer, text)
# 3. 恢复后缀控制符 /%*$ # 3. 恢复后缀控制符 /%*$
match_suffix = re.search(r"/%*\$$", source_text.get(key, "")) match_suffix = re.search(r"/%*\$$", source_text.get(key, ""))
if match_suffix: if match_suffix:
text = text + match_suffix.group(0) text = text + match_suffix.group(0)
# 4. 标点前添加停顿符 ^1
text = re.sub(r"(?<!\^1)([,。!?)】,!?]|\.\.\.)", r"^1\1", text)
return text return text

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff