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,818 @@
|
|
|
1
|
+
"""Kontext- & Lexikon-Detektoren für Berufsbezeichnungen, Klarnamen und Firmennamen."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
|
|
8
|
+
from .detectors_addresses import STREET_COMPOUND_RE, STREET_PREFIX_RE, is_plausible_street
|
|
9
|
+
from .detectors_common import (
|
|
10
|
+
IMAGE_OR_SOCIAL_LINE_RE,
|
|
11
|
+
LEGAL_FORM_TAIL_RE,
|
|
12
|
+
NAME_PARTICLE,
|
|
13
|
+
NAME_SEQ,
|
|
14
|
+
NAME_TOKEN,
|
|
15
|
+
NAME_TOKEN_CI,
|
|
16
|
+
NAME_UPPER_CHARS,
|
|
17
|
+
is_german_compound_non_entity,
|
|
18
|
+
is_public_authority,
|
|
19
|
+
iter_lines_with_offsets,
|
|
20
|
+
)
|
|
21
|
+
from .detectors_structured import BARE_DOMAIN_RE, EMAIL_RE, URL_FULL_RE
|
|
22
|
+
from .german_dict import is_common_german_dictionary_word
|
|
23
|
+
from .lexicons import (
|
|
24
|
+
COMMON_FIRST_NAMES,
|
|
25
|
+
COMMON_SURNAMES,
|
|
26
|
+
FREEMAIL_DOMAIN_STEMS,
|
|
27
|
+
JOB_COMPOUND_SUFFIXES,
|
|
28
|
+
JOB_NON_MATCHES,
|
|
29
|
+
JOB_TITLES_EXACT,
|
|
30
|
+
MAJOR_GERMAN_CITIES,
|
|
31
|
+
NON_NAME_WORDS,
|
|
32
|
+
ORG_NOISE_WORDS,
|
|
33
|
+
)
|
|
34
|
+
from .models import Category, Confidence, SpanMatch
|
|
35
|
+
|
|
36
|
+
# --- 1. Job-Positionen & Berufsbezeichnungen (mit O(1)-LRU-Cache) ---
|
|
37
|
+
|
|
38
|
+
_MULTIWORD_JOB_TITLES = sorted([t for t in JOB_TITLES_EXACT if " " in t], key=len, reverse=True)
|
|
39
|
+
_MULTIWORD_JOB_RE = re.compile(r"\b(?:" + "|".join(re.escape(t) for t in _MULTIWORD_JOB_TITLES) + r")\b", re.IGNORECASE)
|
|
40
|
+
|
|
41
|
+
_DYNAMIC_JOB_PHRASE_RE = re.compile(
|
|
42
|
+
r"\b(?:(?:Senior|Junior|Stellv\.?|Stellvertretende[rn]?|Kaufmännische[rn]?|Technische[rn]?|Leitende[rn]?)\s+)?"
|
|
43
|
+
r"(?:Head\s+of\s+[A-ZÄÖÜ][A-Za-zÄÖÜäöüß&\-\s]{2,35}|"
|
|
44
|
+
r"Team\s*Lead(?:er)?\s+[A-ZÄÖÜ][A-Za-zÄÖÜäöüß&\-]{2,25}|"
|
|
45
|
+
r"Leiter(?:in)?\s+(?:der\s+|des\s+)?[A-ZÄÖÜ][a-zäöüß\-]{3,28}|"
|
|
46
|
+
r"Leitung\s+(?:der\s+|des\s+)?[A-ZÄÖÜ][a-zäöüß\-]{3,28}|"
|
|
47
|
+
r"Assistenz\s+(?:der|des)\s+[A-ZÄÖÜ][a-zäöüß\-]{3,28})",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
_SINGLE_JOB_WORDS = frozenset(t for t in JOB_TITLES_EXACT if " " not in t)
|
|
51
|
+
_WORD_TOKEN_RE = re.compile(r"\b[A-Za-zÄÖÜäöüß][A-Za-zÄÖÜäöüß\-]*(?:[\*/:_](?:in|innen|r|m/w/d))?\b")
|
|
52
|
+
_GENDER_SUFFIX_RE = re.compile(r"[\*/:_](in|innen)$")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@lru_cache(maxsize=4096)
|
|
56
|
+
def normalize_job_token(word: str) -> str:
|
|
57
|
+
w = word.lower()
|
|
58
|
+
if "*" in w or "/" in w or ":" in w or "_" in w:
|
|
59
|
+
w = _GENDER_SUFFIX_RE.sub(r"\1", w)
|
|
60
|
+
return w
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@lru_cache(maxsize=4096)
|
|
64
|
+
def matches_job_stem(norm: str) -> bool:
|
|
65
|
+
if not norm or norm in JOB_NON_MATCHES:
|
|
66
|
+
return False
|
|
67
|
+
if norm in _SINGLE_JOB_WORDS:
|
|
68
|
+
return True
|
|
69
|
+
for suffix_strip in ("s", "n", "en", "nen"):
|
|
70
|
+
if norm.endswith(suffix_strip) and len(norm) > len(suffix_strip) + 4:
|
|
71
|
+
stem = norm[:-len(suffix_strip)]
|
|
72
|
+
if stem in _SINGLE_JOB_WORDS and stem not in JOB_NON_MATCHES:
|
|
73
|
+
return True
|
|
74
|
+
for suf in JOB_COMPOUND_SUFFIXES:
|
|
75
|
+
if norm.endswith(suf) and len(norm) >= len(suf) + 3:
|
|
76
|
+
return True
|
|
77
|
+
if norm.endswith(suf + "s") or norm.endswith(suf + "n"):
|
|
78
|
+
base = norm[:-1]
|
|
79
|
+
if len(base) >= len(suf) + 3 and base not in JOB_NON_MATCHES:
|
|
80
|
+
return True
|
|
81
|
+
elif norm.endswith(suf + "en"):
|
|
82
|
+
base = norm[:-2]
|
|
83
|
+
if len(base) >= len(suf) + 3 and base not in JOB_NON_MATCHES:
|
|
84
|
+
return True
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def detect_job_titles(text: str) -> list[SpanMatch]:
|
|
89
|
+
matches: list[SpanMatch] = []
|
|
90
|
+
|
|
91
|
+
for m in _MULTIWORD_JOB_RE.finditer(text):
|
|
92
|
+
matches.append(SpanMatch(m.start(), m.end(), m.group(0), Category.JOB_TITLE, Confidence.HIGH, "Berufsbezeichnung (Mehrwort)"))
|
|
93
|
+
|
|
94
|
+
for m in _DYNAMIC_JOB_PHRASE_RE.finditer(text):
|
|
95
|
+
raw = m.group(0).strip()
|
|
96
|
+
matches.append(SpanMatch(m.start(), m.start() + len(raw), raw, Category.JOB_TITLE, Confidence.HIGH, "Job-Position (Phrase)"))
|
|
97
|
+
|
|
98
|
+
for m in _WORD_TOKEN_RE.finditer(text):
|
|
99
|
+
word = m.group(0)
|
|
100
|
+
if len(word) <= 3 and not word.isupper():
|
|
101
|
+
continue
|
|
102
|
+
norm = normalize_job_token(word)
|
|
103
|
+
if norm in NON_NAME_WORDS:
|
|
104
|
+
continue
|
|
105
|
+
if matches_job_stem(norm):
|
|
106
|
+
if text[m.end():m.end() + 6].lower().startswith("-notiz"):
|
|
107
|
+
continue
|
|
108
|
+
matches.append(SpanMatch(m.start(), m.end(), word, Category.JOB_TITLE, Confidence.HIGH, "Berufsbezeichnung / Position"))
|
|
109
|
+
|
|
110
|
+
return matches
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# --- 2. Klarnamen (alle Regexes einmalig vorkompiliert) ---
|
|
114
|
+
|
|
115
|
+
_SALUTATION_RE = re.compile(
|
|
116
|
+
r"\b(?:Sehr[ \t]+geehrte[rn]?|Liebe[rn]?|Hallo|Guten[ \t]+Tag|Guten[ \t]+Morgen|Guten[ \t]+Abend|"
|
|
117
|
+
r"Hi|Hey|Moin|Servus|Grüß[ \t]+Gott)[ \t]*,?[ \t]+"
|
|
118
|
+
r"(?:(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+)?"
|
|
119
|
+
r"(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?"
|
|
120
|
+
rf"({NAME_SEQ})",
|
|
121
|
+
)
|
|
122
|
+
_ROUTING_CONTEXT_RE = re.compile(
|
|
123
|
+
r"\b(?:zu[ \t]+Händen|z\.?[ \t]*Hd\.?|z\.?[ \t]*H\.?|Ansprechpartner(?:in)?|Sachbearbeiter(?:in)?|"
|
|
124
|
+
r"Sachbearbeitung|Bearbeiter(?:in)?|Bearbeitung|Kolleg(?:e|in)|Kontoinhaber(?:in)?|Antragsteller(?:in)?|"
|
|
125
|
+
r"Kundenberater(?:in)?|Disponent(?:in)?|Geschäftsführer(?:in)?|Projektleiter(?:in)?|"
|
|
126
|
+
r"Teamleiter(?:in)?|Bauleiter(?:in)?|Fahrer(?:in)?|Inhaber(?:in)?|Bevollmächtigte[rn]?|"
|
|
127
|
+
r"Vertreter(?:in)?|Vertretung|Kontaktperson|Ansprechperson|Auftraggeber(?:in)?|"
|
|
128
|
+
r"Rechnungsempfänger(?:in)?|Empfänger(?:in)?|Absender(?:in)?|Verfasser(?:in)?|"
|
|
129
|
+
r"Mieter(?:in)?|Vermieter(?:in)?|Eigentümer(?:in)?|Hausmeister(?:in)?|Zeug(?:e|in)|"
|
|
130
|
+
r"Erstellt[ \t]+von|Bearbeitet[ \t]+von|Geändert[ \t]+von|Zugewiesen[ \t]+an|"
|
|
131
|
+
r"Gezeichnet|gez\.)[ \t]*[:,\-]?[ \t]+"
|
|
132
|
+
r"(?:(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+)?"
|
|
133
|
+
r"(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?"
|
|
134
|
+
rf"({NAME_SEQ})",
|
|
135
|
+
)
|
|
136
|
+
_FIELD_LABEL_NAME_RE = re.compile(
|
|
137
|
+
r"(?im)(?:^|(?<=[\n;|]))[ \t]*(?:Name|Vorname|Nachname|Vollständiger[ \t]+Name|Kunde|Kundin|"
|
|
138
|
+
r"Kontakt|Von|From|An|To|Cc|Mitarbeiter(?:in)?|Berater(?:in)?|Verantwortlich(?:er|e)?|"
|
|
139
|
+
r"Zuständig(?:er|e)?|Unterschrift|Rückruf(?:wunsch)?)[ \t]*:[ \t]*"
|
|
140
|
+
r"(?:(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+)?"
|
|
141
|
+
r"(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?"
|
|
142
|
+
rf"({NAME_SEQ})",
|
|
143
|
+
)
|
|
144
|
+
_PASSIVE_AGENT_RE = re.compile(
|
|
145
|
+
r"\b(?:durch|von)[ \t]+(?:(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+)?(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?"
|
|
146
|
+
rf"({NAME_SEQ})[ \t]+"
|
|
147
|
+
r"(?:genehmigt|bearbeitet|bestätigt|geprüft|freigegeben|abgelehnt|unterschrieben|"
|
|
148
|
+
r"erstellt|beantragt|übernommen|abgesprochen|geklärt|erledigt|storniert|weitergeleitet|veranlasst)\b",
|
|
149
|
+
)
|
|
150
|
+
_TALKED_TO_RE = re.compile(
|
|
151
|
+
r"\b(?:"
|
|
152
|
+
r"(?:Rücksprache|Gespräch|Telefonat|Kontakt|Absprache|Abstimmung|Termin|telefoniert|gesprochen)[ \t]+mit|"
|
|
153
|
+
r"(?:Anruf|Rückruf|Nachricht|E-?Mail|Mail|Info|Rückmeldung|Bestätigung|Freigabe|Anfrage|Antwort|Hinweis|Beschwerde)[ \t]+(?:von|an|für)|"
|
|
154
|
+
r"(?:weitergeleitet|geschrieben|gesendet|geschickt|übergeben)[ \t]+an|"
|
|
155
|
+
r"laut"
|
|
156
|
+
r")[ \t]+"
|
|
157
|
+
r"(?:(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+)?(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?"
|
|
158
|
+
rf"({NAME_SEQ})",
|
|
159
|
+
)
|
|
160
|
+
_PERSON_ACTION_RE = re.compile(
|
|
161
|
+
rf"(?:^|(?<=[\n.!?;:\-][ \t])|(?<=[\n]))({NAME_SEQ})[ \t]+"
|
|
162
|
+
r"(?:hat[ \t]+(?:angerufen|zurückgerufen|geschrieben|geantwortet|gefragt|bestätigt|storniert|geklärt|mitgeteilt|zugesagt|abgesagt|überwiesen|bezahlt|beantragt)|"
|
|
163
|
+
r"rief[ \t]+(?:an|zurück)|meldet[ \t]+sich|meldete[ \t]+sich|ruft[ \t]+(?:an|zurück)|"
|
|
164
|
+
r"bittet[ \t]+um|bat[ \t]+um|fragt[ \t]+nach|fragte[ \t]+nach|teilte[ \t]+mit|teilt[ \t]+mit|"
|
|
165
|
+
r"schrieb\b|sagte\b|wollte[ \t]+wissen|möchte[ \t]+(?:wissen|stornieren|verschieben))\b"
|
|
166
|
+
)
|
|
167
|
+
_HONORIFIC_NAME_RE = re.compile(
|
|
168
|
+
rf"\b(?:Herrn?|Frau|Hr\.?|Fr\.?)[ \t]+(?:(?:Prof\.?[ \t]*)?(?:Dr\.?[ \t]*)?)?({NAME_SEQ})",
|
|
169
|
+
)
|
|
170
|
+
_HONORIFIC_LOWER_RE = re.compile(
|
|
171
|
+
rf"\b(herrn?|frau|hr\.|fr\.)[ \t]+({NAME_TOKEN_CI}(?:[ \t]+{NAME_TOKEN_CI})?)\b"
|
|
172
|
+
)
|
|
173
|
+
_TITLE_NAME_RE = re.compile(
|
|
174
|
+
rf"\b(?:Prof\.?[ \t]+Dr\.?|Prof\.?|Dr\.?(?:[ \t]+(?:med|jur|rer\.[ \t]*nat|phil|ing)\.?)?)[ \t]+({NAME_SEQ})",
|
|
175
|
+
)
|
|
176
|
+
_SIGN_AUTH_RE = re.compile(rf"\b(?:i\.?[ \t]*A\.?|i\.?[ \t]*V\.?|ppa\.?)[ \t]+({NAME_SEQ})")
|
|
177
|
+
_SIGNOFF_LINE_RE = re.compile(
|
|
178
|
+
r"(?im)^[ \t]*(?:Mit[ \t]+freundlichen[ \t]+Grüßen|Mit[ \t]+freundlichem[ \t]+Gruß|"
|
|
179
|
+
r"Mit[ \t]+kollegialen[ \t]+Grüßen|Freundliche[ \t]+Grüße|Freundlichen[ \t]+Gruß|"
|
|
180
|
+
r"Viele[ \t]+Grüße|Beste[ \t]+Grüße|Herzliche[ \t]+Grüße|Liebe[ \t]+Grüße|Lieben[ \t]+Gruß|"
|
|
181
|
+
r"Schöne[ \t]+Grüße|Sonnige[ \t]+Grüße|Alles[ \t]+Gute|Hochachtungsvoll|"
|
|
182
|
+
r"MfG|VG|BG|LG|Grüße|Gruß|Best[ \t]+regards|Kind[ \t]+regards|Warm[ \t]+regards|Regards|"
|
|
183
|
+
r"Vielen[ \t]+Dank(?:[ \t]+(?:vorab|und[ \t]+(?:viele|freundliche|beste|liebe)[ \t]+Grüße))?)"
|
|
184
|
+
r"(?:[ \t]+aus[ \t]+[A-ZÄÖÜ][a-zäöüß\-]+)?[ \t,!.]*$"
|
|
185
|
+
)
|
|
186
|
+
_INLINE_SIGNOFF_RE = re.compile(
|
|
187
|
+
r"\b(?:Mit[ \t]+freundlichen[ \t]+Grüßen|Viele[ \t]+Grüße|Beste[ \t]+Grüße|Liebe[ \t]+Grüße|"
|
|
188
|
+
rf"Herzliche[ \t]+Grüße|Freundliche[ \t]+Grüße|MfG|VG|BG|LG|Grüße|Gruß)[ \t]*,?[ \t]+({NAME_SEQ})"
|
|
189
|
+
)
|
|
190
|
+
_TWO_CAP_WORDS_RE = re.compile(rf"\b(?=({NAME_TOKEN})[ \t]+(?:({NAME_PARTICLE})[ \t]+)?({NAME_TOKEN})\b)")
|
|
191
|
+
_ALLCAPS_TWO_WORDS_RE = re.compile(rf"\b(?=([{NAME_UPPER_CHARS}]{{2,}})[ \t]+([{NAME_UPPER_CHARS}]{{2,}}(?:-[{NAME_UPPER_CHARS}]{{2,}})?)\b)")
|
|
192
|
+
_ALLCAPS_HONORIFIC_RE = re.compile(rf"\b(?:HERRN?|FRAU|HR\.?|FR\.?)[ \t]+([{NAME_UPPER_CHARS}]{{2,}}(?:[ \t]+[{NAME_UPPER_CHARS}]{{2,}})?)\b")
|
|
193
|
+
_INITIAL_SURNAME_RE = re.compile(rf"\b([{NAME_UPPER_CHARS}]\.)[ \t]+({NAME_TOKEN})\b")
|
|
194
|
+
_SURNAME_COMMA_FIRST_RE = re.compile(rf"\b({NAME_TOKEN}),[ \t]+({NAME_TOKEN})\b")
|
|
195
|
+
_ALLCAPS_SURNAME_COMMA_FIRST_RE = re.compile(rf"\b([{NAME_UPPER_CHARS}]{{2,}}),[ \t]+([{NAME_UPPER_CHARS}]{{2,}})\b")
|
|
196
|
+
_PREP_SINGLE_NAME_RE = re.compile(rf"\b(bei|mit|von|durch|an|für)[ \t]+({NAME_TOKEN})\b")
|
|
197
|
+
_STRICT_PREP_KNOWN_ONLY = frozenset({"für", "mit"})
|
|
198
|
+
_CONTACT_LINE_HINT_RE = re.compile(
|
|
199
|
+
r"(?i)(?:@|https?://|www\.|\b(?:Tel(?:efon)?\.?|Mobil|Handy|Fax|Durchwahl|E-?Mail)\s*[:.]|(?:\+|00)49|\b0[1-9]\d{1,4}\s*[/\-])"
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Vorkompilierte Helfer (früher fälschlich in Schleifen neu kompiliert!)
|
|
203
|
+
_SINGLE_INITIAL_RE = re.compile(r"^[A-ZÄÖÜ]\.?$")
|
|
204
|
+
_SIG_SKIP_CHARS_RE = re.compile(r"[@\d]|https?://|www\.", re.IGNORECASE)
|
|
205
|
+
_SIG_SKIP_COLON_RE = re.compile(r"[@\d:]|https?://|www\.", re.IGNORECASE)
|
|
206
|
+
_SIG_NAME_TRAILING_RE = re.compile(rf"^(?:(?:Prof\.?\s*)?(?:Dr\.?\s*)?)?({NAME_SEQ})(?:\s*[,|/\-].*)?$")
|
|
207
|
+
_SIG_NAME_EXACT_RE = re.compile(rf"^(?:(?:Prof\.?\s*)?(?:Dr\.?\s*)?)?({NAME_SEQ})$")
|
|
208
|
+
_SIG_ALLCAPS_NAME_RE = re.compile(
|
|
209
|
+
rf"^([{NAME_UPPER_CHARS}]{{2,}}(?:-[{NAME_UPPER_CHARS}]{{2,}})?(?:[ \t]+[{NAME_UPPER_CHARS}]{{2,}}(?:-[{NAME_UPPER_CHARS}]{{2,}})?){{1,2}})$"
|
|
210
|
+
)
|
|
211
|
+
_AMBIGUOUS_FIRST_NAMES = frozenset({"mai", "august", "ernst", "frank", "mark", "christian", "peter"})
|
|
212
|
+
_STREET_SUFFIX_CHECK = ("straße", "strasse", "str", "allee", "weg", "platz", "gasse", "ring")
|
|
213
|
+
|
|
214
|
+
_HIGH_CONTEXT_NAME_RULES = (
|
|
215
|
+
(_SALUTATION_RE, "Name (Anrede)"),
|
|
216
|
+
(_ROUTING_CONTEXT_RE, "Name (Zuordnung/Kontext)"),
|
|
217
|
+
(_FIELD_LABEL_NAME_RE, "Name (Feld-Label)"),
|
|
218
|
+
(_PASSIVE_AGENT_RE, "Name (Handlungsträger 'durch/von ...')"),
|
|
219
|
+
(_TALKED_TO_RE, "Name (Gesprächspartner / Kommunikation)"),
|
|
220
|
+
(_HONORIFIC_NAME_RE, "Name (Herr/Frau)"),
|
|
221
|
+
(_TITLE_NAME_RE, "Name (Titel Dr./Prof.)"),
|
|
222
|
+
(_SIGN_AUTH_RE, "Name (Zeichnungsbefugnis i.A./i.V.)"),
|
|
223
|
+
(_INLINE_SIGNOFF_RE, "Name (Grußformel einzeilig)"),
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _trim_name_candidate(raw: str, *, allow_dict_word: bool = False) -> str:
|
|
228
|
+
words = raw.split()
|
|
229
|
+
kept: list[str] = []
|
|
230
|
+
for idx, w in enumerate(words):
|
|
231
|
+
wl = w.lower().rstrip(".,:;!?")
|
|
232
|
+
is_known_surname = wl in COMMON_SURNAMES
|
|
233
|
+
is_known_first = wl in COMMON_FIRST_NAMES
|
|
234
|
+
if idx == 0 and (
|
|
235
|
+
(wl in NON_NAME_WORDS and not is_known_surname and not is_known_first)
|
|
236
|
+
or is_german_compound_non_entity(w)
|
|
237
|
+
or (not allow_dict_word and is_common_german_dictionary_word(w))
|
|
238
|
+
):
|
|
239
|
+
return ""
|
|
240
|
+
if idx > 0 and (
|
|
241
|
+
(wl in NON_NAME_WORDS and not is_known_surname)
|
|
242
|
+
or wl in MAJOR_GERMAN_CITIES
|
|
243
|
+
or LEGAL_FORM_TAIL_RE.fullmatch(w)
|
|
244
|
+
or is_german_compound_non_entity(w)
|
|
245
|
+
or (not allow_dict_word and is_common_german_dictionary_word(w))
|
|
246
|
+
):
|
|
247
|
+
break
|
|
248
|
+
if idx > 0 and matches_job_stem(normalize_job_token(w)) and not is_known_surname:
|
|
249
|
+
break
|
|
250
|
+
kept.append(w)
|
|
251
|
+
if not kept:
|
|
252
|
+
return ""
|
|
253
|
+
if len(kept) == 1 and kept[0].lower() in NON_NAME_WORDS and kept[0].lower() not in COMMON_SURNAMES:
|
|
254
|
+
return ""
|
|
255
|
+
if all(
|
|
256
|
+
(w.lower() in NON_NAME_WORDS and w.lower() not in COMMON_SURNAMES and w.lower() not in COMMON_FIRST_NAMES)
|
|
257
|
+
or w.lower() in MAJOR_GERMAN_CITIES
|
|
258
|
+
for w in kept
|
|
259
|
+
):
|
|
260
|
+
return ""
|
|
261
|
+
if all(w.isupper() and len(w) >= 2 for w in kept):
|
|
262
|
+
return ""
|
|
263
|
+
return " ".join(kept)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def detect_names(text: str, *, lines_cache: list[tuple[int, int, str]] | None = None) -> list[SpanMatch]:
|
|
267
|
+
matches: list[SpanMatch] = []
|
|
268
|
+
|
|
269
|
+
def add_candidate(raw: str, raw_start: int, confidence: Confidence, rule: str, *, allow_dict_word: bool = False) -> None:
|
|
270
|
+
cleaned = _trim_name_candidate(raw, allow_dict_word=allow_dict_word)
|
|
271
|
+
if not cleaned or len(cleaned) < 2 or _SINGLE_INITIAL_RE.match(cleaned):
|
|
272
|
+
return
|
|
273
|
+
matches.append(SpanMatch(raw_start, raw_start + len(cleaned), cleaned, Category.NAME, confidence, rule))
|
|
274
|
+
|
|
275
|
+
# 1. Kontext-Trigger mit hoher Konfidenz
|
|
276
|
+
for regex, rule in _HIGH_CONTEXT_NAME_RULES:
|
|
277
|
+
is_honorific_rule = regex in (_HONORIFIC_NAME_RE, _TITLE_NAME_RE)
|
|
278
|
+
for m in regex.finditer(text):
|
|
279
|
+
add_candidate(m.group(1), m.start(1), Confidence.HIGH, rule, allow_dict_word=is_honorific_rule)
|
|
280
|
+
|
|
281
|
+
# 1b. Kleingeschriebene Anreden („herr schmidt“, „fr. becker“ – aber kein „fr. tourenplanung“ = Freitag!)
|
|
282
|
+
for m in _HONORIFIC_LOWER_RE.finditer(text):
|
|
283
|
+
hon = m.group(1).lower()
|
|
284
|
+
raw = m.group(2)
|
|
285
|
+
if raw[0].isupper():
|
|
286
|
+
continue
|
|
287
|
+
kept: list[str] = []
|
|
288
|
+
for idx, w in enumerate(raw.split()):
|
|
289
|
+
wl = w.lower()
|
|
290
|
+
# Bei „fr.“ (oft Abkürzung für „Freitag“) nur bekannte Vor-/Nachnamen akzeptieren!
|
|
291
|
+
if hon == "fr." and idx == 0 and wl not in COMMON_SURNAMES and wl not in COMMON_FIRST_NAMES:
|
|
292
|
+
break
|
|
293
|
+
if (
|
|
294
|
+
(wl in NON_NAME_WORDS and wl not in COMMON_SURNAMES)
|
|
295
|
+
or wl in MAJOR_GERMAN_CITIES
|
|
296
|
+
or matches_job_stem(normalize_job_token(w))
|
|
297
|
+
or is_common_german_dictionary_word(w)
|
|
298
|
+
):
|
|
299
|
+
break
|
|
300
|
+
kept.append(w)
|
|
301
|
+
if kept:
|
|
302
|
+
cleaned = " ".join(kept)
|
|
303
|
+
if len(cleaned) >= 3:
|
|
304
|
+
matches.append(SpanMatch(m.start(2), m.start(2) + len(cleaned), cleaned, Category.NAME, Confidence.HIGH, "Name (Anrede kleingeschrieben)"))
|
|
305
|
+
|
|
306
|
+
# 1c. CRM-Subjekt vor Personen-Verb
|
|
307
|
+
for m in _PERSON_ACTION_RE.finditer(text):
|
|
308
|
+
cleaned = _trim_name_candidate(m.group(1))
|
|
309
|
+
if not cleaned or len(cleaned) < 3:
|
|
310
|
+
continue
|
|
311
|
+
tokens = cleaned.split()
|
|
312
|
+
if any(t.lower() in MAJOR_GERMAN_CITIES for t in tokens):
|
|
313
|
+
continue
|
|
314
|
+
if len(tokens) == 1 and matches_job_stem(normalize_job_token(tokens[0])):
|
|
315
|
+
continue
|
|
316
|
+
is_known = len(tokens) >= 2 or tokens[0].lower() in COMMON_FIRST_NAMES or tokens[0].lower() in COMMON_SURNAMES
|
|
317
|
+
matches.append(SpanMatch(m.start(1), m.start(1) + len(cleaned), cleaned, Category.NAME, Confidence.HIGH if is_known else Confidence.REVIEW, "Name (Handlungsträger / CRM-Notiz)"))
|
|
318
|
+
|
|
319
|
+
# 1d. GROSSBUCHSTABEN-Namen
|
|
320
|
+
for m in _ALLCAPS_HONORIFIC_RE.finditer(text):
|
|
321
|
+
words = [w for w in m.group(1).split() if w.lower() not in NON_NAME_WORDS or w.lower() in COMMON_SURNAMES]
|
|
322
|
+
if words and not LEGAL_FORM_TAIL_RE.fullmatch(words[0]):
|
|
323
|
+
cleaned = " ".join(words)
|
|
324
|
+
if len(cleaned) >= 3:
|
|
325
|
+
matches.append(SpanMatch(m.start(1), m.start(1) + len(cleaned), cleaned, Category.NAME, Confidence.HIGH, "Name (Herr/Frau GROSSBUCHSTABEN)"))
|
|
326
|
+
|
|
327
|
+
for m in _ALLCAPS_TWO_WORDS_RE.finditer(text):
|
|
328
|
+
w1, w2 = m.group(1), m.group(2)
|
|
329
|
+
w1_l, w2_l = w1.lower(), w2.lower()
|
|
330
|
+
if w1_l in COMMON_FIRST_NAMES and w1_l not in NON_NAME_WORDS:
|
|
331
|
+
w2_ok = (w2_l in COMMON_SURNAMES) or (
|
|
332
|
+
w2_l not in NON_NAME_WORDS
|
|
333
|
+
and w2_l not in MAJOR_GERMAN_CITIES
|
|
334
|
+
and not LEGAL_FORM_TAIL_RE.fullmatch(w2)
|
|
335
|
+
and not matches_job_stem(normalize_job_token(w2))
|
|
336
|
+
and len(w2) >= 3
|
|
337
|
+
)
|
|
338
|
+
if w2_ok:
|
|
339
|
+
s_start, s_end = m.start(1), m.end(2)
|
|
340
|
+
matches.append(SpanMatch(s_start, s_end, text[s_start:s_end], Category.NAME, Confidence.HIGH, "Name (Vorname + Nachname GROSSBUCHSTABEN)"))
|
|
341
|
+
|
|
342
|
+
for m in _ALLCAPS_SURNAME_COMMA_FIRST_RE.finditer(text):
|
|
343
|
+
s_l, f_l = m.group(1).lower(), m.group(2).lower()
|
|
344
|
+
if f_l in COMMON_FIRST_NAMES and (s_l in COMMON_SURNAMES or (s_l not in NON_NAME_WORDS and s_l not in MAJOR_GERMAN_CITIES)):
|
|
345
|
+
matches.append(SpanMatch(m.start(), m.end(), m.group(0), Category.NAME, Confidence.HIGH, "Name (Nachname, Vorname GROSSBUCHSTABEN)"))
|
|
346
|
+
|
|
347
|
+
# 2. Grußformeln & E-Mail-Signaturen (nur wenn mehrzeilig)
|
|
348
|
+
if "\n" in text:
|
|
349
|
+
for sm in _SIGNOFF_LINE_RE.finditer(text):
|
|
350
|
+
pos = sm.end()
|
|
351
|
+
offset = pos
|
|
352
|
+
inspected = 0
|
|
353
|
+
for line in text[pos:].splitlines(keepends=True):
|
|
354
|
+
stripped = line.strip()
|
|
355
|
+
line_start = offset + (len(line) - len(line.lstrip(" \t")))
|
|
356
|
+
offset += len(line)
|
|
357
|
+
if not stripped or IMAGE_OR_SOCIAL_LINE_RE.match(stripped):
|
|
358
|
+
continue
|
|
359
|
+
inspected += 1
|
|
360
|
+
if inspected > 3:
|
|
361
|
+
break
|
|
362
|
+
if LEGAL_FORM_TAIL_RE.search(stripped) or _SIG_SKIP_CHARS_RE.search(stripped) or matches_job_stem(normalize_job_token(stripped)):
|
|
363
|
+
continue
|
|
364
|
+
m_sig = _SIG_NAME_TRAILING_RE.match(stripped)
|
|
365
|
+
if m_sig:
|
|
366
|
+
cand = _trim_name_candidate(m_sig.group(1))
|
|
367
|
+
if cand:
|
|
368
|
+
tokens = cand.split()
|
|
369
|
+
conf = Confidence.HIGH if (len(tokens) >= 2 or cand.lower() in COMMON_FIRST_NAMES or cand.lower() in COMMON_SURNAMES) else Confidence.REVIEW
|
|
370
|
+
name_start = line_start + m_sig.start(1)
|
|
371
|
+
matches.append(SpanMatch(name_start, name_start + len(cand), cand, Category.NAME, conf, "Name (E-Mail-Signatur)"))
|
|
372
|
+
break
|
|
373
|
+
|
|
374
|
+
# 2b. Signatur-Name direkt über Kontakt- oder Positionszeile
|
|
375
|
+
line_recs = lines_cache if lines_cache is not None else iter_lines_with_offsets(text)
|
|
376
|
+
for idx, (ln_start, _ln_end, ln) in enumerate(line_recs):
|
|
377
|
+
stripped = ln.strip()
|
|
378
|
+
if not stripped or IMAGE_OR_SOCIAL_LINE_RE.match(stripped):
|
|
379
|
+
continue
|
|
380
|
+
if LEGAL_FORM_TAIL_RE.search(stripped) or _SIG_SKIP_COLON_RE.search(stripped) or matches_job_stem(normalize_job_token(stripped)):
|
|
381
|
+
continue
|
|
382
|
+
m_sig = _SIG_NAME_EXACT_RE.match(stripped)
|
|
383
|
+
cand = ""
|
|
384
|
+
m_start = 0
|
|
385
|
+
if m_sig:
|
|
386
|
+
cand = _trim_name_candidate(m_sig.group(1))
|
|
387
|
+
m_start = m_sig.start(1)
|
|
388
|
+
else:
|
|
389
|
+
m_caps = _SIG_ALLCAPS_NAME_RE.match(stripped)
|
|
390
|
+
if m_caps:
|
|
391
|
+
caps_words = m_caps.group(1).split()
|
|
392
|
+
if (
|
|
393
|
+
len(caps_words) >= 2
|
|
394
|
+
and not all(w.lower() in NON_NAME_WORDS or w.lower() in MAJOR_GERMAN_CITIES for w in caps_words)
|
|
395
|
+
and not any(matches_job_stem(normalize_job_token(w)) for w in caps_words)
|
|
396
|
+
):
|
|
397
|
+
cand = m_caps.group(1)
|
|
398
|
+
m_start = m_caps.start(1)
|
|
399
|
+
if not cand or len(cand.split()) < 2:
|
|
400
|
+
continue
|
|
401
|
+
next_non_empty: list[str] = []
|
|
402
|
+
for _, _, nln in line_recs[idx + 1:]:
|
|
403
|
+
ns = nln.strip()
|
|
404
|
+
if ns:
|
|
405
|
+
next_non_empty.append(ns)
|
|
406
|
+
if len(next_non_empty) >= 2:
|
|
407
|
+
break
|
|
408
|
+
if any(
|
|
409
|
+
_CONTACT_LINE_HINT_RE.search(ns)
|
|
410
|
+
or matches_job_stem(normalize_job_token(ns))
|
|
411
|
+
or _MULTIWORD_JOB_RE.search(ns)
|
|
412
|
+
for ns in next_non_empty
|
|
413
|
+
):
|
|
414
|
+
line_lead = len(ln) - len(ln.lstrip(" \t"))
|
|
415
|
+
name_start = ln_start + line_lead + m_start
|
|
416
|
+
matches.append(SpanMatch(name_start, name_start + len(cand), cand, Category.NAME, Confidence.HIGH, "Name (Signaturblock über Kontakt/Position)"))
|
|
417
|
+
|
|
418
|
+
# 3. Lexikon-Vollname im Fließtext
|
|
419
|
+
for m in _TWO_CAP_WORDS_RE.finditer(text):
|
|
420
|
+
w1, w2 = m.group(1), m.group(3)
|
|
421
|
+
w1_l, w2_l = w1.lower(), w2.lower()
|
|
422
|
+
if w1_l in COMMON_FIRST_NAMES and w1_l not in NON_NAME_WORDS:
|
|
423
|
+
w2_ok = (w2_l in COMMON_SURNAMES) or (
|
|
424
|
+
w2_l not in NON_NAME_WORDS
|
|
425
|
+
and w2_l not in MAJOR_GERMAN_CITIES
|
|
426
|
+
and not LEGAL_FORM_TAIL_RE.fullmatch(w2)
|
|
427
|
+
and not matches_job_stem(normalize_job_token(w2))
|
|
428
|
+
)
|
|
429
|
+
if w2_ok:
|
|
430
|
+
span_start, span_end = m.start(1), m.end(3)
|
|
431
|
+
conf = Confidence.REVIEW if (w1_l in _AMBIGUOUS_FIRST_NAMES and w2_l not in COMMON_SURNAMES) else Confidence.HIGH
|
|
432
|
+
matches.append(SpanMatch(span_start, span_end, text[span_start:span_end], Category.NAME, conf, "Name (Vorname + Nachname)"))
|
|
433
|
+
|
|
434
|
+
# 4. Initiale + Nachname („M. Müller“)
|
|
435
|
+
if "." in text:
|
|
436
|
+
for m in _INITIAL_SURNAME_RE.finditer(text):
|
|
437
|
+
surname = m.group(2)
|
|
438
|
+
sl = surname.lower()
|
|
439
|
+
if len(surname) < 3 or surname.isupper() or sl in NON_NAME_WORDS or sl in MAJOR_GERMAN_CITIES:
|
|
440
|
+
continue
|
|
441
|
+
if LEGAL_FORM_TAIL_RE.fullmatch(surname) or matches_job_stem(normalize_job_token(surname)):
|
|
442
|
+
continue
|
|
443
|
+
if sl.endswith(_STREET_SUFFIX_CHECK):
|
|
444
|
+
continue
|
|
445
|
+
conf = Confidence.HIGH if sl in COMMON_SURNAMES else Confidence.REVIEW
|
|
446
|
+
matches.append(SpanMatch(m.start(), m.end(), m.group(0), Category.NAME, conf, "Name (Initiale + Nachname)"))
|
|
447
|
+
|
|
448
|
+
# 5. „Müller, Thomas“
|
|
449
|
+
if "," in text:
|
|
450
|
+
for m in _SURNAME_COMMA_FIRST_RE.finditer(text):
|
|
451
|
+
s_l, f_l = m.group(1).lower(), m.group(2).lower()
|
|
452
|
+
if f_l in COMMON_FIRST_NAMES and (s_l in COMMON_SURNAMES or (s_l not in NON_NAME_WORDS and s_l not in MAJOR_GERMAN_CITIES)):
|
|
453
|
+
matches.append(SpanMatch(m.start(), m.end(), m.group(0), Category.NAME, Confidence.HIGH, "Name (Nachname, Vorname)"))
|
|
454
|
+
|
|
455
|
+
# 6. DSGVO-Sicherheitsnetz nach Präposition (mit Wörterbuch- & Komposita-Gegenprüfung!)
|
|
456
|
+
for m in _PREP_SINGLE_NAME_RE.finditer(text):
|
|
457
|
+
prep_l = m.group(1).lower()
|
|
458
|
+
word = m.group(2)
|
|
459
|
+
wl = word.lower()
|
|
460
|
+
if len(word) < 3 or word.isupper():
|
|
461
|
+
continue
|
|
462
|
+
if text[m.end(2):m.end(2) + 1] == ":":
|
|
463
|
+
continue
|
|
464
|
+
is_known = wl in COMMON_FIRST_NAMES or wl in COMMON_SURNAMES
|
|
465
|
+
# Nach „für“ / „mit“ stehen im Deutschen zu ~95 % Sachwörter („für Parktaschen“, „mit Sattelzug“) -> nur bekannte Namen!
|
|
466
|
+
if prep_l in _STRICT_PREP_KNOWN_ONLY and not is_known:
|
|
467
|
+
continue
|
|
468
|
+
if (
|
|
469
|
+
wl in NON_NAME_WORDS
|
|
470
|
+
or wl in MAJOR_GERMAN_CITIES
|
|
471
|
+
or matches_job_stem(normalize_job_token(word))
|
|
472
|
+
or is_common_german_dictionary_word(word)
|
|
473
|
+
):
|
|
474
|
+
continue
|
|
475
|
+
if LEGAL_FORM_TAIL_RE.fullmatch(word) or wl.endswith(_STREET_SUFFIX_CHECK):
|
|
476
|
+
continue
|
|
477
|
+
conf = Confidence.HIGH if is_known else Confidence.REVIEW
|
|
478
|
+
matches.append(SpanMatch(m.start(2), m.end(2), word, Category.NAME, conf, "Name (nach Präposition, DSGVO-Sicherheitsnetz)"))
|
|
479
|
+
|
|
480
|
+
return matches
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
# --- 3. Firmennamen / Organisationen (7 Kontext-Schichten, komplett vorkompiliert) ---
|
|
484
|
+
|
|
485
|
+
_LEGAL_FORM_FULL_ALT = (
|
|
486
|
+
r"g?GmbH(?:[ \t]*&[ \t]*Co\.?[ \t]*(?:KG|OHG|oHG))?"
|
|
487
|
+
r"|g?UG(?:[ \t]*\(haftungsbeschränkt\))?"
|
|
488
|
+
r"|AG(?:[ \t]*&[ \t]*Co\.?[ \t]*KGa?A?)?"
|
|
489
|
+
r"|SE(?:[ \t]*&[ \t]*Co\.?[ \t]*KGaA)?"
|
|
490
|
+
r"|OHG|oHG|GbR|KGaA|PartG(?:mbB)?|mbH"
|
|
491
|
+
r"|e\.?[ \t]*K(?:fm|fr)?\.?|e\.?[ \t]*V\.?|e\.?[ \t]*G\.?"
|
|
492
|
+
r"|Co\.?[ \t]*KG|KG"
|
|
493
|
+
r"|Ltd\.?|Inc\.?|LLC|LLP|PLC|Corp\.?|B\.?V\.?|N\.?V\.?|S\.?A\.?|S\.?r\.?l\.?|Sp\.[ \t]*z[ \t]*o\.?o\.?"
|
|
494
|
+
)
|
|
495
|
+
_LEGAL_FORM_FULL_RE = re.compile(rf"\b(?:{_LEGAL_FORM_FULL_ALT})\b")
|
|
496
|
+
|
|
497
|
+
_COMPANY_LEGAL_RE = re.compile(
|
|
498
|
+
r"(?:^|(?<=[\s,;:(\-\"']))"
|
|
499
|
+
rf"([A-ZÄÖÜ0-9][\wÄÖÜäöüß&\.\-/]+(?:[ \t]+(?:&[ \t]+)?[A-ZÄÖÜ0-9a-zäöüß][\wÄÖÜäöüß&\.\-/]*){{0,5}}[ \t]+"
|
|
500
|
+
rf"(?:{_LEGAL_FORM_FULL_ALT}))(?![A-Za-zÄÖÜäöüß0-9])"
|
|
501
|
+
)
|
|
502
|
+
_COMPANY_LABEL_RE = re.compile(
|
|
503
|
+
r"(?im)(?:^|(?<=[\n;|,]))[ \t]*(?:Firma|Firmenname|Unternehmen|Gesellschaft|Betrieb|"
|
|
504
|
+
r"Arbeitgeber|Auftraggeber|Geschäftspartner|Partnerfirma|Subunternehmer|Dienstleister|"
|
|
505
|
+
r"Lieferant|Spedition|Umzugsfirma|Umzugsunternehmen|Transportunternehmen|Logistikpartner|"
|
|
506
|
+
r"Kanzlei|Steuerkanzlei|Praxis|Hausverwaltung|Immobilienverwaltung|Baufirma|Bauunternehmen|"
|
|
507
|
+
r"Handwerksbetrieb|Kundenfirma|Rechnungsfirma|Company|Organisation|Organization)[ \t]*:[ \t]*"
|
|
508
|
+
r"([^\n;|]{2,80})"
|
|
509
|
+
)
|
|
510
|
+
_COMPANY_CONTEXT_RE = re.compile(
|
|
511
|
+
r"\b(?:"
|
|
512
|
+
r"(?:Wir[ \t]+sind|Ich[ \t]+bin|Anruf|Rückruf|Mail|E-?Mail|Nachricht|Rechnung|Angebot|Anfrage|Mitarbeiter(?:in)?)[ \t]+(?:von|bei)[ \t]+(?:der[ \t]+|dem[ \t]+)?"
|
|
513
|
+
r"|(?:im[ \t]+Auftrag|i\.?[ \t]*A\.?|namens)[ \t]+(?:der|des|von)[ \t]+(?:Firma[ \t]+)?"
|
|
514
|
+
r"|(?:arbeitet|angestellt|beschäftigt)[ \t]+bei[ \t]+(?:der[ \t]+|dem[ \t]+)?"
|
|
515
|
+
r"|(?:über|durch|bei|mit|von|an|für)[ \t]+(?:die[ \t]+|der[ \t]+)?(?:Firma|Fa\.|Spedition|Umzugsfirma|Baufirma|Hausverwaltung|Kanzlei)[ \t]+"
|
|
516
|
+
r"|(?:Vertrag|Zusammenarbeit|Abrechnung)[ \t]+mit[ \t]+(?:der[ \t]+|dem[ \t]+)?"
|
|
517
|
+
r"|(?:Firma|Fa\.|Unternehmen|Spedition|Umzugsfirma|Umzugsunternehmen|Transportfirma|Transportunternehmen|"
|
|
518
|
+
r"Baufirma|Bauunternehmen|Reinigungsfirma|Hausverwaltung|Immobilienverwaltung|Kanzlei|Steuerkanzlei|"
|
|
519
|
+
r"Praxis|Autohaus|Hotel|Agentur|Atelier|Studio|Werkstatt|Schreinerei|Tischlerei|Malerbetrieb|"
|
|
520
|
+
r"Elektrobetrieb|Subunternehmer|Dienstleister|Partnerfirma)[ \t]+"
|
|
521
|
+
r")"
|
|
522
|
+
r"([A-ZÄÖÜ0-9][\wÄÖÜäöüß&\.\-/]+(?:[ \t]+(?:&[ \t]+)?[A-ZÄÖÜ0-9a-zäöüß][\wÄÖÜäöüß&\.\-/]*){0,5})"
|
|
523
|
+
)
|
|
524
|
+
_COMPANY_AMP_RE = re.compile(
|
|
525
|
+
r"\b([A-ZÄÖÜ][\wÄÖÜäöüß\-]+(?:[ \t]+[A-ZÄÖÜ][\wÄÖÜäöüß\-]+)?[ \t]*&[ \t]*"
|
|
526
|
+
r"(?:Söhne|Soehne|Partner|Kollegen|Co\.?|Cie\.?|Brüder|Associates|Friends))\b"
|
|
527
|
+
)
|
|
528
|
+
_COMPANY_INDUSTRY_WORDS = (
|
|
529
|
+
r"Umzüge|Umzugsservice|Umzugslogistik|Umzugsunternehmen|Umzugsfirma|"
|
|
530
|
+
r"Transporte|Transportservice|Möbeltransporte|Logistik|Logistics|Spedition|"
|
|
531
|
+
r"Kurierdienst|Expressdienst|Fuhrparkservice|Immobilien|Hausverwaltung|Objektverwaltung|"
|
|
532
|
+
r"Gebäudereinigung|Gebäudeservice|Facility[ \t]+Management|Gerüstbau|Tiefbau|Hochbau|"
|
|
533
|
+
r"Straßenbau|Gartenbau|Landschaftsbau|Metallbau|Stahlbau|Elektrotechnik|Haustechnik|"
|
|
534
|
+
r"Klimatechnik|Sanitärtechnik|Bauunternehmen|Bauunternehmung|Handelsgesellschaft|"
|
|
535
|
+
r"Vertriebsgesellschaft|Verwaltungsgesellschaft|Dienstleistungen|Services|Solutions|"
|
|
536
|
+
r"Consulting|Systems|Group|Gruppe|Holding|Ventures|Industries|Enterprises|"
|
|
537
|
+
r"Rechtsanwälte|Steuerberatung|Wirtschaftsprüfung|Architekten|Ingenieurbüro|"
|
|
538
|
+
r"Planungsbüro|Maklerbüro|Autovermietung|Baumaschinen|Containerdienst|"
|
|
539
|
+
r"Sicherheitsdienst|Wachdienst|Personalservice|Zeitarbeit|Montageservice|"
|
|
540
|
+
r"Handwerkerservice|Malerbetrieb|Dachdeckerei|Schlosserei|Tischlerei|Schreinerei|"
|
|
541
|
+
r"Zimmerei|Druckerei|Autohaus|Werkstatt"
|
|
542
|
+
)
|
|
543
|
+
_COMPANY_INDUSTRY_WORD_RE = re.compile(rf"\b(?:{_COMPANY_INDUSTRY_WORDS})\b")
|
|
544
|
+
_COMPANY_INDUSTRY_PHRASE_RE = re.compile(
|
|
545
|
+
rf"\b([A-ZÄÖÜ0-9][\wÄÖÜäöüß&\.\-]+(?:[ \t]+(?:&[ \t]+)?[A-ZÄÖÜ0-9][\wÄÖÜäöüß&\.\-]+){{0,2}}[ \t]+(?:{_COMPANY_INDUSTRY_WORDS}))\b"
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
_COMPANY_DROP_PREFIX = frozenset({
|
|
549
|
+
"der", "die", "das", "den", "dem", "des", "ein", "eine", "einer", "einem", "einen",
|
|
550
|
+
"von", "vom", "bei", "beim", "mit", "für", "an", "am", "auf", "in", "im", "zu", "zum", "zur",
|
|
551
|
+
"über", "durch", "und", "oder", "aber", "sind", "ist", "war", "wir", "sie", "ich", "er", "es",
|
|
552
|
+
"hat", "haben", "wird", "wurde", "bitte", "danke", "hallo", "moin", "sehr", "geehrte", "geehrter",
|
|
553
|
+
"firma", "fa.", "fa", "unternehmen", "kunde", "kunden", "auftraggeber", "partner", "laut", "gemäß",
|
|
554
|
+
"hier", "dort", "heute", "morgen", "wegen", "trotz", "sowie", "dass", "weil", "wenn", "ob",
|
|
555
|
+
"anruf", "mail", "e-mail", "nachricht", "rechnung", "angebot", "anfrage", "vertrag",
|
|
556
|
+
})
|
|
557
|
+
_COMPANY_STOP_TAIL = frozenset({
|
|
558
|
+
"hat", "haben", "hatte", "hätte", "ist", "sind", "war", "wäre", "wird", "werden", "wurde",
|
|
559
|
+
"kann", "können", "könnte", "muss", "müssen", "soll", "sollen", "sollte", "will", "wollen",
|
|
560
|
+
"möchte", "möchten", "darf", "dürfen", "bittet", "bat", "meldet", "meldete", "ruft", "rief",
|
|
561
|
+
"schrieb", "sagte", "teilt", "teilte", "fragt", "fragte", "bestätigt", "storniert", "kommt",
|
|
562
|
+
"fährt", "stellt", "liefert", "übernimmt", "bezahlt", "überweist", "benötigt", "braucht",
|
|
563
|
+
"wegen", "für", "mit", "bei", "beim", "am", "im", "in", "zu", "zum", "zur", "nach", "aus",
|
|
564
|
+
"ab", "bis", "auf", "über", "unter", "neben", "zwischen", "durch", "gegen", "ohne", "um",
|
|
565
|
+
"und", "oder", "aber", "denn", "weil", "dass", "daß", "wenn", "falls", "ob", "sowie", "bzw",
|
|
566
|
+
"die", "der", "das", "den", "dem", "des", "ein", "eine", "einen", "einem", "einer",
|
|
567
|
+
"nicht", "noch", "bereits", "schon", "hier", "dort", "heute", "morgen", "gestern", "sofort",
|
|
568
|
+
"bitte", "danke", "leider", "gerne", "gern", "sehr", "auch", "nochmal", "wieder", "aktuell",
|
|
569
|
+
"fahrzeuge", "fahrzeug", "lkw", "pkw", "termin", "datum", "uhr", "adresse", "anschrift",
|
|
570
|
+
"telefon", "tel", "email", "e-mail", "mail", "iban", "betrag", "kosten", "preis", "rechnung",
|
|
571
|
+
})
|
|
572
|
+
_EXPLICIT_COMPANY_TRIGGERS = (
|
|
573
|
+
"firma", "fa.", "unternehmen", "spedition", "umzugsfirma", "umzugsunternehmen",
|
|
574
|
+
"transportfirma", "baufirma", "bauunternehmen", "reinigungsfirma", "hausverwaltung",
|
|
575
|
+
"kanzlei", "praxis", "autohaus", "hotel", "agentur", "studio", "werkstatt",
|
|
576
|
+
"schreinerei", "tischlerei", "malerbetrieb", "elektrobetrieb", "subunternehmer",
|
|
577
|
+
"dienstleister", "partnerfirma", "wir sind von", "ich bin von", "im auftrag",
|
|
578
|
+
"arbeitet bei", "angestellt bei", "beschäftigt bei", "vertrag mit",
|
|
579
|
+
)
|
|
580
|
+
_ADDRESS_BLOCK_PROSE_WORDS = frozenset({
|
|
581
|
+
"ist", "sind", "war", "waren", "wäre", "wird", "werden", "wurde", "hat", "haben", "hatte",
|
|
582
|
+
"kann", "können", "soll", "sollen", "muss", "müssen", "möchte", "möchten", "will", "wollen",
|
|
583
|
+
"bitte", "bitten", "erbitte", "danke", "leider", "gerne", "gern", "vielen", "sehr", "liebe",
|
|
584
|
+
"lieber", "hallo", "guten", "moin", "servus", "dass", "daß", "weil", "wenn", "aber", "oder",
|
|
585
|
+
"nicht", "noch", "schon", "bereits", "hier", "dort", "heute", "morgen", "gestern", "kommt",
|
|
586
|
+
"kommen", "fährt", "fahren", "steht", "stehen", "liegt", "liegen", "bleibt", "bleiben",
|
|
587
|
+
"weitergeleitet", "weitergeleitete", "betreff", "datum", "uhrzeit", "telefon", "mobil",
|
|
588
|
+
"email", "e-mail", "mail", "iban", "bic", "betrag", "kosten", "rechnung", "bestellung",
|
|
589
|
+
"auftrag", "genehmigung", "adresse", "anschrift", "lieferadresse", "rechnungsadresse",
|
|
590
|
+
"einsatzort", "aufstellort", "standort", "abholort", "zielort",
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
_DOMAIN_EXTRACT_RE = re.compile(r"(?:@|https?://(?:www\.)?|\bwww\.)([a-zA-Z0-9][a-zA-Z0-9\-]{2,40})\.[a-zA-Z]{2,15}\b", re.IGNORECASE)
|
|
594
|
+
_FIRST_WORD_WS_RE = re.compile(r"^(\S+)([ \t]+)")
|
|
595
|
+
_TAIL_PUNCT_SPLIT_RE = re.compile(r"(?:\.[ \t]+|[;!?()\[\]]|,[ \t]+)")
|
|
596
|
+
_NOT_COMPANY_VAL_RE = re.compile(r"[@]|^\d[\d\s.,:/\-]+$")
|
|
597
|
+
_DOMAIN_CANDIDATE_RE = re.compile(r"\b([A-ZÄÖÜ][A-Za-zÄÖÜäöüß0-9\-]{2,30}(?:[ \t]+[A-ZÄÖÜ][A-Za-zÄÖÜäöüß0-9\-]{2,25}){0,2})\b")
|
|
598
|
+
_COMPACT_WS_DASH_RE = re.compile(r"[\s\-]+")
|
|
599
|
+
_ADDR_HEADER_BAD_RE = re.compile(r"[!?]|\.[ \t]+[A-ZÄÖÜ]|@|https?://|www\.|\d{4,}|\d{1,2}\.\d{1,2}\.\d{2,4}", re.IGNORECASE)
|
|
600
|
+
_HONORIFIC_HEADS = frozenset({"herr", "herrn", "frau", "hr", "fr", "dr", "prof", "c/o", "z.hd", "z.hd."})
|
|
601
|
+
_CONNECTOR_WORDS = frozenset({"&", "für", "von", "der", "des", "am", "im", "in", "an", "e.k.", "e.v.", "mbh", "gmbh"})
|
|
602
|
+
_TRAILING_CONNECTORS = frozenset({"&", "und", "für", "von", "der", "des", "am", "im", "in", "an"})
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def _trim_company_prefix(raw: str) -> tuple[int, str]:
|
|
606
|
+
offset = 0
|
|
607
|
+
s = raw
|
|
608
|
+
while True:
|
|
609
|
+
m = _FIRST_WORD_WS_RE.match(s)
|
|
610
|
+
if not m:
|
|
611
|
+
break
|
|
612
|
+
first = m.group(1)
|
|
613
|
+
rest = s[m.end():]
|
|
614
|
+
if not rest:
|
|
615
|
+
break
|
|
616
|
+
first_l = first.lower().strip(".,:;!?\"'()")
|
|
617
|
+
if first_l in _COMPANY_DROP_PREFIX or (first[0].islower() and first_l not in {"van", "von", "de"}):
|
|
618
|
+
offset += m.end()
|
|
619
|
+
s = rest
|
|
620
|
+
else:
|
|
621
|
+
break
|
|
622
|
+
return offset, s
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def _trim_company_context_tail(raw: str) -> str:
|
|
626
|
+
line = raw.splitlines()[0].strip()
|
|
627
|
+
line = _TAIL_PUNCT_SPLIT_RE.split(line, maxsplit=1)[0].strip(" .,:;-")
|
|
628
|
+
words = line.split()
|
|
629
|
+
kept: list[str] = []
|
|
630
|
+
for idx, w in enumerate(words):
|
|
631
|
+
wl = w.lower().rstrip(".,:;!?")
|
|
632
|
+
if idx > 0 and wl in _COMPANY_STOP_TAIL:
|
|
633
|
+
break
|
|
634
|
+
if idx == 0 and wl in _COMPANY_DROP_PREFIX:
|
|
635
|
+
return ""
|
|
636
|
+
if idx > 0 and w[0].islower() and wl not in _CONNECTOR_WORDS:
|
|
637
|
+
break
|
|
638
|
+
kept.append(w)
|
|
639
|
+
while len(kept) > 1 and kept[-1].lower() in _TRAILING_CONNECTORS:
|
|
640
|
+
kept.pop()
|
|
641
|
+
return " ".join(kept).strip(" .,:;-")
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def _extract_company_domain_stems(text: str) -> set[str]:
|
|
645
|
+
if "@" not in text and "www." not in text.lower() and "http" not in text.lower():
|
|
646
|
+
return set()
|
|
647
|
+
stems: set[str] = set()
|
|
648
|
+
for m in _DOMAIN_EXTRACT_RE.finditer(text):
|
|
649
|
+
stem = m.group(1).lower()
|
|
650
|
+
if stem in FREEMAIL_DOMAIN_STEMS or len(stem) < 4:
|
|
651
|
+
continue
|
|
652
|
+
stems.add(stem)
|
|
653
|
+
for part in stem.split("-"):
|
|
654
|
+
if len(part) >= 5 and part not in FREEMAIL_DOMAIN_STEMS and part not in MAJOR_GERMAN_CITIES and part not in NON_NAME_WORDS:
|
|
655
|
+
stems.add(part)
|
|
656
|
+
return stems
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
def _valid_company(candidate: str) -> bool:
|
|
660
|
+
if not candidate or len(candidate) < 2:
|
|
661
|
+
return False
|
|
662
|
+
low = candidate.lower()
|
|
663
|
+
if is_public_authority(candidate):
|
|
664
|
+
return False
|
|
665
|
+
if low in NON_NAME_WORDS or low in MAJOR_GERMAN_CITIES or low in ORG_NOISE_WORDS:
|
|
666
|
+
return False
|
|
667
|
+
if IMAGE_OR_SOCIAL_LINE_RE.match(candidate):
|
|
668
|
+
return False
|
|
669
|
+
return True
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def _is_standalone_street_line(line_txt: str) -> bool:
|
|
673
|
+
s = line_txt.strip()
|
|
674
|
+
if not s or len(s) > 95:
|
|
675
|
+
return False
|
|
676
|
+
m_st = STREET_COMPOUND_RE.match(s) or STREET_PREFIX_RE.match(s)
|
|
677
|
+
if not m_st or not is_plausible_street(m_st.group(0).strip()):
|
|
678
|
+
return False
|
|
679
|
+
tail = s[m_st.end():].strip(" ,;-/")
|
|
680
|
+
return len(tail.split()) <= 5
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def _is_person_or_role_header(cand: str) -> bool:
|
|
684
|
+
words = cand.split()
|
|
685
|
+
if not words:
|
|
686
|
+
return False
|
|
687
|
+
first_l = words[0].lower().rstrip(".,:")
|
|
688
|
+
if first_l in _HONORIFIC_HEADS:
|
|
689
|
+
return True
|
|
690
|
+
if "&" in cand or first_l in {"der", "die", "das"} or _LEGAL_FORM_FULL_RE.search(cand) or _COMPANY_INDUSTRY_WORD_RE.search(cand):
|
|
691
|
+
return False
|
|
692
|
+
if any(matches_job_stem(normalize_job_token(w)) for w in words):
|
|
693
|
+
return True
|
|
694
|
+
if 2 <= len(words) <= 3:
|
|
695
|
+
w0 = words[0].lower().rstrip(".,")
|
|
696
|
+
w_last = words[-1].lower().rstrip(".,")
|
|
697
|
+
if w0 in COMMON_FIRST_NAMES or (len(words) == 2 and w_last in COMMON_SURNAMES):
|
|
698
|
+
return True
|
|
699
|
+
return False
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def _is_plausible_address_block_company(cand: str) -> bool:
|
|
703
|
+
if not cand or len(cand) < 2 or len(cand) > 65:
|
|
704
|
+
return False
|
|
705
|
+
if not (cand[0].isupper() or cand[0].isdigit()) or cand[-1] in ":?!,;":
|
|
706
|
+
return False
|
|
707
|
+
if _ADDR_HEADER_BAD_RE.search(cand):
|
|
708
|
+
return False
|
|
709
|
+
if _SIGNOFF_LINE_RE.match(cand) or _SALUTATION_RE.match(cand) or IMAGE_OR_SOCIAL_LINE_RE.match(cand):
|
|
710
|
+
return False
|
|
711
|
+
if not _valid_company(cand):
|
|
712
|
+
return False
|
|
713
|
+
words = cand.split()
|
|
714
|
+
if not (1 <= len(words) <= 6):
|
|
715
|
+
return False
|
|
716
|
+
low_words = [w.lower().strip(".,:;!?\"'()") for w in words]
|
|
717
|
+
if any(lw in _ADDRESS_BLOCK_PROSE_WORDS for lw in low_words):
|
|
718
|
+
return False
|
|
719
|
+
return not all(lw in NON_NAME_WORDS or lw in MAJOR_GERMAN_CITIES for lw in low_words)
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
def detect_companies(text: str, *, lines_cache: list[tuple[int, int, str]] | None = None) -> list[SpanMatch]:
|
|
723
|
+
matches: list[SpanMatch] = []
|
|
724
|
+
|
|
725
|
+
# 1. Rechtsform (GmbH, UG, AG, ...)
|
|
726
|
+
for m in _COMPANY_LEGAL_RE.finditer(text):
|
|
727
|
+
rel_off, cleaned = _trim_company_prefix(m.group(1))
|
|
728
|
+
cleaned = cleaned.strip(" .,:;")
|
|
729
|
+
if _valid_company(cleaned):
|
|
730
|
+
start = m.start(1) + rel_off
|
|
731
|
+
matches.append(SpanMatch(start, start + len(cleaned), cleaned, Category.COMPANY, Confidence.HIGH, "Firmenname (Rechtsform)"))
|
|
732
|
+
|
|
733
|
+
# 2. Feld-Labels („Firma: ...“, „Arbeitgeber: ...“)
|
|
734
|
+
if ":" in text:
|
|
735
|
+
for m in _COMPANY_LABEL_RE.finditer(text):
|
|
736
|
+
raw = m.group(1)
|
|
737
|
+
lead = len(raw) - len(raw.lstrip(" \t"))
|
|
738
|
+
cleaned = _trim_company_context_tail(raw.lstrip(" \t"))
|
|
739
|
+
if _valid_company(cleaned) and not _NOT_COMPANY_VAL_RE.search(cleaned):
|
|
740
|
+
start = m.start(1) + lead
|
|
741
|
+
matches.append(SpanMatch(start, start + len(cleaned), cleaned, Category.COMPANY, Confidence.HIGH, "Firmenname (Feld-Label)"))
|
|
742
|
+
|
|
743
|
+
# 3. Kontext-Sätze
|
|
744
|
+
for m in _COMPANY_CONTEXT_RE.finditer(text):
|
|
745
|
+
cleaned = _trim_company_context_tail(m.group(1))
|
|
746
|
+
if not _valid_company(cleaned):
|
|
747
|
+
continue
|
|
748
|
+
if cleaned.split()[0].lower() in {"herr", "herrn", "frau", "hr.", "fr.", "dr.", "prof."}:
|
|
749
|
+
continue
|
|
750
|
+
prefix_txt = text[m.start():m.start(1)].lower()
|
|
751
|
+
is_explicit = any(kw in prefix_txt for kw in _EXPLICIT_COMPANY_TRIGGERS)
|
|
752
|
+
if not is_explicit:
|
|
753
|
+
if not (_LEGAL_FORM_FULL_RE.search(cleaned) or "&" in cleaned or _COMPANY_INDUSTRY_WORD_RE.search(cleaned)):
|
|
754
|
+
continue
|
|
755
|
+
matches.append(SpanMatch(m.start(1), m.start(1) + len(cleaned), cleaned, Category.COMPANY, Confidence.HIGH, "Firmenname (Kontext)"))
|
|
756
|
+
|
|
757
|
+
# 4. „& Söhne / & Partner / & Co.“
|
|
758
|
+
if "&" in text:
|
|
759
|
+
for m in _COMPANY_AMP_RE.finditer(text):
|
|
760
|
+
cleaned = m.group(1).strip(" .,:;")
|
|
761
|
+
if _valid_company(cleaned):
|
|
762
|
+
matches.append(SpanMatch(m.start(1), m.start(1) + len(cleaned), cleaned, Category.COMPANY, Confidence.HIGH, "Firmenname (& Partner / & Söhne)"))
|
|
763
|
+
|
|
764
|
+
# 5. Markenname + Branchenwort
|
|
765
|
+
for m in _COMPANY_INDUSTRY_PHRASE_RE.finditer(text):
|
|
766
|
+
rel_off, cleaned = _trim_company_prefix(m.group(1))
|
|
767
|
+
cleaned = cleaned.strip(" .,:;")
|
|
768
|
+
if not _valid_company(cleaned) or len(cleaned.split()) < 2:
|
|
769
|
+
continue
|
|
770
|
+
w0_l = cleaned.split()[0].lower()
|
|
771
|
+
if w0_l in NON_NAME_WORDS and w0_l not in COMMON_SURNAMES:
|
|
772
|
+
continue
|
|
773
|
+
start = m.start(1) + rel_off
|
|
774
|
+
matches.append(SpanMatch(start, start + len(cleaned), cleaned, Category.COMPANY, Confidence.HIGH, "Firmenname (Branchenbezeichnung)"))
|
|
775
|
+
|
|
776
|
+
# 6. Domain-Kontext-Abgleich
|
|
777
|
+
domain_stems = _extract_company_domain_stems(text)
|
|
778
|
+
if domain_stems:
|
|
779
|
+
url_or_mail_ranges = [
|
|
780
|
+
(um.start(), um.end())
|
|
781
|
+
for um in list(EMAIL_RE.finditer(text)) + list(URL_FULL_RE.finditer(text)) + list(BARE_DOMAIN_RE.finditer(text))
|
|
782
|
+
]
|
|
783
|
+
for cand_m in _DOMAIN_CANDIDATE_RE.finditer(text):
|
|
784
|
+
cs, ce = cand_m.start(1), cand_m.end(1)
|
|
785
|
+
if any(us <= cs and ce <= ue for us, ue in url_or_mail_ranges):
|
|
786
|
+
continue
|
|
787
|
+
cand = cand_m.group(1)
|
|
788
|
+
norm_compact = _COMPACT_WS_DASH_RE.sub("", cand.lower())
|
|
789
|
+
norm_ascii = norm_compact.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue").replace("ß", "ss")
|
|
790
|
+
if (norm_compact in domain_stems or norm_ascii in domain_stems) and _valid_company(cand):
|
|
791
|
+
matches.append(SpanMatch(cs, ce, cand, Category.COMPANY, Confidence.HIGH, "Firmenname (E-Mail-/Web-Domain-Kontext)"))
|
|
792
|
+
|
|
793
|
+
# 7. Adressblock-Kontext (Zeile direkt über alleinstehender Straßenzeile, z. B. „Der Packesel\nAlte Heroldstr.23“)
|
|
794
|
+
if "\n" in text:
|
|
795
|
+
line_records = lines_cache if lines_cache is not None else iter_lines_with_offsets(text)
|
|
796
|
+
existing_comp_spans = [(m.start, m.end) for m in matches]
|
|
797
|
+
for idx, (_ls, _le, line_txt) in enumerate(line_records):
|
|
798
|
+
if idx == 0 or not _is_standalone_street_line(line_txt):
|
|
799
|
+
continue
|
|
800
|
+
for lookback in (idx - 1, idx - 2):
|
|
801
|
+
if lookback < 0:
|
|
802
|
+
break
|
|
803
|
+
prev_start, _prev_end, prev_txt = line_records[lookback]
|
|
804
|
+
cand = prev_txt.strip()
|
|
805
|
+
if not cand:
|
|
806
|
+
break
|
|
807
|
+
if _is_person_or_role_header(cand):
|
|
808
|
+
continue
|
|
809
|
+
if _is_plausible_address_block_company(cand):
|
|
810
|
+
lead = len(prev_txt) - len(prev_txt.lstrip(" \t"))
|
|
811
|
+
cs = prev_start + lead
|
|
812
|
+
ce = cs + len(cand)
|
|
813
|
+
if not any(es <= cs and ce <= ee for es, ee in existing_comp_spans):
|
|
814
|
+
matches.append(SpanMatch(cs, ce, cand, Category.COMPANY, Confidence.REVIEW, "Firmenname (Adressblock über Straße)"))
|
|
815
|
+
existing_comp_spans.append((cs, ce))
|
|
816
|
+
break
|
|
817
|
+
|
|
818
|
+
return matches
|