Map user-facing topic aliases onto a stable internal key when known.
(topic_text: str)
| 428 | |
| 429 | |
| 430 | def resolve_canonical_topic_key(topic_text: str) -> Optional[str]: |
| 431 | """Map user-facing topic aliases onto a stable internal key when known.""" |
| 432 | resolved = resolve_canonical_direction(topic_text, include_paper_terms=True) |
| 433 | if resolved: |
| 434 | return str(resolved.get("canonical_name")) |
| 435 | |
| 436 | target = normalize_topic_token(topic_text) |
| 437 | if not target: |
| 438 | return None |
| 439 | |
| 440 | for topic_key in DIRECTION_TRANSLATIONS.keys(): |
| 441 | alias_tokens = { |
| 442 | normalize_topic_token(alias) |
| 443 | for alias in get_canonical_topic_aliases(topic_key) |
| 444 | if normalize_topic_token(alias) |
| 445 | } |
| 446 | if target in alias_tokens: |
| 447 | return topic_key |
| 448 | |
| 449 | return None |
| 450 | |
| 451 | |
| 452 | SEMANTIC_TOPIC_FAMILIES = { |
no test coverage detected