feat(graph): warn on low citing-paper coverage in graph report (R-D)
Add graph.citing_coverage() (papers with >=1 out-edge / total) and a graph_min_citing_coverage setting (default 0.8). codex graph report now surfaces 'Citing coverage: N/M papers with out-edges (P%)' in text and JSON, and warns when the share is below threshold -- low citing coverage starves PageRank/coupling even when the paper count looks healthy (the DQ-1 sub-item). Separate from the existing total-count graph_min_corpus_size warning. Tests: citing_coverage unit tests + CLI tests (line shown, warning fires/suppressed, JSON field). Full suite green; ruff + mypy clean. Live: graph report shows 29/29 (100%), no warning. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -100,6 +100,20 @@ def citation_pagerank(graph: nx.DiGraph, *, damping: float = 0.85) -> dict[str,
|
||||
return cast(dict[str, float], nx.pagerank(graph, alpha=damping))
|
||||
|
||||
|
||||
def citing_coverage(graph: nx.DiGraph, known_ids: set[str]) -> tuple[int, int]:
|
||||
"""Return ``(papers_with_out_edges, total_papers)`` — the citing-paper coverage.
|
||||
|
||||
A paper "covers" the citation graph when it has ≥1 out-edge (it cites at least
|
||||
one work). Low citing coverage starves the F-15 layer (PageRank / coupling /
|
||||
co-citation) even when the total paper count looks healthy, because those
|
||||
metrics are driven by out-edges, not by node count. Surfaced by
|
||||
``codex graph report`` (R-D); the warning threshold is
|
||||
:attr:`codex.config.Settings.graph_min_citing_coverage`.
|
||||
"""
|
||||
n_citing = sum(1 for pid in known_ids if pid in graph and graph.out_degree(pid) > 0)
|
||||
return n_citing, len(known_ids)
|
||||
|
||||
|
||||
def find_related(paper_id: str, graph: nx.DiGraph, *, min_shared: int = 2) -> list[str]:
|
||||
"""Bibliographic coupling: papers sharing ≥ ``min_shared`` references with ``paper_id``.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user