Saarland publiziert keine Wortprotokolle, sondern eigene HTML-Seiten
mit strukturierten Abstimmungsergebnissen pro Sitzung:
<p>Drucksache 17/2076 ... in Erster Lesung mit Stimmenmehrheit
angenommen ... [SPD: dafür; CDU und AfD: dagegen]</p>
Daher Input ist HTML, nicht PDF. Parser nutzt LI-Block-Iteration und
extrahiert pro Block:
- Drucksache aus "Drucksache N/M"
- Status aus "(einstimmig|mit Stimmenmehrheit)? (angenommen|abgelehnt)"
- Vote-Block aus "[SPD: dafür; CDU: dagegen; AfD: Enthaltung]"
- einstimmig=True falls Status enthaelt "einstimmig"
Vote-Bracket-Parser (eigenstaendig vs. Reden-Stil-Parser anderer BL):
- Splits per ; → "Phrase: Status"
- Phrase per Wortgrenzen-Regex auf {SPD,CDU,AfD} matchen
- Status-Map: dafür→ja, dagegen→nein, Enthaltung→enthaltung
URL-Pattern (nicht direkt vorhersagbar wegen Datums-Slug):
https://www.landtag-saar.de/aktuelles/mitteilungen/abstimmungsergebnisse-der-{n}-landtagssitzung-vom-{datum}/
Auto-Ingest via Index-Scrape (analog HH/HE/SH):
- /aktuelles/mitteilungen/ scrape
- WP16-URLs (mit "wahlperiode-vom") ueberspringen
- Pro neue Sitzung: HTML herunterladen, ingest_pdf-API auf .html-Datei
Tests: 18 SL-Tests (Verifikation Sitzung 46 → 18 Votes mit korrekten
JA/NEIN/ENTH-Listen). Stand: 9 produktive Parser
(NRW, BUND, BE, HH, TH, HE, SH, HB, SL).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
86 lines
2.8 KiB
Python
86 lines
2.8 KiB
Python
"""BL-uebergreifende Plenarprotokoll-Abstimmungsparser (#126).
|
|
|
|
Architektur (vgl. ADR 0009): pro Bundesland eine Modul-Datei
|
|
``app/protokoll_parsers/<bl-code>.py``, die mindestens eine Funktion
|
|
``parse_protocol(pdf_path: str) -> list[dict]`` exportiert. Die Registry
|
|
``PROTOKOLL_PARSERS`` mappt BL-Code → Parser-Funktion.
|
|
|
|
Erwartetes Result-Schema pro Eintrag in der Liste::
|
|
|
|
{
|
|
"drucksache": str | None, # z.B. "18/1234"; None bei nicht aufloesbar
|
|
"ergebnis": str, # angenommen | abgelehnt | ueberwiesen | ...
|
|
"einstimmig": bool, # explizit als einstimmig markiert
|
|
"kind": str, # parser-intern, fuer Debug
|
|
"votes": { # fraktions-Listen pro Vote-Kategorie
|
|
"ja": list[str],
|
|
"nein": list[str],
|
|
"enthaltung": list[str],
|
|
},
|
|
}
|
|
|
|
NRW ist die Referenz-Implementierung. Folge-BL (HE/BB/MV/BE/...) bekommen
|
|
eigene Module mit demselben Funktions-Vertrag — neue Eintraege in der
|
|
Registry sind reine Tippelarbeit, das Reverse-Engineering pro Landtag
|
|
ist die eigentliche Arbeit.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable
|
|
|
|
from .nrw import parse_protocol as _parse_nrw
|
|
from .bund import parse_protocol as _parse_bund
|
|
from .be import parse_protocol as _parse_be
|
|
from .hh import parse_protocol as _parse_hh
|
|
from .th import parse_protocol as _parse_th
|
|
from .he import parse_protocol as _parse_he
|
|
from .sh import parse_protocol as _parse_sh
|
|
from .hb import parse_protocol as _parse_hb
|
|
from .sl import parse_protocol as _parse_sl
|
|
|
|
# Typ-Alias fuer Lesbarkeit; Parser-Signatur ist bewusst minimal.
|
|
ProtokollParser = Callable[[str], list[dict]]
|
|
|
|
PROTOKOLL_PARSERS: dict[str, ProtokollParser] = {
|
|
"NRW": _parse_nrw,
|
|
"BUND": _parse_bund,
|
|
"BE": _parse_be,
|
|
"HH": _parse_hh,
|
|
"TH": _parse_th,
|
|
"HE": _parse_he,
|
|
"SH": _parse_sh,
|
|
"HB": _parse_hb,
|
|
"SL": _parse_sl,
|
|
}
|
|
|
|
|
|
def parse_protocol(bundesland: str, pdf_path: str) -> list[dict]:
|
|
"""BL-uebergreifender Einstieg. Sucht den Parser in der Registry.
|
|
|
|
Raises:
|
|
NotImplementedError: wenn fuer das Bundesland (noch) kein Parser
|
|
registriert ist. Folge-Issue: BL-Adapter ergaenzen mit einem
|
|
eigenen Modul plus Eintrag hier.
|
|
"""
|
|
parser = PROTOKOLL_PARSERS.get(bundesland)
|
|
if parser is None:
|
|
supported = ", ".join(sorted(PROTOKOLL_PARSERS)) or "(keine)"
|
|
raise NotImplementedError(
|
|
f"Kein Plenarprotokoll-Parser fuer {bundesland!r}. "
|
|
f"Unterstuetzt: {supported}. Siehe #126."
|
|
)
|
|
return parser(pdf_path)
|
|
|
|
|
|
def supported_bundeslaender() -> list[str]:
|
|
"""Liste der BL-Codes mit registrierten Parsern."""
|
|
return sorted(PROTOKOLL_PARSERS)
|
|
|
|
|
|
__all__ = [
|
|
"ProtokollParser",
|
|
"PROTOKOLL_PARSERS",
|
|
"parse_protocol",
|
|
"supported_bundeslaender",
|
|
]
|