#!/usr/bin/env python3 """Remove profile links and timestamps from the Lexilogia discussion shards. python3 strip_profiles_and_timestamps.py SOURCE_DIR OUTPUT_DIR Removed, everywhere they occur at any depth: author_url, op_author_url links to a member's profile page created_at, last_activity when a post or thread happened extracted_at, ts when the record was collected Everything else is kept as collected. Handles stay as written: these are public threads, and stripping the names people post under would break the one thing the corpus is for — following who is answering whom. """ import gzip import json import sys from pathlib import Path REMOVE = { "author_url", "op_author_url", "created_at", "last_activity", "extracted_at", "ts", } def strip(node): if isinstance(node, list): return [strip(v) for v in node] if isinstance(node, dict): return {k: strip(v) for k, v in node.items() if k not in REMOVE} return node def main(): src, dst = Path(sys.argv[1]), Path(sys.argv[2]) dst.mkdir(parents=True, exist_ok=True) total = 0 for path in sorted(src.glob("*.jsonl.gz")): n = 0 with gzip.open(path, "rt", encoding="utf-8") as fin, \ gzip.open(dst / path.name, "wt", encoding="utf-8") as fout: for line in fin: fout.write(json.dumps(strip(json.loads(line)), ensure_ascii=False) + "\n") n += 1 print(f" {path.name}: {n} discussions") total += n print(f"{total} discussions written to {dst}") if __name__ == "__main__": main()