Normalize a wikilink target for fuzzy comparison. Applies, in order: - NFKC unicode normalization (e.g. full-width ')' → ASCII ')') - Lowercase - Underscore → hyphen - Collapse repeated hyphens - Strip leading/trailing hyphens (per segment when path-like) Path separator
(target: str)
| 28 | |
| 29 | |
| 30 | def _normalize_target(target: str) -> str: |
| 31 | """Normalize a wikilink target for fuzzy comparison. |
| 32 | |
| 33 | Applies, in order: |
| 34 | - NFKC unicode normalization (e.g. full-width ')' → ASCII ')') |
| 35 | - Lowercase |
| 36 | - Underscore → hyphen |
| 37 | - Collapse repeated hyphens |
| 38 | - Strip leading/trailing hyphens (per segment when path-like) |
| 39 | |
| 40 | Path separators are preserved so ``concepts/Gist_Memory`` normalizes to |
| 41 | ``concepts/gist-memory``. |
| 42 | """ |
| 43 | s = unicodedata.normalize("NFKC", target) |
| 44 | s = s.lower().replace("_", "-") |
| 45 | # Normalize each path segment independently to avoid collapsing the '/' |
| 46 | parts = [re.sub(r"-+", "-", p).strip("-") for p in s.split("/")] |
| 47 | return "/".join(parts) |
| 48 | |
| 49 | |
| 50 | def build_norm_index(known_targets: set[str]) -> dict[str, str]: |
no outgoing calls