本地清洗弹幕TXT并压缩重复刷屏内容
This commit is contained in:
@@ -981,10 +981,49 @@ class DouyuDanmuSummaryHelper:
|
||||
time_text = str(item.get("timestamp_text") or "").strip()
|
||||
nickname = str(item.get("nickname") or "").strip() or "观众"
|
||||
repeat_count = int(item.get("repeat_count", 1) or 1)
|
||||
repeat_suffix = f" [重复{repeat_count}次]" if repeat_count > 1 else ""
|
||||
lines.append(f"[{time_text}] {nickname}:{content}{repeat_suffix}")
|
||||
normalized_content = cls._format_llm_transcript_content(content, repeat_count)
|
||||
# 本地清洗给 LLM 的 txt 时,统一移除 UID。
|
||||
# UID 对日报写作没有帮助,还会占 token、污染阅读流。
|
||||
lines.append(f"[{time_text}] {nickname}:{normalized_content}")
|
||||
return lines
|
||||
|
||||
@classmethod
|
||||
def _format_llm_transcript_content(cls, content: str, repeat_count: int) -> str:
|
||||
"""
|
||||
规范化给 LLM 的弹幕正文显示形式。
|
||||
目标:
|
||||
1. 像“哈哈哈”“666”“?”这类典型短刷屏,直接压成 `哈哈哈*120`;
|
||||
2. 正常讨论内容仍保留原句,只在后面标一次重复次数;
|
||||
3. 既减小文本体积,又尽量不牺牲讨论语义。
|
||||
"""
|
||||
text = str(content or "").strip()
|
||||
count = int(repeat_count or 1)
|
||||
if count <= 1:
|
||||
return text
|
||||
if cls._should_compact_burst_text(text):
|
||||
return f"{text}*{count}"
|
||||
return f"{text} [重复{count}次]"
|
||||
|
||||
@classmethod
|
||||
def _should_compact_burst_text(cls, content: str) -> bool:
|
||||
"""
|
||||
判断某条弹幕是否属于“适合压缩成 xN”的短刷屏文本。
|
||||
这里故意保持保守,只压缩:
|
||||
1. 已知短 burst 词;
|
||||
2. 纯问号/感叹号/句号等情绪符号;
|
||||
3. 很短、且由同类字符重复组成的刷屏文本。
|
||||
"""
|
||||
text = str(content or "").strip().lower()
|
||||
if not text:
|
||||
return False
|
||||
if text in cls.SHORT_BURST_WORDS:
|
||||
return True
|
||||
if re.fullmatch(r"[??!!。\.~~]+", text):
|
||||
return True
|
||||
if len(text) <= 8 and len(set(text)) <= 3:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def _build_chronological_samples(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user