#!/usr/bin/env python3 """Re-run our count of the statements in Blanc et al. (2026) on space weather and the atmosphere below the mesosphere, its weather and its climate (rules: RULES_inventory.txt). Usage: python3 -I inventory_rerun.py [--pdf ] Needs Python 3.8 or later and the pdftotext command (Xpdf or Poppler) on the PATH; nothing else. We used pdftotext 4.00 from Xpdf, as shipped with Git for Windows. Poppler's pdftotext gives the same words but may break lines differently; the script compares every sentence with the hash we logged, so any difference in extraction shows up as a mismatch rather than a silent change. What it does: 1. Downloads the paper's PDF from Springer (CC BY 4.0) into , under a plain client name, unless --pdf names a copy, and checks it against the SHA-256 of the copy we used. On November 15, 2026, Springer answered our script with a check page meant for browsers, though it had sent the PDF to a plain download earlier the same day. If that happens, the script stops and asks for a copy downloaded in a browser, passed with --pdf. A copy whose SHA-256 differs from ours (a browser may be served a different file) gets a warning, not a stop: step 3 still checks every sentence against the hash we logged for it, so a copy with the same text gives the same result, and any difference in the text shows up there. 2. Extracts its text with `pdftotext -enc UTF-8`, keeps the abstract, highlights, sections 1-5, figure captions and Table 1, splits the text into sentences and selects the candidates by the keyword rule (step 1 of the rules). 3. Checks each candidate, and each sentence we list as missed by the filter, against the SHA-256 we logged for it in inventory-classified.csv and inventory-missed.csv. 4. Applies our classification from inventory-classified.csv (step 2: our judgment, recorded line by line) and writes the counts (step 3) to /out/inventory-summary.txt, then compares that file with the inventory-summary.txt we host. The full candidate sentences go to /out/inventory-candidates-full.csv, for checking. That text is the paper's, so we don't host it. """ import csv import hashlib import os import re import subprocess import sys import urllib.request from pathlib import Path HERE = Path(__file__).resolve().parent PDF_URL = "https://link.springer.com/content/pdf/10.1007/s10712-026-09968-1.pdf" PDF_SHA256 = "cfb48529ed52e9b84a1996ead61368eca1536b0dfa9513b87079f0690199415f" UA = {"User-Agent": "factchecked-research/1.0"} # Step 1: the keyword rule, as pre-registered A = re.compile(r"solar|\bsun\b|space weather|weather in space|geomagnetic|magnetospher|" r"particle|cosmic|\bGCR|\bSEP|solar wind|\bEUV|X-ray|irradiance|flare|" r"from above|interplanetary", re.I) B = re.compile(r"tropospher|lower atmosphere|surface|weather|climate|stratospher|ozone|" r"middle atmosphere|chemistry|\bNOx|\bHOx|polar vortex", re.I) HEAD = re.compile(r"^(\d(\.\d)?\s+[A-Z][^.]{3,90})$") HEAD_INLINE = re.compile(r"^(\d\.\d\s+[A-Z][^.]{3,90}?)\s+(The|In|An|A)\s") ABBR = ["et al.", "e.g.", "i.e.", "Fig.", "Sect.", "Eq.", "vs.", "approx."] LEADER = "․" # one-dot leader: stands in for the dot of an abbreviation while splitting def sha(b): return hashlib.sha256(b).hexdigest() def get_pdf(folder, local): path = Path(local) if local else folder / "blanc2026.pdf" if not path.exists(): req = urllib.request.Request(PDF_URL, headers=UA) with urllib.request.urlopen(req, timeout=120) as r: data = r.read() if not data.startswith(b"%PDF-"): sys.exit("Springer sent a web page, not the PDF: it may ask a browser to pass a check first. " "Download the PDF in your browser from https://doi.org/10.1007/s10712-026-09968-1 " "and run the script again with --pdf .") path.write_bytes(data) digest = sha(path.read_bytes()) if digest != PDF_SHA256: print(f"Warning: the PDF's SHA-256 is {digest}, not the {PDF_SHA256} of the copy we used. " "Going on: every sentence is still checked against the hash we logged for it.") return path, digest def pdf_text(pdf, folder): txt = folder / "blanc2026.txt" subprocess.run(["pdftotext", "-enc", "UTF-8", str(pdf), str(txt)], check=True) return txt.read_text(encoding="utf-8") def included_text(raw): """The included part of the text, as (PDF page, line) pairs.""" out, page, keep = [], 1, False for ln in raw.split("\n"): # headings carry an en space and a BEL control character between number and title s = re.sub("[ \x07]+", " ", ln).strip() if s == "Surveys in Geophysics": # the running head that starts every page after the first page += 1 continue if s.startswith("Abstract "): keep = True if s.startswith("Hermann Opgenoorth: Deceased") or s.startswith("Vol.:("): continue if s.startswith("Appendix A."): keep = False if keep and s: out.append((page, s)) return out def protect(s): for a in ABBR: s = s.replace(a, a.replace(".", LEADER)) return s def sentences(lines): section, buf, buf_page = "Abstract", "", None for page, s in lines: s = protect(s) if HEAD.match(s) and len(s) < 100 and not s.endswith("."): if buf: yield section, buf_page, buf.replace(LEADER, ".") buf = "" section = s.replace(LEADER, ".") continue mi = HEAD_INLINE.match(s) if mi and len(s) >= 100: if buf: yield section, buf_page, buf.replace(LEADER, ".") buf = "" section = mi.group(1).replace(LEADER, ".") s = s[len(mi.group(1)):].strip() if s.startswith("Article Highlights"): if buf: yield section, buf_page, buf.replace(LEADER, ".") buf = "" section = "Article Highlights" s = s[len("Article Highlights"):].strip() if not s: continue if s.startswith("Keywords"): continue if buf_page is None or not buf: buf_page = page buf = (buf + " " + s).strip() parts = re.split(r"(?<=[.?!])\s+(?=[A-Z•(])|\s*•\s*", buf) for p in parts[:-1]: if p.strip(): yield section, buf_page, p.strip().replace(LEADER, ".") buf_page = page buf = parts[-1] if buf.strip(): yield section, buf_page, buf.strip().replace(LEADER, ".") def starts_with(s, n=6): w = s.split() return " ".join(w[:n]) + (" …" if len(w) > n else "") def main(argv): if not argv or argv[0].startswith("-"): sys.exit(__doc__) folder = Path(argv[0]) local = argv[argv.index("--pdf") + 1] if "--pdf" in argv else None out = folder / "out" out.mkdir(parents=True, exist_ok=True) pdf, digest = get_pdf(folder, local) all_sents = list(sentences(included_text(pdf_text(pdf, folder)))) cands = [(sec, p, s) for sec, p, s in all_sents if A.search(s) and B.search(s)] with open(out / "inventory-candidates-full.csv", "w", encoding="utf-8", newline="") as f: w = csv.writer(f, lineterminator="\n") w.writerow(["id", "section", "pdf_page", "sentence_sha256", "sentence"]) for i, (sec, p, s) in enumerate(cands, 1): w.writerow([i, sec, p, sha(s.encode("utf-8")), s]) ours = list(csv.DictReader(open(HERE / "inventory-classified.csv", encoding="utf-8"))) missed = list(csv.DictReader(open(HERE / "inventory-missed.csv", encoding="utf-8"))) match = sum(1 for (sec, p, s), r in zip(cands, ours) if sha(s.encode("utf-8")) == r["sentence_sha256"]) if len(cands) != len(ours) or match != len(ours): print(f"Warning: {len(cands)} candidates here, {len(ours)} in our list, {match} with the same " f"text; the counts below use our classification by id.") every = {sha(s.encode("utf-8")) for _, _, s in all_sents} found = sum(1 for r in missed if r["sentence_sha256"] in every) d = [r for r in ours if r["scope"] == "D"] lines = [ "Blanc et al. (2026): statements on solar or space effects on the atmosphere below the", "mesosphere, its weather or its climate. Rules: RULES_inventory.txt", f"PDF SHA-256: {digest}" + ("" if digest == PDF_SHA256 else f" (ours: {PDF_SHA256})"), f"candidates: {len(ours)} (sentences with the same text as ours: {match} of {len(ours)})", "by scope: " + ", ".join(f"{k}={sum(r['scope'] == k for r in ours)}" for k in ("D", "U", "X")), f"D sentences: {len(d)}", "D by strength: " + ", ".join(f"{k}={sum(r['strength'] == k for r in d)}" for k in ("asserted", "hedged", "need")), "D cited: " + ", ".join(f"{k}={sum(r['cited'] == k for r in d)}" for k in ("yes", "no")), f"missed by the filter, listed and not counted: {len(missed)} (found in the text: {found} of " f"{len(missed)}; cited: {sum(r['cited'] == 'yes' for r in missed)})", "", "D sentences (id | section | PDF page | strength | cited | starts with):", ] for r in d: lines.append(f"{r['id']} | {r['section']} | p. {r['pdf_page']} | {r['strength']} | " f"{r['cited']} | {r['starts_with']}") lines += ["", "Missed by the filter (section | PDF page | strength | cited | starts with):"] for r in missed: lines.append(f"{r['section']} | p. {r['pdf_page']} | {r['strength']} | {r['cited']} | " f"{r['starts_with']}") text = "\n".join(lines) + "\n" (out / "inventory-summary.txt").write_bytes(text.encode("utf-8")) sys.stdout.flush() # so that any warning above prints before the summary sys.stdout.buffer.write(text.encode("utf-8")) sys.stdout.buffer.flush() hosted = HERE / "inventory-summary.txt" if hosted.exists(): same = hosted.read_bytes() == text.encode("utf-8") print("Same as our hosted inventory-summary.txt:", "yes" if same else "NO") if digest != PDF_SHA256: alike = text.replace(lines[2] + "\n", f"PDF SHA-256: {PDF_SHA256}\n", 1).encode("utf-8") print("Same apart from the line with the PDF's hash:", "yes" if hosted.read_bytes() == alike else "NO") print("SHA-256 of out/inventory-summary.txt:", sha(text.encode("utf-8"))) if __name__ == "__main__": main(sys.argv[1:])