Skip to content

Commit 016a797

Browse files
fix: major classification uses word-level matching, not substring
'stat' no longer matches 'state', 'cs' no longer matches 'statistics'. Both _classify_major (contribute) and _profile_adjustment (prediction) now match against individual majors using word splitting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ba517e2 commit 016a797

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

cli/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,22 @@ def _classify_major(majors: list) -> str:
330330
"""Map majors to anonymous category."""
331331
if not majors:
332332
return "Unknown"
333-
combined = " " + " ".join(majors).lower() + " "
334-
quant_kw = ["math", "stat", "physics", "computer"]
335-
n_quant = sum(1 for kw in quant_kw if kw in combined)
333+
_QUANT = [
334+
"math", "mathematics", "applied math",
335+
"statistics", "stats", "stat",
336+
"physics",
337+
"computer science", "computer", "computing", "cs",
338+
]
339+
_ECON = ["econ", "economics", "finance", "financial"]
340+
n_quant = sum(
341+
1 for m in majors
342+
if any(kw == m.lower() or kw in m.lower().split() for kw in _QUANT)
343+
)
336344
if n_quant >= 2:
337345
return "Multi-quant (math/stats/CS)"
338346
if n_quant >= 1:
339347
return "Quant-related"
340-
if any(kw in combined for kw in ["econ", "finance"]):
348+
if any(any(kw in m.lower() for kw in _ECON) for m in majors):
341349
return "Econ/Finance"
342350
return "Other"
343351

core/lr_predictor.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,25 @@ def _profile_adjustment(profile: "UserProfile") -> float:
231231
# --- Major relevance (+0 to +0.15) ---
232232
majors = getattr(profile, "majors", [])
233233
if majors:
234-
major_lower = " ".join(majors).lower()
235-
quant_kw = ["math", "stat", "physics", "computer", "cs"]
236-
n_quant = sum(1 for kw in quant_kw if kw in major_lower)
234+
_QUANT_MAJORS = [
235+
"math", "mathematics", "applied math",
236+
"statistics", "stats", "stat",
237+
"physics",
238+
"computer science", "computer", "computing", "cs",
239+
]
240+
_ECON_MAJORS = ["econ", "economics", "finance", "financial"]
241+
n_quant = sum(
242+
1 for m in majors
243+
if any(kw == m.lower() or kw in m.lower().split() for kw in _QUANT_MAJORS)
244+
)
237245
if n_quant >= 2:
238246
adj += 0.15
239247
elif n_quant >= 1:
240248
adj += 0.08
241-
elif any(kw in major_lower for kw in ["econ", "finance"]):
249+
elif any(
250+
any(kw in m.lower() for kw in _ECON_MAJORS)
251+
for m in majors
252+
):
242253
adj += 0.05
243254

244255
return adj

0 commit comments

Comments
 (0)