"""Compare two macronize_oga_corpus.py runs line by line (same input, same chunking). Usage: python3 compare_runs.py OLD_OUT_DIR NEW_OUT_DIR """ import collections, glob, json, os, sys old, new = sys.argv[1:3] strip = lambda s: s.replace("^", "").replace("_", "") n = same = text_diff = marks_only = count_mismatch = 0 ex = collections.defaultdict(list) for f in sorted(glob.glob(os.path.join(new, "parts", "*.txt"))): a = open(os.path.join(old, "parts", os.path.basename(f)), encoding="utf-8").read().splitlines() b = open(f, encoding="utf-8").read().splitlines() if len(a) != len(b): count_mismatch += 1; ex["count_mismatch"].append((os.path.basename(f), len(a), len(b))); continue for x, y in zip(a, b): n += 1 if x == y: same += 1 elif strip(x) != strip(y): text_diff += 1 if len(ex["text"]) < 40: ex["text"].append((x, y)) else: marks_only += 1 if len(ex["marks"]) < 40: ex["marks"].append((x, y)) s = dict(lines=n, identical=same, text_differs=text_diff, marks_only_differ=marks_only, files_with_line_count_mismatch=count_mismatch) print(json.dumps(s, indent=2)) json.dump(dict(summary=s, examples=ex), open(os.path.join(new, "compare_to_previous.json"), "w"), ensure_ascii=False, indent=1)