MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / canonicalize_weight_mapping

Function canonicalize_weight_mapping

config/direction_lexicon.py:644–664  ·  view source on GitHub ↗
(
    mapping: Optional[Dict[str, Any]],
    *,
    lexicon: Optional[Dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

642
643
644def 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
667def add_direction_alias(canonical_name: str, alias: str) -> bool:

Callers 3

ensure_profile_schemaFunction · 0.85

Calls 4

load_lexiconFunction · 0.85
normalize_direction_keyFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected