Ver código fonte

decompose:① is_empty=true 时短路,跳过 ②③⑤

读懂判无知识 → 该帖直接 knowledges:[] + no_knowledge:true,不浪费 LLM、不造假颗。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SamLee 1 mês atrás
pai
commit
b05ecd62be
1 arquivos alterados com 10 adições e 5 exclusões
  1. 10 5
      scripts/decompose.py

+ 10 - 5
scripts/decompose.py

@@ -42,7 +42,7 @@ def read_post(cid: str, extractor: GeminiExtractor):
     if ec.from_image:
         parts.append("【图片要点】\n" + ec.from_image)
     parts += [f"【卡片{c.index}】{c.content}" for c in ec.cards if c.content]
-    return post, "\n\n".join(p for p in parts if p)
+    return post, "\n\n".join(p for p in parts if p), bool(ec.is_empty)
 
 
 # ---------- ② 判颗+成形+轻标签 ----------
@@ -163,7 +163,14 @@ def main() -> None:
     posts_out, payloads = [], []
     for cid in CIDS:
         print(f"\n=== {cid[:8]} ===")
-        post, read = read_post(cid, extractor)
+        post, read, is_empty = read_post(cid, extractor)
+        meta = {"post_id": cid, "title": post.title or "", "platform": post.platform,
+                "url": post.url, "img_base": f"/data/demo/xiaohongshu/xhs_{cid}",
+                "img_count": len(post.image_urls)}
+        if is_empty:  # ① 总闸:判无知识 → 不走 ②③⑤
+            print(f"  ① 读懂 {len(read)} 字 → 判定无可提取的创作知识,跳过拆颗")
+            posts_out.append({**meta, "no_knowledge": True, "knowledges": []})
+            continue
         print(f"  ① 读懂 {len(read)} 字")
         knowledges = shape(post, read)
         # 守卫:组件颗 parent 必须指向同帖一个 how,否则降级为 orphan 主颗
@@ -176,9 +183,7 @@ def main() -> None:
         print(f"  ② {len(knowledges)} 颗:" + ", ".join(f"{k.get('type')}/{k.get('role')}" for k in knowledges))
         apply_scopes(knowledges, scope_candidates(knowledges), linker)
         print("  ③⑤ 作用域回扣 + 组装")
-        posts_out.append({"post_id": cid, "title": post.title or "", "platform": post.platform,
-                          "url": post.url, "img_base": f"/data/demo/xiaohongshu/xhs_{cid}",
-                          "img_count": len(post.image_urls), "knowledges": knowledges})
+        posts_out.append({**meta, "knowledges": knowledges})
         payloads += [build_payload(post, k, how_titles) for k in knowledges]
     (ROOT / "web/frameworks.json").write_text(
         json.dumps({"count": len(posts_out), "posts": posts_out}, ensure_ascii=False, indent=1), encoding="utf-8")