File size: 1,639 Bytes
901f964 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | """cdc_dolma.py META.csv OUT.json.gz ZIP... (10-27) - CDC journals (MMWR weekly / RR / SS / supplements / notifiable diseases, EID,
PCD) from github.com/cmheilig/harvest-cdc-journals (CC0; research/health.md #1: surveillance numbers, vaccine schedules, outbreak
firsts that PubMed abstracts lack) -> dolma json.gz for dolma_chunk.py doc. Each zip holds {url: plain text}; titles and datelines
come from csv-output/cdc_corpus_df.csv. Title "CDC <SERIES> (<dateline>): <title>". Health: local only."""
import sys, csv, json, gzip, zipfile, os, re
meta, dst, zips = sys.argv[1], sys.argv[2], sys.argv[3:]
csv.field_size_limit(1 << 30)
M = {r["url"]: r for r in csv.DictReader(open(meta, encoding="utf-8"))}
BOIL = re.compile(r"^.{0,400}?(subject line of e-mail\.|Accommodation and the title of the report[^.]*\.)\s*", re.S)
n = 0
with gzip.open(dst + ".tmp", "wt") as f:
for z in zips:
zf = zipfile.ZipFile(z)
for name in zf.namelist():
for url, txt in json.load(zf.open(name)).items():
m = M.get(url, {}); txt = BOIL.sub("", txt or "")
if len(txt.split()) < 40:
continue
t = re.sub(r"^CDC - |\s+", " ", m.get("title") or "").strip() or txt.split("\n", 1)[0][:120]
title = f"CDC {(m.get('series') or name.split('_')[0]).upper()} ({m.get('dateline') or m.get('dl_year_mo') or ''}): {t}"
f.write(json.dumps({"id": url, "text": txt, "metadata": {"title": re.sub(r"\s+", " ", title)[:160]}}) + "\n"); n += 1
print(z, "docs so far", n, flush=True)
os.replace(dst + ".tmp", dst)
print("docs", n, flush=True)
|