Download _scripts/make_cite_influence.py from imecai/cl-agentic-vault: direct link, hf CLI and curl.
- Browser
- Download file 6.44 kB
-
https://huggingface.co/datasets/imecai/cl-agentic-vault/resolve/main/_scripts/make_cite_influence.py
- Command line
-
hf download hf://datasets/imecai/cl-agentic-vault/_scripts/make_cite_influence.py
-
curl -L -o make_cite_influence.py https://huggingface.co/datasets/imecai/cl-agentic-vault/resolve/main/_scripts/make_cite_influence.py
6.44 kB
| #!/usr/bin/env python3 | |
| """Scatter of external citations vs in-graph influence for the top influencers. | |
| x = real-world citation count (log scale); y = in-graph influence (how many | |
| corpus papers `builds-on` it). Median lines split the plane into quadrants: | |
| canonical (high/high), sleeping beauties (high influence / low citation), | |
| broadly-cited-but-less-built-on (high citation / low influence), and niche. | |
| Reads a JSON produced by the citation fetch (default /tmp/cif.json), of the form | |
| {slug: {"influence": int, "year": int, "title": str, "cites": int|null}} | |
| and writes one self-contained HTML page (D3 from CDN). Citation counts come from | |
| Semantic Scholar's batch endpoint (slightly below Google Scholar but close); the | |
| fetch recipe (batch by arXiv id in one request, title-search fallback, <=1 req/s) | |
| is in skills/visualize-graph/SKILL.md. This script only draws the scatter. | |
| python3 _scripts/make_cite_influence.py --data /tmp/cif.json --out reports/cite-vs-influence.html | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import re | |
| VAULT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| def short(slug): | |
| m = re.match(r"[a-z]+\d{4}-(.+)", slug) | |
| return (m.group(1) if m else slug).replace("-", " ") | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--data", default="/tmp/cif.json") | |
| ap.add_argument("--out", default="reports/cite-vs-influence.html") | |
| ap.add_argument("--title", default="Citations vs in-graph influence") | |
| a = ap.parse_args() | |
| raw = json.load(open(a.data, encoding="utf-8")) | |
| pts = [{"slug": s, "label": short(s), "cites": v["cites"], | |
| "infl": v["influence"], "year": v.get("year") or 0} | |
| for s, v in raw.items() if v.get("cites") is not None] | |
| pts.sort(key=lambda p: -p["infl"]) | |
| data = json.dumps(pts) | |
| html = TEMPLATE.replace("__DATA__", data).replace("__TITLE__", a.title) | |
| out = a.out if os.path.isabs(a.out) else os.path.join(VAULT, a.out) | |
| os.makedirs(os.path.dirname(out), exist_ok=True) | |
| open(out, "w", encoding="utf-8").write(html) | |
| print(f"wrote {out}: {len(pts)} points") | |
| TEMPLATE = r'''<!doctype html> | |
| <html lang="en"><head> | |
| <meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/> | |
| <title>__TITLE__</title> | |
| <script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script> | |
| <style> | |
| :root{--bg:#fbfaf8;--ink:#1a1a1f;--muted:#6b6b78;--line:#e7e4de} | |
| *{box-sizing:border-box} body{margin:0;background:var(--bg);color:var(--ink); | |
| font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif} | |
| .wrap{max-width:1000px;margin:0 auto;padding:22px} | |
| h1{font:600 21px/1.2 Georgia,serif;margin:0 0 4px} | |
| p.sub{color:var(--muted);margin:0 0 4px;font-size:13.5px;max-width:720px} | |
| .quad{fill:#9a9aa8;font-size:12px;font-weight:600;opacity:.5} | |
| .axlbl{fill:var(--muted);font-size:12px} | |
| .pt{stroke:#fff;stroke-width:1;cursor:pointer} | |
| .plabel{font-size:10.5px;fill:var(--ink);pointer-events:none;paint-order:stroke;stroke:#fbfaf8;stroke-width:3px;stroke-linejoin:round} | |
| .grid line{stroke:#eceae4} .grid path{stroke:none} | |
| #tip{position:fixed;pointer-events:none;background:#1a1a1f;color:#fff;padding:6px 9px;border-radius:6px;font-size:12px;opacity:0;transition:opacity .1s;z-index:9;max-width:240px} | |
| </style></head><body> | |
| <div class="wrap"> | |
| <h1>__TITLE__</h1> | |
| <p class="sub">The 50 papers most built-on within the corpus. <b>x</b> = external citations (Semantic Scholar, log scale — conservative vs Google Scholar); <b>y</b> = in-graph influence (how many corpus papers build on it). Color = year. Dashed lines are medians. Hover a point for details.</p> | |
| <svg id="chart"></svg> | |
| </div> | |
| <div id="tip"></div> | |
| <script> | |
| const data=__DATA__; | |
| const M={t:24,r:20,b:46,l:52}, W=Math.min(940,innerWidth-44), H=560; | |
| const iw=W-M.l-M.r, ih=H-M.t-M.b; | |
| const svg=d3.select("#chart").attr("width",W).attr("height",H); | |
| const g=svg.append("g").attr("transform",`translate(${M.l},${M.t})`); | |
| const x=d3.scaleLog().domain([Math.max(1,d3.min(data,d=>d.cites)*0.8), d3.max(data,d=>d.cites)*1.3]).range([0,iw]); | |
| const y=d3.scaleLinear().domain([0, d3.max(data,d=>d.infl)+1]).range([ih,0]); | |
| const yr=d3.extent(data,d=>d.year); | |
| const color=d3.scaleSequential(d3.interpolateViridis).domain(yr); | |
| // grids | |
| g.append("g").attr("class","grid").attr("transform",`translate(0,${ih})`).call(d3.axisBottom(x).ticks(6,"~s").tickSize(-ih)); | |
| g.append("g").attr("class","grid").call(d3.axisLeft(y).ticks(8).tickSize(-iw)); | |
| // medians | |
| const mx=d3.median(data,d=>d.cites), my=d3.median(data,d=>d.infl); | |
| [["x",mx],["y",my]].forEach(([ax,m])=>{ | |
| g.append("line").attr("stroke","#c9b78a").attr("stroke-dasharray","5 4") | |
| .attr(ax==="x"?"x1":"y1",ax==="x"?x(m):y(m)).attr(ax==="x"?"x2":"y2",ax==="x"?x(m):y(m)) | |
| .attr(ax==="x"?"y1":"x1",0).attr(ax==="x"?"y2":"x2",ax==="x"?ih:iw); | |
| }); | |
| // quadrant labels | |
| g.append("text").attr("class","quad").attr("x",iw-6).attr("y",14).attr("text-anchor","end").text("canonical"); | |
| g.append("text").attr("class","quad").attr("x",4).attr("y",14).text("sleeping beauties"); | |
| g.append("text").attr("class","quad").attr("x",iw-6).attr("y",ih-6).attr("text-anchor","end").text("broadly cited, less built-on"); | |
| g.append("text").attr("class","quad").attr("x",4).attr("y",ih-6).text("niche"); | |
| // axis labels | |
| g.append("text").attr("class","axlbl").attr("x",iw/2).attr("y",ih+38).attr("text-anchor","middle").text("external citations (Semantic Scholar, log)"); | |
| g.append("text").attr("class","axlbl").attr("transform","rotate(-90)").attr("x",-ih/2).attr("y",-38).attr("text-anchor","middle").text("in-graph influence (papers building on it)"); | |
| // points | |
| const tip=d3.select("#tip"); | |
| g.selectAll("circle.pt").data(data).join("circle").attr("class","pt") | |
| .attr("cx",d=>x(d.cites)).attr("cy",d=>y(d.infl)).attr("r",5.5).attr("fill",d=>color(d.year)) | |
| .on("mousemove",(e,d)=>tip.style("opacity",1).style("left",(e.clientX+12)+"px").style("top",(e.clientY+12)+"px") | |
| .html(`<b>${d.slug}</b><br>${d.cites.toLocaleString()} citations · ${d.infl} build on it · ${d.year}`)) | |
| .on("mouseout",()=>tip.style("opacity",0)); | |
| // labels for the most influential + citation outliers | |
| const lab=data.filter((d,i)=>i<12 || d.cites>mx*4 || d.infl>=my+3); | |
| g.selectAll("text.plabel").data(lab).join("text").attr("class","plabel") | |
| .attr("x",d=>x(d.cites)+7).attr("y",d=>y(d.infl)+3).text(d=>d.label); | |
| </script></body></html>''' | |
| if __name__ == "__main__": | |
| main() | |