#!/usr/bin/env python3 """Offline word n-gram overlap between the manuscript prose and the reference PDFs in refs/. Nothing leaves the machine. Prose of paper/sections/*.tex and paper_gp/main.tex (math, citation and reference commands removed) is compared with the text of every distinct PDF in refs/ (PyMuPDF; line-end hyphenation joined). Runs of shared word n-grams are merged into spans and written, longest first, to outputs/ref_overlap/overlap_n.json. Only near-verbatim reuse is found, and only against refs/ (PDFs listed in refs/MISSING.md are not checked). Not a substitute for iThenticate. python scripts/50_ref_overlap.py [N] # default N = 8 """ import glob, hashlib, json, os, re, sys, warnings warnings.filterwarnings("ignore") import fitz REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) N = int(sys.argv[1]) if len(sys.argv) > 1 else 8 OUT = os.path.join(REPO, "outputs", "ref_overlap") os.makedirs(OUT, exist_ok=True) def tex_to_text(s): s = re.sub(r"(?