nomenclate.core.nameparser module¶
This module does name parsing to recover information about the name based on common conventions. it will be very prone to missing information since names will be very variable, but hopefully it will be more intelligent as time goes on
- class nomenclate.core.nameparser.NameParser[source]
Bases:
object
This parses names of assets. It assumes the usual convention of strings separated by underscores.
- CONFIG_DISCIPLINES = ['animation', 'compositing', 'lighting', 'matchmove', 'modeling', 'rigging']
- CONFIG_SIDES = ['center', 'left', 'right']
- PARSABLE = ['basename', 'version', 'date', 'side', 'udim']
- REGEX_ABBR_CAMEL = '(?:[a-z])({ABBR})(?:$|[A-Z]|{SEP})'
- REGEX_ABBR_ISLAND = '(?:[{SEP}]+)({ABBR})(?:[{SEP}]+)'
- REGEX_ABBR_SEOS = '(?:^|[a-z]|{SEP})({ABBR})(?:$|[A-Z][a-z]+|{SEP})'
- REGEX_BASENAME = '(?:^[-._]+)?([a-zA-Z0-9_\\-|]+?)(?=[-._]{2,}|\\.)'
- REGEX_CAMEL = '(?:{SEP}?)((?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z]))(?:{SEP}?)'
- REGEX_DATE = '(?<!\\d)(%s)(?!\\d)'
- REGEX_SEPARATORS = '[ ,_!?:\\.\\-]'
- REGEX_UDIM = '(?:[a-zA-Z]|[._-])(1[0-9]{3})(?:[._-])'
- REGEX_VERSION = '(?:^|[a-z]{{2,}}[a-uw-z]+|{SEP}[a-z]?[a-uw-z]+|{SEP})([vV]?[0-9]{{1,4}})(?={SEP}|$)'
- classmethod get_base(name)[source]
- Checks a string for a possible base name of an object (no prefix, no suffix).
We need to do a full parse to make sure we’ve ruled out all the possible other parse queries
- Parameters
name – str, string that represents a possible name of an object
- Returns
str, the detected basename
- classmethod get_base_naive(name, ignore='')[source]
- Checks a string for a possible base name of an object (no prefix, no suffix).
We need to do a full parse to make sure we’ve ruled out all the possible other parse queries
- Parameters
name – str, string that represents a possible name of an object
- Returns
str, the detected basename
- classmethod get_date(name)[source]
- Checks a string for a possible date formatted into the name. It assumes dates do not have other
numbers at the front or head of the date. Currently only supports dates in 1900 and 2000. Heavily relies on datetime for error checking to see if date is actually viable. It follows similar ideas to this post: http://stackoverflow.com/questions/9978534/match-dates-using-python-regular-expressions
- Parameters
name – str, string that represents a possible name of an object
- Returns
datetime.datetime, datetime object with current time or None if not found
- classmethod get_discipline(name, ignore='', min_length=3)[source]
- Checks a string for a possible discipline string token, this assumes its on its own
and is not part of or camel cased and combined with a word. Returns first found match to reduce duplicates. We can be safe to assume the abbreviation for the discipline does not have camel casing within its own word.
- Parameters
name – str, the string based object name
ignore – str, specific ignore string for the search to avoid
min_length – int, minimum length for possible abbreviations of disciplines. Lower = more wrong guesses.
- Returns
dict, match dictionary
- classmethod get_short(name)[source]
Returns the short name of a Maya asset name or path
- Parameters
name – str, string that represents a possible name of an object
- Returns
str, the short name of the maya node
- classmethod get_side(name, ignore='')[source]
- Checks a string for a possible side string token, this assumes its on its own
and is not part of or camel cased and combined with a word. Returns first found side to reduce duplicates. We can be safe to assume the abbreviation for the side does not have camel casing within its own word.
- Parameters
name – str, string that represents a possible name of an object
name – str, string that represents a possible name of an object
- Returns
(None, str), either the found permutation of the side found in name or None
- classmethod get_string_camel_patterns(name, min_length=0)[source]
Finds all permutations of possible camel casing of the given name
- Parameters
name – str, the name we need to get all possible permutations and abbreviations for
min_length – int, minimum length we want for abbreviations
- Returns
list(list(str)), list casing permutations of list of abbreviations
- classmethod get_udim(name)[source]
Checks a string for a possible base name of an object (no prefix, no suffix)
- Parameters
name – str, string that represents a possible name of an object
- Returns
int, the last found match because convention keeps UDIM markers at the end.
- classmethod get_version(name)[source]
- Checks a string for a possible version of an object (no prefix, no suffix).
Assumes only up to 4 digit padding
- Parameters
name – str, string that represents a possible name of an object
- Returns
(float, int, list(str), None), gets the version number then the string matches
- classmethod get_version_naive(name, ignore='')[source]
- Checks a string for a possible version of an object (no prefix, no suffix) without filtering date out
Assumes only up to 4 digit padding
- Parameters
name – str, string that represents a possible name of an object
- Returns
(float, int, list(str), None), gets the version number then the string matches
- classmethod is_valid_camel(input_string, strcmp=None, ignore='')[source]
- Checks to see if an input string is valid for use in camel casing
This assumes that all lowercase strings are not valid camel case situations and no camel string can just be a capitalized word. Took ideas from here: http://stackoverflow.com/questions/29916065/how-to-do-camelcase-split-in-python
- Parameters
input_string – str, input word
strcmp – str, force detection on a substring just in case its undetectable (e.g. part of a section of text that’s all lowercase)
ignore – str, what kind of string to ignore in the regex search
- Returns
bool, whether it is valid or not
- classmethod parse_name(name)[source]
- Parses a name into a dictionary of identified subsections with accompanying information to
correctly identify and replace if necessary
- Parameters
name – str, string to be parsed
- Returns
dict, dictionary with relevant parsed information