UniHive_RecSys / engine_3_0 /training_scripts /make_interest_taxonomy_ts.py
Tirthanker's picture
Add engine 3.0 (BGE-384) work in progress with open-issues list
6b1bc4b verified
Raw History Blame Contribute Delete
1.66 kB
"""Generate src/interestTaxonomy.ts (data only) for the UniHive frontend: the recommender's 13 interest categories and 114 interests.
`slug` and `label` are exactly what migration 012 seeds into `domains`, and what POST /api/users/profile resolves (it matches interest strings against
domains.name or domains.slug, case-insensitively), so the onboarding screen can send either. Usage: python make_interest_taxonomy_ts.py <taxonomy.py> <out.ts>"""
import importlib.util, json, sys
src, out = sys.argv[1], sys.argv[2]
spec = importlib.util.spec_from_file_location("taxonomy", src); tx = importlib.util.module_from_spec(spec); spec.loader.exec_module(tx)
cats = [{"slug": tx.slugify(n), "label": n, "description": d, "interests": [{"slug": tx.slugify(c), "label": c} for c in kids]} for b, n, d, kids in tx.TAXONOMY]
assert len(cats) == 13 and sum(len(c["interests"]) for c in cats) == 114
ts = ("// Generated from the recommender's taxonomy (backend/migrations/012_domains_catalogue.sql seeds the same rows into `domains`).\n"
"// Send either `slug` or `label` to POST /api/users/profile as an interest; the backend resolves it against domains.slug / domains.name.\n"
"export interface InterestItem { slug: string; label: string }\n"
"export interface InterestCategory { slug: string; label: string; description: string; interests: InterestItem[] }\n\n"
f"export const INTEREST_TAXONOMY: InterestCategory[] = {json.dumps(cats, indent=2, ensure_ascii=False)}\n")
open(out, "w", encoding="utf8", newline="\n").write(ts); print("written", out, "|", len(cats), "categories,", sum(len(c["interests"]) for c in cats), "interests")