Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Merge PR #1417: deduplicate ask_user options

Bingxi Zhao (Frank)33b74abdbcf0
diff --cc deeptutor/tools/ask_user.py
index 27e1716b5,e554d21b4..05276a72e
--- a/deeptutor/tools/ask_user.py
+++ b/deeptutor/tools/ask_user.py
@@@ -268,22 -271,15 +272,26 @@@ def _build_question(raw: Any, idx: int
continue
# The card auto-renders an "Other" free-text row; drop a
# model-supplied duplicate so the user never sees two.
- if allow_free_text and normalised.label.lower() in _REDUNDANT_OTHER_LABELS:
+ match_key = _option_match_key(normalised.label)
+ if allow_free_text and match_key in _REDUNDANT_OTHER_LABELS:
continue
- if normalised.label in seen_labels:
+ # Two labels that differ only by whitespace or case render as the
+ # same choice, so keep the first rather than shipping an
+ # unanswerable card (#1409).
+ if match_key in seen_labels:
continue
- seen_labels.add(normalised.label)
+ # Two options whose visible text matches once whitespace and case
+ # are folded leave the learner nothing to pick between — the same
+ # duplicate-body rule the mastery quiz contract enforces at
+ # registration (#1409). An option with no body *is* its label, so
+ # label-only cards are governed by label uniqueness alone.
+ body = (normalised.description or "").strip()
+ if body:
+ body_key = " ".join(body.split()).casefold()
+ if body_key in seen_bodies:
+ continue
+ seen_bodies.add(body_key)
+ seen_labels.add(match_key)
cleaned.append(normalised)
if len(cleaned) >= MAX_OPTIONS:
break