1234
This commit is contained in:
parent
018d647783
commit
5c3a2cb65a
14
04.py
14
04.py
@ -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
16062
text_target/ch2/en.json
16062
text_target/ch2/en.json
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user