(
mapping: Optional[Dict[str, Any]],
*,
lexicon: Optional[Dict[str, Any]] = None,
)
| 642 | |
| 643 | |
| 644 | def canonicalize_weight_mapping( |
| 645 | mapping: Optional[Dict[str, Any]], |
| 646 | *, |
| 647 | lexicon: Optional[Dict[str, Any]] = None, |
| 648 | ) -> Dict[str, float]: |
| 649 | current_lexicon = lexicon or load_lexicon() |
| 650 | canonicalized: Dict[str, float] = {} |
| 651 | for key, value in (mapping or {}).items(): |
| 652 | try: |
| 653 | numeric_value = float(value) |
| 654 | except (TypeError, ValueError): |
| 655 | continue |
| 656 | cleaned = str(key or "").strip() |
| 657 | if not cleaned: |
| 658 | continue |
| 659 | resolved = resolve_canonical_direction(cleaned, lexicon=current_lexicon, include_paper_terms=True) |
| 660 | canonical_name = resolved["canonical_name"] if resolved else normalize_direction_key(cleaned) |
| 661 | if not canonical_name: |
| 662 | continue |
| 663 | canonicalized[canonical_name] = max(float(canonicalized.get(canonical_name, 0.0)), numeric_value) |
| 664 | return canonicalized |
| 665 | |
| 666 | |
| 667 | def add_direction_alias(canonical_name: str, alias: str) -> bool: |
no test coverage detected