Does light charge the quons? › Files cited on the page › check_trial14_fable/

extract_ch7.py

In the investigation at sim/models_AB/check_trial14_fable/extract_ch7.py · last changed in commit eb6a522, 16 November 2026 · 2,036 bytes · the folder as a zip


"""Extract visible text from the fetched copy of POC ch. 7 (untrusted download), and compare the source note's passages with it."""
import sys, re, html, unicodedata
from html.parser import HTMLParser
src, passages_path, out_path = sys.argv[1], sys.argv[2], sys.argv[3]
class P(HTMLParser):
    def __init__(self):
        super().__init__(); self.parts=[]; self.skip=0
    def handle_starttag(self, tag, attrs):
        if tag in ("script","style"): self.skip+=1
        if tag in ("p","br","div","h1","h2","h3","li","tr"): self.parts.append("\n")
    def handle_endtag(self, tag):
        if tag in ("script","style"): self.skip=max(0,self.skip-1)
        if tag in ("p","div","h1","h2","h3","li","tr"): self.parts.append("\n")
    def handle_data(self, d):
        if not self.skip: self.parts.append(d)
raw = open(src, "rb").read().decode("utf-8", "replace")
p = P(); p.feed(raw); text = html.unescape("".join(p.parts))
open(out_path, "w").write(text)
def norm(s):
    s = unicodedata.normalize("NFKC", s)
    s = s.replace("’","'").replace("‘","'").replace("“",'"').replace("”",'"').replace(" "," ")
    return re.sub(r"\s+", " ", s).strip()
T = norm(text)
# the passages file: take every block between the ==== headers
pf = open(passages_path).read()
blocks = re.split(r"\n=+\n.*?\n=+\n", pf)
hdrs = re.findall(r"\n=+\n(.*?)\n=+\n", pf)
print("page text length (normalized):", len(T))
for h, b in zip(hdrs, blocks[1:]):
    b = norm(b)
    # compare sentence by sentence (split on '. ')
    sents = [s for s in re.split(r"(?<=[.?!”\"])\s+", b) if len(s) > 25]
    miss = [s for s in sents if s not in T]
    print(f"\n[{h}] {len(sents)} sentences; whole block verbatim in page: {b in T}; sentences not found: {len(miss)}")
    for s in miss[:8]: print("   MISSING:", s[:160])
# occurrences of key terms in the full page for omitted passages
for term in ["muon", "E₀", "E0", "pressure", "postulat", "assum", "continuum", "virtual", "equilibrium", "energy density"]:
    print(f"{term!r}: {T.count(term)} occurrences")