- spac.utils.spell_out_special_characters(text)[source]
Convert special characters in a string to comply with NIDAP naming rules.
This function processes a string by replacing or removing disallowed characters to ensure compatibility with NIDAP. Spaces, special symbols, and certain substrings are replaced or transformed into readable and regulation-compliant equivalents.
- Parameters:
text (str) – The input string to be processed and converted.
- Returns:
str – A sanitized string with special characters replaced or removed, adhering to NIDAP naming conventions.
Processing Steps
—————-
Spaces are replaced with underscores (_).
2. Substrings related to units (e.g., ‘µm²’) are replaced with text – equivalents: - ‘µm²’ -> ‘um2’ - ‘µm’ -> ‘um’
Hyphens (-) between letters are replaced with underscores (_).
4. Certain special symbols are mapped to readable equivalents –
+ -> _pos_
- -> _neg_
@ -> at
# -> hash
& -> and
And more (see Notes section for a full mapping).
5. Remaining disallowed characters are removed (non-alphanumeric and – non-underscore characters).
6. Consecutive underscores are consolidated into a single underscore.
7. Leading and trailing underscores are stripped.
Notes
The following special character mappings are used: - µ -> u - ² -> 2 - / -> slash - = -> equals - ! -> exclamation - | -> pipe - For a complete list, refer to the special_char_map in the code.
Example
>>> spell_out_special_characters("Data µm²+Analysis #1-2") 'Data_um2_pos_Analysis_hash1_neg_2'
>>> spell_out_special_characters("Invalid!Char@Format") 'Invalid_exclamation_Char_at_Format'