Files
sim-numerics/apply_article_sections.py

39 lines
1.4 KiB
Python

"""Renumber: the negative results become Section 10 and the conclusion Section 11, making room
for the new Sections 8 (the flat regime by analogy) and 9 (out-of-sample evidence). Exact
substrings with expected counts; nothing is written unless every one matches.
python -u apply_article_sections.py
"""
from __future__ import annotations
PATH = "article/sim_numerics.md"
REPL = [
("(iii) the negative results of §8;", "(iii) the negative results of §10;", 1),
("as in item 5 of §8, and", "as in item 5 of §10, and", 1),
("(4449 on the canonical set, §8)", "(4449 on the canonical set, §10)", 1),
("the curvature-corrected scale of §8 item 5", "the curvature-corrected scale of §10 item 5", 1),
("measured and refuted (§8, item 11)", "measured and refuted (§10, item 11)", 1),
("## 8. Negative results", "## 10. Negative results", 1),
("## 9. Conclusion", "## 11. Conclusion", 1),
]
def main():
with open(PATH, encoding="utf8") as fh:
text = fh.read()
bad = [(o, n, text.count(o)) for o, _new, n in REPL if text.count(o) != n]
if bad:
for o, n, got in bad:
print(f"expected {n}, found {got}: {o}")
raise SystemExit("aborted, nothing written")
for o, new, _n in REPL:
text = text.replace(o, new)
with open(PATH, "w", encoding="utf8") as fh:
fh.write(text)
print("sections renumbered")
if __name__ == "__main__":
main()