blackthis 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -2
- package/bin/blackthis.js +255 -0
- package/dsgvo_redactor/__init__.py +3 -0
- package/dsgvo_redactor/cli.py +214 -0
- package/dsgvo_redactor/csv_io.py +221 -0
- package/dsgvo_redactor/detectors.py +114 -0
- package/dsgvo_redactor/detectors_addresses.py +278 -0
- package/dsgvo_redactor/detectors_common.py +72 -0
- package/dsgvo_redactor/detectors_entities.py +818 -0
- package/dsgvo_redactor/detectors_structured.py +471 -0
- package/dsgvo_redactor/engine.py +810 -0
- package/dsgvo_redactor/german_dict.py +100 -0
- package/dsgvo_redactor/lexicons.py +690 -0
- package/dsgvo_redactor/models.py +247 -0
- package/dsgvo_redactor/ner_engine.py +377 -0
- package/dsgvo_redactor/pdf_export.py +393 -0
- package/dsgvo_redactor/pdf_redactor.py +356 -0
- package/dsgvo_redactor/report.py +269 -0
- package/dsgvo_redactor/session.py +518 -0
- package/dsgvo_redactor/validators.py +188 -0
- package/dsgvo_redactor/web_app.py +630 -0
- package/dsgvo_redactor/whitelist.py +273 -0
- package/package.json +52 -4
- package/redact_csv.py +7 -0
- package/requirements.txt +8 -0
- package/static/app.js +1670 -0
- package/static/styles.css +1067 -0
- package/templates/index.html +344 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Offline-Abgleich gegen deutsches Häufigkeitswörterbuch (wordfreq) + Komposita-Zerlegung.
|
|
2
|
+
|
|
3
|
+
Verhindert False Positives bei normalen deutschen Substantiven & Komposita (z. B. ‚Fluss‘,
|
|
4
|
+
‚Sattelzug‘, ‚Baumschnittarbeiten‘, ‚Pelletlieferanten‘, ‚Parktaschen‘), ohne jemals bekannte
|
|
5
|
+
Vor-/Nachnamen oder Städte zu blockieren. Läuft 100 % offline mit sauberem Fallback, falls
|
|
6
|
+
`wordfreq` noch nicht installiert ist.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from functools import lru_cache
|
|
12
|
+
|
|
13
|
+
from .detectors_common import is_german_compound_non_entity
|
|
14
|
+
from .lexicons import COMMON_FIRST_NAMES, COMMON_SURNAMES, MAJOR_GERMAN_CITIES, NON_NAME_WORDS
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
from wordfreq import zipf_frequency as _zipf_frequency # type: ignore
|
|
18
|
+
|
|
19
|
+
WORDFREQ_AVAILABLE = True
|
|
20
|
+
except ImportError:
|
|
21
|
+
_zipf_frequency = None
|
|
22
|
+
WORDFREQ_AVAILABLE = False
|
|
23
|
+
|
|
24
|
+
# Echte deutsche Nachnamen-Endungen, bei denen eine Komposita-Zerlegung NICHT als Sachwort werten darf
|
|
25
|
+
# (z. B. „Neuhaus“, „Goldstein“, „Rosenfeld“, „Bergmann“, „Hofbauer“, „Schönwald“)
|
|
26
|
+
_SURNAME_COMPOUND_TAILS = frozenset({
|
|
27
|
+
"mann", "frau", "berg", "berger", "stein", "steiner", "bach", "bacher", "dorf", "dorfer",
|
|
28
|
+
"feld", "felder", "wald", "walder", "baum", "bäume", "haus", "häuser", "hausen", "hof",
|
|
29
|
+
"hofer", "höfer", "meier", "meyer", "maier", "mayer", "müller", "schmidt", "schmitt",
|
|
30
|
+
"weber", "wagner", "becker", "bauer", "fischer", "schulz", "richter", "klein", "wolf",
|
|
31
|
+
"schröder", "neumann", "schwarz", "braun", "krüger", "hartmann", "lange", "werner",
|
|
32
|
+
"krause", "lehmann", "köhler", "herrmann", "walter", "kaiser", "fuchs", "lang", "vogel",
|
|
33
|
+
"jung", "hahn", "keller", "busch", "horn", "brandt", "roth", "beck", "lorenz", "baier",
|
|
34
|
+
"frank", "albrecht", "simon", "ludwig", "winter", "sommer", "könig", "graf", "herzog",
|
|
35
|
+
"ritter", "kaufmann", "zimmermann", "schneider", "koch", "krämer", "schäfer",
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
# Fugenelemente im Deutschen („Produktions-büro“ -> produktion + s + büro)
|
|
39
|
+
_FUGEN_ELEMENTS = ("", "s", "n", "es", "en")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@lru_cache(maxsize=8192)
|
|
43
|
+
def german_zipf(word_lower: str) -> float:
|
|
44
|
+
"""Liefert die Zipf-Worthäufigkeit im Deutschen (0.0 – 8.0), 100 % offline."""
|
|
45
|
+
if _zipf_frequency is None or not word_lower:
|
|
46
|
+
return 0.0
|
|
47
|
+
try:
|
|
48
|
+
return float(_zipf_frequency(word_lower, "de"))
|
|
49
|
+
except Exception: # noqa: BLE001
|
|
50
|
+
return 0.0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_dictionary_compound(wl: str) -> bool:
|
|
54
|
+
"""Prüft, ob ein langes deutsches Wort aus 2 geläufigen deutschen Wörterbuch-Wörtern besteht."""
|
|
55
|
+
n = len(wl)
|
|
56
|
+
if _zipf_frequency is None or n < 8:
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
# Positionen für Split: links >= 4 Zeichen, rechts >= 4 Zeichen
|
|
60
|
+
for split_pos in range(4, n - 3):
|
|
61
|
+
left = wl[:split_pos]
|
|
62
|
+
if german_zipf(left) < 3.1:
|
|
63
|
+
continue
|
|
64
|
+
for fuge in _FUGEN_ELEMENTS:
|
|
65
|
+
r_start = split_pos + len(fuge)
|
|
66
|
+
if r_start > n - 4:
|
|
67
|
+
continue
|
|
68
|
+
if fuge and not wl.startswith(fuge, split_pos):
|
|
69
|
+
continue
|
|
70
|
+
right = wl[r_start:]
|
|
71
|
+
if right in _SURNAME_COMPOUND_TAILS:
|
|
72
|
+
continue
|
|
73
|
+
if german_zipf(right) >= 3.3:
|
|
74
|
+
return True
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@lru_cache(maxsize=8192)
|
|
79
|
+
def is_common_german_dictionary_word(word: str) -> bool:
|
|
80
|
+
"""True, wenn `word` klar ein normales deutsches Wort/Kompositum ist (und KEIN bekannter Name/Ort)."""
|
|
81
|
+
wl = word.lower().strip(".,:;!?()[]{}\"'")
|
|
82
|
+
if len(wl) < 3:
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
# 1. Bekannte Vor-/Nachnamen & Städte NIEMALS als Sachwort verwerfen!
|
|
86
|
+
if wl in COMMON_FIRST_NAMES or wl in COMMON_SURNAMES or wl in MAJOR_GERMAN_CITIES:
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
# 2. Kuratierte Nicht-Namen & Komposita-Suffixe (funktioniert immer, auch ohne wordfreq)
|
|
90
|
+
if wl in NON_NAME_WORDS or is_german_compound_non_entity(wl):
|
|
91
|
+
return True
|
|
92
|
+
|
|
93
|
+
# 3. Offline-Wörterbuch (wordfreq): direktes häufiges deutsches Wort oder deutsches Kompositum
|
|
94
|
+
if _zipf_frequency is not None:
|
|
95
|
+
if german_zipf(wl) >= 3.0:
|
|
96
|
+
return True
|
|
97
|
+
if _is_dictionary_compound(wl):
|
|
98
|
+
return True
|
|
99
|
+
|
|
100
|
+
return False
|