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

Function format_direction_label

config/direction_lexicon.py:491–518  ·  view source on GitHub ↗

Return a stable user-facing label for a canonical direction key or alias.

(
    direction_key: Any,
    *,
    lexicon: Optional[Dict[str, Any]] = None,
    prefer_chinese: bool = True,
)

Source from the content-addressed store, hash-verified

489
490
491def format_direction_label(
492 direction_key: Any,
493 *,
494 lexicon: Optional[Dict[str, Any]] = None,
495 prefer_chinese: bool = True,
496) -> str:
497 """Return a stable user-facing label for a canonical direction key or alias."""
498 cleaned = str(direction_key or "").strip()
499 if not cleaned:
500 return ""
501
502 entry = get_direction_entry(cleaned, lexicon=lexicon) or {}
503 if not entry:
504 resolved = resolve_canonical_direction(cleaned, lexicon=lexicon, include_paper_terms=True)
505 if resolved:
506 entry = resolved.get("entry") or get_direction_entry(resolved["canonical_name"], lexicon=lexicon) or {}
507
508 if entry:
509 if prefer_chinese:
510 label = str(entry.get("name_cn") or entry.get("name") or cleaned).strip()
511 else:
512 label = str(entry.get("name") or entry.get("name_cn") or cleaned).strip()
513 if label:
514 return label
515
516 if any("\u4e00" <= ch <= "\u9fff" for ch in cleaned):
517 return cleaned
518 return cleaned.replace("-", " ").replace("_", " ").title()
519
520
521def build_bootstrap_summary(

Callers 3

build_bootstrap_summaryFunction · 0.70
format_drift_hintFunction · 0.50

Calls 3

get_direction_entryFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected