Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion graphify/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ def build(
return build_from_json(combined, directed=directed, root=root)


def _norm_label(label: str) -> str:
def _norm_label(label: str | None) -> str:
"""Canonical dedup key — Unicode-aware, preserves CJK/word characters."""
if not isinstance(label, str):
label = "" if label is None else str(label)
label = unicodedata.normalize("NFKC", label)
return re.sub(r"[\W_ ]+", " ", label.casefold(), flags=re.UNICODE).strip()

Expand Down
4 changes: 3 additions & 1 deletion graphify/dedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

# ── helpers ───────────────────────────────────────────────────────────────────

def _norm(label: str) -> str:
def _norm(label: str | None) -> str:
"""Lowercase + collapse non-alphanumeric runs to space (Unicode-aware)."""
if not isinstance(label, str):
label = "" if label is None else str(label)
label = unicodedata.normalize("NFKC", label)
return re.sub(r"[\W_]+", " ", label.casefold(), flags=re.UNICODE).strip()

Expand Down
4 changes: 3 additions & 1 deletion graphify/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def _obsidian_tag(name: str) -> str:
return re.sub(r"[^a-zA-Z0-9_\-/]", "", name.replace(" ", "_"))


def _strip_diacritics(text: str) -> str:
def _strip_diacritics(text: str | None) -> str:
import unicodedata
if not isinstance(text, str):
text = "" if text is None else str(text)
nfkd = unicodedata.normalize("NFKD", text)
return "".join(c for c in nfkd if not unicodedata.combining(c))

Expand Down
4 changes: 3 additions & 1 deletion graphify/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def _communities_from_graph(G: nx.Graph) -> dict[int, list[str]]:
return communities


def _strip_diacritics(text: str) -> str:
def _strip_diacritics(text: str | None) -> str:
import unicodedata
if not isinstance(text, str):
text = "" if text is None else str(text)
nfkd = unicodedata.normalize("NFKD", text)
return "".join(c for c in nfkd if not unicodedata.combining(c))

Expand Down