Official Codebase of 3DCodeVerse
Python
texturing: material keyword words split acronyms with to_snake — a node called PVCPipe finds "pvc"
gaoypengac5341a6fd33
diff --git a/harness/codeverse3d/texturing/materials.py b/harness/codeverse3d/texturing/materials.pyindex 5522c64c..2de23895 100644--- a/harness/codeverse3d/texturing/materials.py+++ b/harness/codeverse3d/texturing/materials.py@@ -33,6 +33,8 @@ from typing import NamedTuplefrom pydantic import BaseModel, Field+from codeverse3d.conventions import to_snake+#: glTF/Blender/three framework defaults. A material sitting exactly on one of#: these pairs was never authored — see ``is_framework_default``.FRAMEWORK_DEFAULTS: tuple[tuple[float, float], ...] = (@@ -216,25 +218,11 @@ class FamilyMatch(NamedTuple):def _tokens(text: str) -> set[str]:- """Whole words of ``text``, splitting snake_case, kebab-case AND CamelCase."""+ """Whole words of ``text`` as :func:`~codeverse3d.conventions.to_snake` splits them+ (snake_case, kebab-case, CamelCase and acronyms: ``PVCPipe`` → ``pvc``, ``pipe``),+ plus the words joined (``pvcpipe``)."""s = str(text or "")- parts: list[str] = []- cur: list[str] = []- prev_lower = False- for ch in s:- if ch.isalnum():- if ch.isupper() and prev_lower and cur:- parts.append("".join(cur))- cur = []- cur.append(ch.lower())- prev_lower = ch.islower() or ch.isdigit()- else:- if cur:- parts.append("".join(cur))- cur = []- prev_lower = False- if cur:- parts.append("".join(cur))+ parts = [w for w in to_snake(s).split("_") if w] if any(c.isascii() and c.isalnum() for c in s) else []joined = "".join(parts)return {*parts, joined} if joined else set(parts)diff --git a/harness/tests/core/test_names.py b/harness/tests/core/test_names.pyindex b72afce2..1ef03b3e 100644--- a/harness/tests/core/test_names.py+++ b/harness/tests/core/test_names.py@@ -16,6 +16,7 @@ from codeverse3d.conventions import PASCAL_RE, to_pascal, to_snakefrom codeverse3d.languages.blender import lint_blender_sourcefrom codeverse3d.languages.cadquery import lint_cadquery_sourcefrom codeverse3d.languages.urdf import _IDENT as URDF_LINK_RE+from codeverse3d.texturing.materials import family_forfrom codeverse3d.tracks.planner import normalise_names, plan_exampleWRAPPERS = Path(__file__).resolve().parents[2] / "codeverse3d" / "languages" / "wrappers"@@ -103,3 +104,7 @@ def test_the_part_name_lints_accept_acronyms():assert any("named objects" in f.message and "USBPort" in f.message for f in rep.findings)assert all(URDF_LINK_RE.match(n) for n in ("TVStand", "LED", "CPU_2", "A"))++def test_material_words_split_acronyms():+ hit = family_for("PVCPipe")+ assert hit is not None and hit == family_for("pvc pipe")