Upload text_utils.py with huggingface_hub
Browse files11 unmodified lines12131415161718192021222336 unmodified lines6061626364656667686955 unmodified lines12512612712811 unmodified lineslist: The list of words obtained after splitting the string."""# Split PascalCase or camelCases = re.sub("([A-Z][a-z]+)", r" \1", re.sub("([A-Z]+)", r" \1", s)).strip()# Split snake_case or kebab-cases = re.sub("[_-]", " ", s)# Split numbers attached to stringss = re.sub("([a-zA-Z])(\d)", r"\1 \2", s)s = re.sub("(\d)([a-zA-Z])", r"\1 \2", s)# Split the string into words based on spaceswords = s.split()return words36 unmodified linesstr: The string converted to snake_case."""# Add an underscore before every uppercase letter that is followed by a lowercase letter or digit and not preceded by an underscore, a hyphen or an uppercase letters = re.sub("(?<=[^A-Z_-])([A-Z])", r"_\1", s)# Ensure there's an underscore before any uppercase letter that's followed by a lowercase letter or digit and comes after a sequence of uppercase letterss = re.sub("([A-Z]+)([A-Z][a-z0-9])", r"\1_\2", s)s = s.lower()return s55 unmodified linesresult.append(nested_tuple_to_string(item))else:result.append(str(item))return "_".join(result)11 unmodified lines12131415161718192021222336 unmodified lines6061626364656667686955 unmodified lines12512612712811 unmodified lineslist: The list of words obtained after splitting the string."""# Split PascalCase or camelCases = re.sub(r"([A-Z][a-z]+)", r" \1", re.sub(r"([A-Z]+)", r" \1", s)).strip()# Split snake_case or kebab-cases = re.sub(r"[_-]", " ", s)# Split numbers attached to stringss = re.sub(r"([a-zA-Z])(\d)", r"\1 \2", s)s = re.sub(r"(\d)([a-zA-Z])", r"\1 \2", s)# Split the string into words based on spaceswords = s.split()return words36 unmodified linesstr: The string converted to snake_case."""# Add an underscore before every uppercase letter that is followed by a lowercase letter or digit and not preceded by an underscore, a hyphen or an uppercase letters = re.sub(r"(?<=[^A-Z_-])([A-Z])", r"_\1", s)# Ensure there's an underscore before any uppercase letter that's followed by a lowercase letter or digit and comes after a sequence of uppercase letterss = re.sub(r"([A-Z]+)([A-Z][a-z0-9])", r"\1_\2", s)s = s.lower()return s55 unmodified linesresult.append(nested_tuple_to_string(item))else:result.append(str(item))return "_".join(result)
text_utils.py+7-7