MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _normalize_target

Function _normalize_target

openkb/lint.py:30–47  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

28
29
30def _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
50def build_norm_index(known_targets: set[str]) -> dict[str, str]:

Callers 9

test_lowercasesMethod · 0.90
build_graphFunction · 0.90
build_norm_indexFunction · 0.85
_replFunction · 0.85

Calls

no outgoing calls