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

Function _normalize_direction_weight_map

agents/coldstart-agent/main.py:189–220  ·  view source on GitHub ↗

Collapse duplicate direction aliases into canonical keys while preserving unknown topics.

(raw_weights: Any)

Source from the content-addressed store, hash-verified

187
188 return normalized
189
190
191def _normalize_direction_weight_map(raw_weights: Any) -> Dict[str, float]:
192 """Collapse duplicate direction aliases into canonical keys while preserving unknown topics."""
193 if not isinstance(raw_weights, dict):
194 return {}
195
196 try:
197 direction_lexicon = importlib.import_module("config.direction_lexicon")
198 resolve_canonical_direction = getattr(direction_lexicon, "resolve_canonical_direction", None)
199 except Exception:
200 resolve_canonical_direction = None
201
202 normalized: Dict[str, float] = {}
203 for raw_key, raw_weight in raw_weights.items():
204 key_text = _collapse_whitespace(raw_key)
205 if not key_text:
206 continue
207 try:
208 weight = round(float(raw_weight or 0.0), 4)
209 except (TypeError, ValueError):
210 continue
211
212 canonical_key = key_text
213 if callable(resolve_canonical_direction):
214 try:
215 resolved = resolve_canonical_direction(key_text, include_paper_terms=True)
216 except Exception:
217 resolved = None
218 canonical_key = str((resolved or {}).get("canonical_name") or key_text).strip() or key_text
219
220 normalized[canonical_key] = round(max(float(normalized.get(canonical_key, 0.0)), weight), 4)
221
222 return normalized
223

Callers 1

ensure_profile_shapeFunction · 0.85

Calls 3

_collapse_whitespaceFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected