"""spell_de.py translations/.json [EN-Rohdaten JAHR] -> verdaechtige Woerter je Meldung Prueft kleingeschriebene Woerter gegen ein deutsches Woerterbuch (pyspellchecker) plus typische Tippfehler. Woerter, die im englischen Original oder in Frontier-DE-Texten anderer Jahre vorkommen, gelten als bekannt.""" import json, re, sys from collections import Counter from spellchecker import SpellChecker sp = SpellChecker(language='de') T = json.load(open(sys.argv[1], encoding='utf-8')) known = Counter() if len(sys.argv) > 2: # Frontier-DE-Wortschatz als Zusatz-Woerterbuch from pathlib import Path for f in (Path(sys.argv[2]) / 'DE').glob('*.json'): for a in json.load(open(f, encoding='utf-8'))['articles']: known.update(w.lower() for w in re.findall(r'[A-Za-zÄÖÜäöüß-]+', a['body'])) EXTRA = re.compile(r'(.)\1\1|Thagoid|Thargoiod|Allainz|Föderaiton') for fid, t in T.items(): txt = t['title'] + '\n' + t['body'] bad = set() for w in re.findall(r'\b[a-zäöüß][a-zäöüß-]{3,}\b', txt): if w in sp or known[w] >= 2: continue if all(p in sp or known[p] for p in w.split('-') if p): continue bad.add(w) bad |= {m.group(0) for m in re.finditer(r'\w*(?:' + EXTRA.pattern + r')\w*', txt)} # klein geschriebene Nomen nach "zu"/"im" usw. erkennt das nicht; dafuer Liste fester Wendungen for p in ('zu ehren', 'zu gute', 'im allgemeinen', 'des weiteren'): if p in txt: bad.add(p) if bad: print(fid, t['title'][:50], '|', ', '.join(sorted(bad)))