(
direction_key: str,
name: str,
name_cn: str,
keywords: Optional[List[str]] = None,
*,
aliases: Optional[List[str]] = None,
paper_terms: Optional[List[str]] = None,
source_text: str = "",
)
| 684 | |
| 685 | |
| 686 | def add_new_direction( |
| 687 | direction_key: str, |
| 688 | name: str, |
| 689 | name_cn: str, |
| 690 | keywords: Optional[List[str]] = None, |
| 691 | *, |
| 692 | aliases: Optional[List[str]] = None, |
| 693 | paper_terms: Optional[List[str]] = None, |
| 694 | source_text: str = "", |
| 695 | ) -> bool: |
| 696 | canonical_name = normalize_direction_key(direction_key) |
| 697 | if not canonical_name: |
| 698 | return False |
| 699 | |
| 700 | lexicon = load_lexicon() |
| 701 | entry = _default_entry( |
| 702 | canonical_name, |
| 703 | name=name or canonical_name.replace("-", " ").title(), |
| 704 | name_cn=name_cn or name or canonical_name.replace("-", " ").title(), |
| 705 | aliases=_dedupe_strings([*(aliases or []), *(keywords or []), source_text]), |
| 706 | paper_terms=_dedupe_strings([*(paper_terms or []), *(keywords or []), source_text]), |
| 707 | ) |
| 708 | if source_text: |
| 709 | entry["source_text"] = source_text |
| 710 | lexicon[canonical_name] = entry |
| 711 | return save_lexicon(lexicon) |
| 712 | |
| 713 | |
| 714 | def _load_pending_store() -> Dict[str, Dict[str, Any]]: |
no test coverage detected