Skip to content

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.py
index 5522c64c..2de23895 100644
--- a/harness/codeverse3d/texturing/materials.py
+++ b/harness/codeverse3d/texturing/materials.py
@@ -33,6 +33,8 @@ from typing import NamedTuple
from 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.py
index 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_snake
from codeverse3d.languages.blender import lint_blender_source
from codeverse3d.languages.cadquery import lint_cadquery_source
from codeverse3d.languages.urdf import _IDENT as URDF_LINK_RE
+from codeverse3d.texturing.materials import family_for
from codeverse3d.tracks.planner import normalise_names, plan_example
WRAPPERS = 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")