Skip to content

Instantly share code, notes, and snippets.

@kingspp
Created October 24, 2018 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingspp/78e8d2de92b3e3baf51772b31ea86bdd to your computer and use it in GitHub Desktop.
Save kingspp/78e8d2de92b3e3baf51772b31ea86bdd to your computer and use it in GitHub Desktop.
import re
def generate_label_from_name(name: str):
"""
:param name: Name for which label has to be generate
:return:
"""
caps_split = sum([list(match) for match in re.findall('([A-Z][^A-Z][a-z]*)|([0-9][A-Z][^A-Z][a-z]*)|([0-9][A-Z][a-z]*)', name)], [])
print(caps_split)
# exit()
if "." in name:
return name.split('.')[-1].title()
elif '_' in name:
return ' '.join(name.split('_')).title()
elif ' ' not in name and len(caps_split) > 1:
return ' '.join([cap for cap in caps_split if cap!=''])
else:
return name.title()
name = 'Convolution3DLayer'
print(generate_label_from_name(name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment