"""Detect reports about legal proceedings in news headlines (and WKStA press releases). Everything found here is a *proposal*: claims are created with review=True (hidden until a human approves them via `politrack review`). Headline wording is ambiguous, the data is specially protected (Art. 10 GDPR) and wrong attributions can be defamatory. Official parliament immunity data does not go through this path. Several outlets reporting the same person + stage in the same month attach to one claim (corroboration). """ from __future__ import annotations import re from collections.abc import Iterator from datetime import datetime from psycopg.types.json import Jsonb from politrack.core import Enricher, RunContext, register from politrack.core.records import Claim, Evidence, Legal, PersonRef from politrack.core.spec import DERIVED # Most specific first. STAGES = [ # "nicht rechtskräftig verurteilt" must never be read as a final conviction. ("convicted_final", re.compile(r"(? str | None: for stage, pattern in STAGES: if pattern.search(headline): return stage return None @register class LegalDetector(Enricher): spec = DERIVED name = "enrich.legal" description = "Propose legal-proceeding claims from headlines (human review required)" schedule = "6-59/10 * * * *" def run(self, ctx: RunContext) -> Iterator[Claim]: conn = ctx.conn while True: rows = conn.execute( """SELECT c.id, c.person_id, c.occurred_at, d.url, d.title, d.published_at, s.slug AS source FROM claim c JOIN claim_evidence e ON e.claim_id = c.id JOIN document d ON d.id = e.document_id JOIN source s ON s.id = d.source_id WHERE c.claim_type = 'media_mention' AND c.person_id IS NOT NULL AND NOT (c.data ? 'legal_checked') AND (s.kind IN ('media', 'aggregator') OR s.slug = 'wksta') ORDER BY c.id LIMIT 1000""" ).fetchall() if not rows: return for row in rows: stage = classify(row["title"] or "") if stage: when = row["published_at"] or row["occurred_at"] or datetime.now() yield Claim( claim_type="legal_proceeding", person=PersonRef(ids={"politrack": str(row["person_id"])}), key=("legal-news", row["person_id"], stage, when.strftime("%Y-%m")), occurred_at=when, summary_de=STAGE_DE[stage], summary_en=f"Reported legal matter ({stage.replace('_', ' ')})", data={"detected_from": "headline"}, sensitive=True, review=True, evidence=[Evidence(url=row["url"], source=row["source"], title=row["title"], published_at=when, quote=row["title"], confidence=0.5)], topics=("Inneres und Recht",), facet=Legal(stage=stage, stage_date=when.date()), ) ctx.stats["proposed"] += 1 conn.execute("UPDATE claim SET data = data || %s WHERE id = %s", (Jsonb({"legal_checked": True}), row["id"]))