refactor: use svd_labels for fallback labels in explorer and axis_classifier (Task 4)
This commit is contained in:
+17
-10
@@ -13,7 +13,7 @@ import numpy as np
|
||||
import re
|
||||
import json
|
||||
|
||||
from analysis.svd_labels import get_svd_label
|
||||
from analysis.svd_labels import get_svd_label, get_fallback_labels
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -44,16 +44,21 @@ _LABELS = {
|
||||
def display_label_for_modal(modal_label: Optional[str], axis: str) -> str:
|
||||
"""Return a user-facing axis label for a modal/internal label.
|
||||
|
||||
Keeps existing behavior: map numeric fallback names 'As 1' / 'Stempatroon As 1'
|
||||
to the conventional semantic defaults used in the UI. Any other label is
|
||||
returned unchanged; None is treated as the semantic fallback for the axis.
|
||||
Maps numeric fallback names 'As 1' / 'Stempatroon As 1' to the
|
||||
semantic labels from SVD_THEMES. Any other label is returned unchanged.
|
||||
None is treated as the semantic fallback for the axis.
|
||||
"""
|
||||
if modal_label is None:
|
||||
return "Links\u2013Rechts" if axis == "x" else "Progressief\u2013Conservatief"
|
||||
# Fallback to component 1 (x) or 2 (y)
|
||||
comp = 1 if axis == "x" else 2
|
||||
return get_svd_label(comp)
|
||||
|
||||
# Map "As 1" / "As 2" to semantic labels
|
||||
if axis == "x" and modal_label in ("As 1", "Stempatroon As 1"):
|
||||
return "Links\u2013Rechts"
|
||||
return get_svd_label(1)
|
||||
if axis == "y" and modal_label in ("As 2", "Stempatroon As 2"):
|
||||
return "Progressief\u2013Conservatief"
|
||||
return get_svd_label(2)
|
||||
|
||||
return modal_label
|
||||
|
||||
|
||||
@@ -430,7 +435,8 @@ def _assign_label(
|
||||
Returns (label, interpretation_string, quality_score).
|
||||
"""
|
||||
orientation = "horizontale" if axis == "x" else "verticale"
|
||||
fallback_label = _LABELS["fallback_x"] if axis == "x" else _LABELS["fallback_y"]
|
||||
_x_fallback, _y_fallback = get_fallback_labels()
|
||||
fallback_label = _x_fallback if axis == "x" else _y_fallback
|
||||
quality = max(abs(r_lr), abs(r_co), abs(r_pc))
|
||||
|
||||
if abs(r_lr) >= _THRESHOLD:
|
||||
@@ -608,13 +614,14 @@ def classify_axes(
|
||||
|
||||
# ── Final label resolution ────────────────────────────────────────────
|
||||
# If both motion and ideology paths produced nothing, use generic fallback.
|
||||
_x_fallback, _y_fallback = get_fallback_labels()
|
||||
if x_lbl is None:
|
||||
x_lbl = _LABELS["fallback_x"]
|
||||
x_lbl = _x_fallback
|
||||
x_int = _INTERPRETATION_TEMPLATES["fallback"].format(
|
||||
orientation="horizontale"
|
||||
)
|
||||
if y_lbl is None:
|
||||
y_lbl = _LABELS["fallback_y"]
|
||||
y_lbl = _y_fallback
|
||||
y_int = _INTERPRETATION_TEMPLATES["fallback"].format(
|
||||
orientation="verticale"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user