提取关键发现(取前几个二级标题或加粗项)
(content: str, max_items: int = 3)
| 45 | |
| 46 | |
| 47 | def extract_key_findings(content: str, max_items: int = 3) -> list[str]: |
| 48 | """提取关键发现(取前几个二级标题或加粗项)""" |
| 49 | # 尝试提取##标题 |
| 50 | headings = re.findall(r'^##\s+(.+)$', content, re.MULTILINE) |
| 51 | if headings: |
| 52 | return headings[:max_items] |
| 53 | |
| 54 | # fallback: 提取加粗项 |
| 55 | bolds = re.findall(r'\*\*(.+?)\*\*', content) |
| 56 | if bolds: |
| 57 | return bolds[:max_items] |
| 58 | |
| 59 | # fallback: 取前3个非空行 |
| 60 | lines = [l.strip() for l in content.split('\n') if l.strip() and not l.startswith('#')] |
| 61 | return [l[:50] + '...' if len(l) > 50 else l for l in lines[:max_items]] |
| 62 | |
| 63 | |
| 64 | def find_contradictions(files: dict[str, str]) -> list[str]: |