update m3tpostprocess
This commit is contained in:
@@ -140,24 +140,31 @@ def process_circus_line(data: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def replace_quote_str(s) -> str:
|
def replace_quote_str(s) -> str:
|
||||||
|
all_left_quotes = set(CJK_LEFT_QUOTE + NEED_REPLACED_LEFT_QUOTE)
|
||||||
|
all_right_quotes = set(CJK_RIGHT_QUOTE + NEED_REPLACED_RIGHT_QUOTE)
|
||||||
|
starts_with_left = len(s) > 0 and s[0] in all_left_quotes
|
||||||
|
ends_with_right = len(s) > 0 and s[-1] in all_right_quotes
|
||||||
|
# 引号只出现在头尾时(整个字符串被引号包裹),最外层使用「」;
|
||||||
|
# 否则最外层使用『』
|
||||||
|
offset = 0 if (starts_with_left and ends_with_right) else 1
|
||||||
depth = 0
|
depth = 0
|
||||||
re = ""
|
result = ""
|
||||||
for c in s:
|
for c in s:
|
||||||
if c in CJK_LEFT_QUOTE:
|
if c in CJK_LEFT_QUOTE:
|
||||||
re += CJK_LEFT_QUOTE[depth % 2]
|
result += CJK_LEFT_QUOTE[(depth + offset) % 2]
|
||||||
depth += 1
|
depth += 1
|
||||||
elif c in CJK_RIGHT_QUOTE:
|
elif c in CJK_RIGHT_QUOTE:
|
||||||
depth -= 1
|
depth -= 1
|
||||||
re += CJK_RIGHT_QUOTE[depth % 2]
|
result += CJK_RIGHT_QUOTE[(depth + offset) % 2]
|
||||||
elif c in NEED_REPLACED_LEFT_QUOTE:
|
elif c in NEED_REPLACED_LEFT_QUOTE:
|
||||||
re += CJK_LEFT_QUOTE[depth % 2]
|
result += CJK_LEFT_QUOTE[(depth + offset) % 2]
|
||||||
depth += 1
|
depth += 1
|
||||||
elif c in NEED_REPLACED_RIGHT_QUOTE:
|
elif c in NEED_REPLACED_RIGHT_QUOTE:
|
||||||
depth -= 1
|
depth -= 1
|
||||||
re += CJK_RIGHT_QUOTE[depth % 2]
|
result += CJK_RIGHT_QUOTE[(depth + offset) % 2]
|
||||||
else:
|
else:
|
||||||
re += c
|
result += c
|
||||||
return re
|
return result
|
||||||
|
|
||||||
|
|
||||||
def check_dialogue(source: str, target: str) -> str:
|
def check_dialogue(source: str, target: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user