import json, os, re, sys here = os.path.dirname(os.path.abspath(__file__)) cands = [os.path.join(here, "..", "output"), os.path.join(os.getcwd(), "output")] out = next((c for c in cands if os.path.exists(os.path.join(c, "article.md"))), None) print("output dir:", out) if out is None: sys.exit("output dir not found") art = open(os.path.join(out, "article.md"), encoding="utf-8").read() meta = json.load(open(os.path.join(out, "metadata.json"), encoding="utf-8")) def wc(t): return len(t.split()) lines = art.splitlines() h1 = [l for l in lines if l.startswith("# ")] print("H1:", h1) full = wc(art) no_h1 = wc("\n".join(l for l in lines if not l.startswith("# "))) no_heads = wc("\n".join(l for l in lines if not l.startswith("#"))) cite_re = re.compile(r"\((S\d-[a-z\-]+\.md), (\"[^\"]+\")\)") no_cites = wc(cite_re.sub("", "\n".join(l for l in lines if not l.startswith("#")))) no_cites_no_note = wc(cite_re.sub("", "\n".join(l for l in lines if not l.startswith("#") and not l.startswith("*Based")))) print("words: whole file", full) print("words: excl. H1", no_h1) print("words: excl. all headings", no_heads) print("words: excl. headings and citations", no_cites) print("words: excl. headings, citations, source note", no_cites_no_note) print("citations found:") for f, s in cite_re.findall(art): print(" ", f, s) # verify cited headings exist in the input files inp = next((c for c in [os.path.join(here, "..", "inputs"), os.path.join(os.getcwd(), "inputs")] if os.path.isdir(c)), None) print("inputs dir:", inp) if inp: for f, s in sorted(set(cite_re.findall(art))): p = os.path.join(inp, f) ok = os.path.exists(p) and ("## " + s.strip('"')) in open(p, encoding="utf-8").read() print(" heading exists:", f, s, ok) h = meta["headline"]; e = meta["excerpt"]; d = meta["search_description"] print("keys:", sorted(meta.keys())) print("headline chars:", len(h), 50 <= len(h) <= 70) print("excerpt words:", wc(e), wc(e) <= 45) print("search_description chars:", len(d), 140 <= len(d) <= 160) print("headline matches H1:", h1 and h1[0][2:] == h) low = art.lower() for term in ["gdpr", "offline", "hallucinat", "60%", "60 percent", "fired", "certified", "paperwork department", "we tested", "i tested", "in our testing", "annual"]: idxs = [m.start() for m in re.finditer(re.escape(term), low)] print("term %-22r count %d" % (term, len(idxs)), [art[max(0, i-40):i+40].replace("\n", " ") for i in idxs]) for m in re.finditer(r"USD 19", art): print("USD 19 context:", art[max(0, m.start()-60):m.end()+80].replace("\n", " ")) # arithmetic print("3*29 =", 3*29, "| +12 =", 3*29+12, "| 300*0.08 =", round(300*0.08, 2), "| 800-500 =", 800-500)