(evidence_pack: dict, *, limit: int = 20)
| 38 | |
| 39 | |
| 40 | def sanitize_reference_candidates(evidence_pack: dict, *, limit: int = 20) -> list[dict]: |
| 41 | candidates = evidence_pack.get("reference_candidates", []) or [] |
| 42 | if not isinstance(candidates, list): |
| 43 | return [] |
| 44 | try: |
| 45 | matched_candidates = resolve_reference_links(candidates[:limit], runtime_config()) |
| 46 | except Exception: |
| 47 | matched_candidates = [ |
| 48 | { |
| 49 | **candidate, |
| 50 | "wikilink": "", |
| 51 | "vault_target": "", |
| 52 | "match_status": "vault_unavailable", |
| 53 | "match_reason": "none", |
| 54 | } |
| 55 | for candidate in candidates[:limit] |
| 56 | if isinstance(candidate, dict) |
| 57 | ] |
| 58 | |
| 59 | sanitized: list[dict] = [] |
| 60 | for item in matched_candidates: |
| 61 | if not isinstance(item, dict): |
| 62 | continue |
| 63 | raw_text = normalize_whitespace(str(item.get("raw_text", ""))) |
| 64 | display_text = normalize_whitespace(str(item.get("display_text", ""))) |
| 65 | if not raw_text and not display_text: |
| 66 | continue |
| 67 | sanitized.append( |
| 68 | { |
| 69 | "raw_text": raw_text, |
| 70 | "display_text": display_text, |
| 71 | "page_hint": normalize_whitespace(str(item.get("page_hint", ""))), |
| 72 | "doi": normalize_whitespace(str(item.get("doi", ""))), |
| 73 | "arxiv_id": normalize_whitespace(str(item.get("arxiv_id", ""))), |
| 74 | "wikilink": normalize_whitespace(str(item.get("wikilink", ""))), |
| 75 | "vault_target": normalize_whitespace(str(item.get("vault_target", ""))), |
| 76 | "match_status": normalize_whitespace( |
| 77 | str(item.get("match_status", "no_vault_match")) |
| 78 | ), |
| 79 | "match_reason": normalize_whitespace(str(item.get("match_reason", "none"))), |
| 80 | } |
| 81 | ) |
| 82 | return sanitized |
| 83 | |
| 84 | |
| 85 | def figure_quality_summary(assets_wrapper: dict) -> dict[str, int]: |
no test coverage detected