openrig.naming.normalizers module

Normalization functions for token values.

Each public function in this module conforms to the Normalizer signature:

Callable[[object], str]

This means they accept any object (the raw token value before normalization, which may be a str, an Enum, or any other type) and always return a plain str. Empty string signals “no value provided”.

All functions are registered in NORMALIZER_MAP at the bottom of the module, which is the single source of truth consumed by rules.build_normalizers().

Note on the if not value guard:

These functions use if not value: return "" as a fast-exit for falsy inputs. This is intentional: the Manager never passes None to a normalizer (it returns "" before calling them), and a falsy non-None value such as 0 or False is not a valid token value in this system. If that assumption changes, the guard should be replaced with an explicit if value is None: return "".

openrig.naming.normalizers.side(value: object) str[source]

Normalizes a side value to its standard abbreviation.

Maps long-form or mixed-case side strings to their canonical short form (e.g. 'Left''l'). Values not found in the mapping are converted to camelCase as a fallback.

Parameters:

value – The raw side value to normalize.

Returns:

The normalized side string (e.g. 'left''l'), or "" if the value is falsy.

openrig.naming.normalizers.descriptor(value: object) str[source]

Normalizes a descriptor to camelCase.

Converts any casing or separator style to camelCase to avoid conflicts with the naming separator (e.g. 'upper_arm''upperArm').

Parameters:

value – The raw descriptor value to normalize.

Returns:

The camelCase descriptor string, or "" if the value is falsy.

openrig.naming.normalizers.normalize_type(value: object) str[source]

Normalizes a type token to camelCase.

Registered in NORMALIZER_MAP under the key "type". The function is named normalize_type to avoid shadowing the type builtin.

Parameters:

value – The raw type value to normalize.

Returns:

The camelCase type string, or "" if the value is falsy.

openrig.naming.normalizers.pascal_case(value: object) str[source]

Normalizes a token value to PascalCase.

Parameters:

value – The raw value to normalize.

Returns:

The PascalCase string, or "" if the value is falsy.

openrig.naming.normalizers.snake_case(value: object) str[source]

Normalizes a token value to snake_case.

Parameters:

value – The raw value to normalize.

Returns:

The snake_case string, or "" if the value is falsy.

openrig.naming.normalizers.kebab_case(value: object) str[source]

Normalizes a token value to kebab-case.

Parameters:

value – The raw value to normalize.

Returns:

The kebab-case string, or "" if the value is falsy.

openrig.naming.normalizers.clean(value: object) str[source]

Cleans a token value by replacing invalid characters.

Parameters:

value – The raw value to normalize.

Returns:

The cleaned string, or "" if the value is falsy.

openrig.naming.normalizers.version(value: object) str[source]

Normalizes a version number to the vNNN format.

Accepts both raw integers (1'v001') and already-formatted strings ('v3''v003').

Parameters:

value – The raw version value to normalize (int or str).

Returns:

The normalized version string (e.g. 'v001'), or "" if falsy.

openrig.naming.normalizers.upper(value: object) str[source]

Normalizes a token value to uppercase.

Parameters:

value – The raw value to normalize.

Returns:

The uppercase string, or "" if the value is falsy.

openrig.naming.normalizers.lower(value: object) str[source]

Normalizes a token value to lowercase.

Parameters:

value – The raw value to normalize.

Returns:

The lowercase string, or "" if the value is falsy.

openrig.naming.normalizers.capitalize(value: object) str[source]

Normalizes a token value by capitalizing its first letter.

Parameters:

value – The raw value to normalize.

Returns:

The capitalized string, or "" if the value is falsy.

openrig.naming.normalizers.strip_digits(value: object) str[source]

Removes all digit characters from a token value.

Parameters:

value – The raw value to normalize.

Returns:

The string with all digits removed, or "" if the value is falsy.

openrig.naming.normalizers.strip_namespace(value: object) str[source]

Removes the namespace prefix from a token value.

Strips everything up to and including the last : separator.

Parameters:

value – The raw value to normalize (e.g. 'ns:nodeName').

Returns:

The string without its namespace prefix, or "" if the value is falsy.

openrig.naming.normalizers.base_name(value: object) str[source]

Returns the leaf component of a path-like token value.

Splits on | and returns the last segment.

Parameters:

value – The raw value to normalize (e.g. '|group|node').

Returns:

The base name string, or "" if the value is falsy.