normalize_org_name keeps a partnership marker: a GmbH & Co KG no longer matches the GmbH
'Huber GmbH & Co KG' -> 'huber kg', 'Porsche Austria GmbH & Co OG' -> 'porsche austria og' (also &CoKG, KEG, OHG), 'Huber GmbH' -> 'huber'. Alias matching treated the partnership and its general partner (different legal entities) as one organisation. New legal_form_class(); firmenbuch.is_partnership uses it. Existing aliases are recomputed and the merged organisations split by a one-off script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c61cb31e4a
commit
1395dc2840
3 files changed
+44
-7
No files matched your search
@@ -37,7 +37,7 @@ from politrack.core import (
|
|||||||
)
|
)
|
||||||
from politrack.core.records import Claim, Evidence, OrgRecord, OrgRef, PersonRef
|
from politrack.core.records import Claim, Evidence, OrgRecord, OrgRef, PersonRef
|
||||||
from politrack.core.spec import DERIVED
|
from politrack.core.spec import DERIVED
|
||||||
from politrack.text import firmenbuch_number, format_eur_de, normalize_org_name
|
from politrack.text import firmenbuch_number, format_eur_de, legal_form_class, normalize_org_name
|
||||||
|
|
||||||
URL = "https://justizonline.gv.at/jop/api/at.gv.justiz.fbw/ws"
|
URL = "https://justizonline.gv.at/jop/api/at.gv.justiz.fbw/ws"
|
||||||
NS = "ns://firmenbuch.justiz.gv.at/Abfrage/"
|
NS = "ns://firmenbuch.justiz.gv.at/Abfrage/"
|
||||||
@@ -203,12 +203,9 @@ def search_term(name: str) -> str:
|
|||||||
return term if len(term) >= 3 else ""
|
return term if len(term) >= 3 else ""
|
||||||
|
|
||||||
|
|
||||||
PARTNERSHIP = re.compile(r"\b(kg|og|kommanditgesellschaft|offene gesellschaft|co\.?\s*kg)\b", re.IGNORECASE)
|
|
||||||
|
|
||||||
|
|
||||||
def is_partnership(name: str) -> bool:
|
def is_partnership(name: str) -> bool:
|
||||||
"""KG / OG / GmbH & Co KG: a different legal entity from the GmbH of the same name (often its general partner)."""
|
"""KG / OG / GmbH & Co KG: a different legal entity from the GmbH of the same name (often its general partner)."""
|
||||||
return bool(PARTNERSHIP.search(name))
|
return legal_form_class(name) in {"kg", "og"}
|
||||||
|
|
||||||
|
|
||||||
def unique_match(name: str, hits: list[dict[str, Any]]) -> dict[str, Any] | None:
|
def unique_match(name: str, hits: list[dict[str, Any]]) -> dict[str, Any] | None:
|
||||||
|
|||||||
@@ -49,17 +49,45 @@ LEGAL_FORMS = re.compile(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Partnerships (KG, OG, GmbH & Co KG) are separate legal entities from the corporation of the same name, which is
|
||||||
|
# often their general partner. KEG and OHG/OEG are the pre-2007 names of KG and OG (same entity, renamed by the UGB).
|
||||||
|
PARTNERSHIP_FORMS = re.compile(
|
||||||
|
r"\b(?:(?P<kg>kommanditgesellschaft|kommandit-erwerbsgesellschaft|keg|kg|cokg)"
|
||||||
|
r"|(?P<og>offene\s+(?:handels|erwerbs)?gesellschaft|ohg|oeg|og))\b"
|
||||||
|
)
|
||||||
|
CORPORATE_FORMS = re.compile(
|
||||||
|
r"\b(gmbh|gesmbh|mbh|g\.m\.b\.h|m\.?\s?b\.?\s?h|ag|aktiengesellschaft|se|e\.?\s?gen|egen|eg|ltd|inc|llc|plc)\b"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def legal_form_class(name: str) -> str | None:
|
||||||
|
"""'kg' or 'og' for a partnership (also 'GmbH & Co KG'), 'corp' for a corporation (GmbH, AG, SE, eGen ...),
|
||||||
|
None when the name carries no legal form."""
|
||||||
|
text = normalize(name)
|
||||||
|
m = PARTNERSHIP_FORMS.search(text)
|
||||||
|
if m:
|
||||||
|
return "kg" if m.group("kg") else "og"
|
||||||
|
return "corp" if CORPORATE_FORMS.search(text) else None
|
||||||
|
|
||||||
|
|
||||||
def normalize_org_name(name: str) -> str:
|
def normalize_org_name(name: str) -> str:
|
||||||
"""'HYPO TIROL BANK AG' == 'Hypo Tirol Bank Aktiengesellschaft' -> 'hypo tirol bank'.
|
"""'HYPO TIROL BANK AG' == 'Hypo Tirol Bank Aktiengesellschaft' -> 'hypo tirol bank'.
|
||||||
|
|
||||||
Lowercase, strip accents, quotes, punctuation and legal-form suffixes, so the same company is
|
Lowercase, strip accents, quotes, punctuation and legal-form suffixes, so the same company is
|
||||||
recognised across sources (side-job lists, procurement notices, donation lists, ad reports).
|
recognised across sources (side-job lists, procurement notices, donation lists, ad reports).
|
||||||
|
A partnership keeps a marker: 'Huber GmbH & Co KG' -> 'huber kg', 'Maier OG' -> 'maier og', so it never
|
||||||
|
matches 'Huber GmbH' -> 'huber'.
|
||||||
"""
|
"""
|
||||||
text = normalize(name)
|
text = normalize(name)
|
||||||
|
partnership = PARTNERSHIP_FORMS.search(text)
|
||||||
text = re.sub(r"[\"'„“”»«]", "", text)
|
text = re.sub(r"[\"'„“”»«]", "", text)
|
||||||
text = LEGAL_FORMS.sub(" ", text)
|
text = LEGAL_FORMS.sub(" ", text)
|
||||||
|
text = PARTNERSHIP_FORMS.sub(" ", text)
|
||||||
text = re.sub(r"[^\w\s-]", " ", text)
|
text = re.sub(r"[^\w\s-]", " ", text)
|
||||||
return re.sub(r"\s+", " ", text).strip(" -")
|
text = re.sub(r"\s+", " ", text).strip(" -&")
|
||||||
|
if partnership and text:
|
||||||
|
text += " kg" if partnership.group("kg") else " og"
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def firmenbuch_number(value: str | None) -> str | None:
|
def firmenbuch_number(value: str | None) -> str | None:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from politrack.core.adapter import Request, redact_url
|
|||||||
from politrack.core.records import Claim, Evidence, Money, OrgRef, to_jsonable
|
from politrack.core.records import Claim, Evidence, Money, OrgRef, to_jsonable
|
||||||
from politrack.openapi_ts import to_typescript, ts_type
|
from politrack.openapi_ts import to_typescript, ts_type
|
||||||
from politrack.sources.bundesregierung import ITEM, german_date, offices, period_start
|
from politrack.sources.bundesregierung import ITEM, german_date, offices, period_start
|
||||||
from politrack.text import format_eur_de, normalize_org_name
|
from politrack.text import format_eur_de, legal_form_class, normalize_org_name
|
||||||
|
|
||||||
|
|
||||||
def test_request_fingerprint_ignores_meta_and_headers():
|
def test_request_fingerprint_ignores_meta_and_headers():
|
||||||
@@ -50,6 +50,18 @@ def test_normalize_org_name():
|
|||||||
assert normalize_org_name("Muster Bau Gesellschaft m.b.H.") == "muster bau"
|
assert normalize_org_name("Muster Bau Gesellschaft m.b.H.") == "muster bau"
|
||||||
|
|
||||||
|
|
||||||
|
def test_partnership_keeps_its_marker():
|
||||||
|
# A GmbH & Co KG is a different legal entity from the GmbH of the same name.
|
||||||
|
kg = {normalize_org_name(n) for n in ("Huber GmbH & Co KG", "Huber Ges.m.b.H. & Co. KG.", "Huber GmbH&CoKG",
|
||||||
|
"Huber KG", "HUBER GMBH & CO KEG")}
|
||||||
|
assert kg == {"huber kg"}
|
||||||
|
assert normalize_org_name("Huber GmbH") == "huber"
|
||||||
|
assert normalize_org_name("Porsche Austria GmbH & Co OG") == normalize_org_name("Porsche Austria GmbH & Co. OHG")
|
||||||
|
assert normalize_org_name("Porsche Austria GmbH & Co OG") == "porsche austria og"
|
||||||
|
assert [legal_form_class(n) for n in ("Huber GmbH & Co KG", "Maier OG", "Huber GmbH", "Hypo AG", "Rotfuchs")] \
|
||||||
|
== ["kg", "og", "corp", "corp", None]
|
||||||
|
|
||||||
|
|
||||||
def test_format_eur_de():
|
def test_format_eur_de():
|
||||||
assert format_eur_de(1234567.8) == "1.234.567,80"
|
assert format_eur_de(1234567.8) == "1.234.567,80"
|
||||||
assert format_eur_de("n/a") == "n/a"
|
assert format_eur_de("n/a") == "n/a"
|
||||||
|
|||||||
Reference in new issue
Block a user