ki:galnet:werkzeuge:make_2015
make_2015.py
Setzt translations/2015.json zusammen: Olivers Fassungen, Dubletten-Zwillinge, Wochenberichte (weekly.py), Claudes Übersetzungen (new_2015_*.py, nur in 2015.json enthalten).
Ablage beim Arbeiten: translations/src/make_2015.py. Herunterladen: auf den Dateinamen über dem Code klicken.
- make_2015.py
"""make_2015.py RAW -> translations/2015.json Olivers Fassungen (2015_alt.json, mit fix_2015.py korrigiert) + Dubletten-Zwillinge + Wochenberichte (weekly.py) + Claudes Uebersetzungen.""" import json, csv, re, sys, collections from pathlib import Path sys.path.insert(0, 'translations/src') import weekly, new_2015_a, new_2015_b, new_2015_c R = Path(sys.argv[1]) idx = [r for r in csv.DictReader(open(R / 'index.csv', encoding='utf-8'), delimiter=';') if int(r['date'][:4]) == 2015] EN = {} for f in (R / 'EN').glob('3301*.json'): for a in json.load(open(f, encoding='utf-8'))['articles']: EN[a['id']] = a T = json.load(open('translations/2015_alt.json', encoding='utf-8')) NEW = {**new_2015_a.N, **new_2015_b.N, **new_2015_c.N} # Oliver hatte zu 07.03.3301 "GalNet Health Report Sparks Action" nur den Titel -> Claudes Fassung for k in list(T): if k in NEW and len(T[k]['body']) < 200: del T[k] out = {k: dict(v, source='eigene') for k, v in T.items()} # Dubletten: Frontier hat 3301 manche Meldungen zweimal veroeffentlicht (1–4 Tage Abstand, gleiche ID-lose Fassung) norm = lambda a: (re.sub(r'\W+', '', a['title'].lower()), re.sub(r'\W+', '', a['body'].lower())[:400]) g = collections.defaultdict(list) for r in idx: g[norm(EN[r['frontier_id']])].append(r['frontier_id']) twins = 0 for v in g.values(): have = [x for x in v if x in out] for x in v: if x not in out and have: out[x] = dict(out[have[0]]); twins += 1 ki_w = ki_n = 0 for r in idx: fid = r['frontier_id'] if fid in out: continue a = EN[fid] if a['title'].strip() in weekly.TITLES: out[fid] = dict(title=weekly.TITLES[a['title'].strip()], body=weekly.translate(a['body']), source='KI'); ki_w += 1 else: t, b = NEW[fid]; out[fid] = dict(title=t, body=b.strip(), source='KI'); ki_n += 1 missing = [r['frontier_id'] for r in idx if r['frontier_id'] not in out] json.dump(out, open('translations/2015.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=1) print(f"{len(out)} Meldungen: {len(T)} Oliver, {twins} Dubletten (Olivers Text), {ki_w} Wochenberichte KI, {ki_n} KI; fehlen {len(missing)}")
ki/galnet/werkzeuge/make_2015.txt · Zuletzt geändert: (Externe Bearbeitung)
