Files
sim-numerics/apply_article_rename.py

43 lines
1.8 KiB
Python

"""Rename the rule of Section 3 from 'the proposed rule' to 'the base rule' in
article/sim_numerics.md: the method the paper now proposes is A' (Section 8), built on it.
Each (old, new, expected count) must match exactly, otherwise nothing is written.
python -u apply_article_rename.py
"""
from __future__ import annotations
PATH = "article/sim_numerics.md"
REPL = [
("the proposed rule", "the base rule", 10),
("The proposed rule and the same rule", "The base rule and the same rule", 1),
("The proposed projection never binds", "The projection of the base rule never binds", 1),
("| ours, proposed (projection) |", "| ours, base rule (projection) |", 1),
("The configuration proposed in Section 3", "The base rule of Section 3", 1),
("**proposed: tent, 3-point, projection ($c=2$)**", "**base rule: tent, 3-point, projection ($c=2$)**", 1),
("| proposed: tent, 3-point, projection $c=2$ (§3) |", "| base rule: tent, 3-point, projection $c=2$ (§3) |", 1),
("APS, projection — proposed", "APS, projection — base rule", 1),
("Chandrupatla, projection — proposed", "Chandrupatla, projection — base rule", 1),
("under the proposed projection", "under the projection of the base rule", 1),
("the proposed scale wins", "the derived scale wins", 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("renamed")
if __name__ == "__main__":
main()