feat: add _classify_from_titles keyword classifier to axis_classifier
This commit is contained in:
@@ -42,6 +42,95 @@ _INTERPRETATION_TEMPLATES = {
|
||||
}
|
||||
|
||||
|
||||
# Simple keyword-based classifier for motion titles (fallback signal)
|
||||
_KEYWORD_THRESHOLD = 0.4
|
||||
|
||||
_KEYWORDS: Dict[str, List[str]] = {
|
||||
"Links\u2013Rechts": [
|
||||
# economic
|
||||
"belasting",
|
||||
"uitkering",
|
||||
"bijstand",
|
||||
"minimumloon",
|
||||
"cao",
|
||||
"vakbond",
|
||||
"bezuiniging",
|
||||
"privatisering",
|
||||
"subsidie",
|
||||
"pensioen",
|
||||
"aow",
|
||||
"zorg",
|
||||
# immigration
|
||||
"asiel",
|
||||
"asielaanvraag",
|
||||
"migratie",
|
||||
"vreemdeling",
|
||||
"vluchtelingen",
|
||||
"terugkeer",
|
||||
"grenzen",
|
||||
"opvang",
|
||||
"statushouder",
|
||||
],
|
||||
"Progressief\u2013Conservatief": [
|
||||
# environment
|
||||
"klimaat",
|
||||
"stikstof",
|
||||
"duurzaam",
|
||||
"duurzaamheid",
|
||||
"co2",
|
||||
"energietransitie",
|
||||
"biodiversiteit",
|
||||
# social
|
||||
"euthanasie",
|
||||
"abortus",
|
||||
"lgbtq",
|
||||
"transgender",
|
||||
"diversiteit",
|
||||
"traditi",
|
||||
"gezin",
|
||||
"religie",
|
||||
"geloof",
|
||||
],
|
||||
"Nationaal\u2013Internationaal": [
|
||||
"navo",
|
||||
"nato",
|
||||
"europees",
|
||||
"europese",
|
||||
" eu ",
|
||||
"verdrag",
|
||||
" vn ",
|
||||
"internationaal",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _classify_from_titles(titles: List[str]) -> Tuple[Optional[str], float]:
|
||||
"""Classify a list of motion titles into an axis category using keyword matching.
|
||||
|
||||
Returns (category_label, confidence) where confidence = fraction of titles
|
||||
containing at least one keyword from the winning category.
|
||||
Returns (None, 0.0) if confidence is below _KEYWORD_THRESHOLD.
|
||||
"""
|
||||
if not titles:
|
||||
return None, 0.0
|
||||
|
||||
counts: Dict[str, int] = {cat: 0 for cat in _KEYWORDS}
|
||||
for title in titles:
|
||||
lower = title.lower()
|
||||
for cat, keywords in _KEYWORDS.items():
|
||||
if any(kw in lower for kw in keywords):
|
||||
counts[cat] += 1
|
||||
|
||||
best_cat = max(counts, key=lambda c: counts[c])
|
||||
best_count = counts[best_cat]
|
||||
confidence = best_count / len(titles)
|
||||
|
||||
if confidence < _KEYWORD_THRESHOLD:
|
||||
return None, confidence
|
||||
|
||||
return best_cat, confidence
|
||||
|
||||
|
||||
def _load_ideology(csv_path: Path) -> Dict[str, Dict[str, float]]:
|
||||
"""Load party ideology scores from CSV.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user