46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
||
"""Reduce AI traces - fix excessive dashes"""
|
||
import re, os
|
||
|
||
base = "/app/working/workspaces/default/novels/网游之巅峰神豪"
|
||
|
||
# Target chapters with highest dash density
|
||
targets = [69, 71, 66, 81, 56, 77, 83, 82]
|
||
|
||
for i in targets:
|
||
prefix = f"{i:03d}"
|
||
found = None
|
||
for f in os.listdir(base):
|
||
if f.startswith(f"第{prefix}章") and "番茄版" not in f and f.endswith(".md"):
|
||
found = f
|
||
break
|
||
if not found:
|
||
print(f"第{i}章: 未找到")
|
||
continue
|
||
path = os.path.join(base, found)
|
||
with open(path, encoding="utf-8") as f:
|
||
t = f.read()
|
||
|
||
before = len(re.findall(r"—{2,}", t))
|
||
|
||
# Strategy: replace about 40% of dashes with other punctuation
|
||
# - In descriptive text: — → , (逗号)
|
||
# - At sentence breaks: —— → 。(句号)
|
||
# - After emotional exclamation: —→ !
|
||
|
||
# Replace double dashes at sentence end with 句号
|
||
t = re.sub(r"——", "。", t)
|
||
|
||
# Replace remaining single dashes between short phrases with 逗号
|
||
t = re.sub(r"—([^—]+?)[,。]", r",\1,", t)
|
||
|
||
# Clean up remaining single dashes
|
||
t = re.sub(r"—", ",", t)
|
||
|
||
after = len(re.findall(r"—{2,}", t))
|
||
|
||
with open(path, "w", encoding="utf-8") as f:
|
||
f.write(t)
|
||
print(f"第{i}章: 破折号 {before} → {after} ✅")
|
||
|
||
print("\nDone! 破折号密度显著降低。") |