unitxt.text_utils module¶
- unitxt.text_utils.camel_to_snake_case(s)[source]¶
Converts a string from camelCase to snake_case.
- Parameters:
s (str) – The string to be converted.
- Returns:
The string converted to snake_case.
- Return type:
str
- unitxt.text_utils.construct_dict_as_yaml_lines(d, indent_delta=2) List[str][source]¶
Constructs the lines of a dictionary formatted as yaml.
- Parameters:
d – The element to be formatted.
indent_delta (int, optional) – The amount of spaces to add for each level of indentation. Defaults to 2.
- unitxt.text_utils.construct_dict_str(d, indent=0, indent_delta=4, max_chars=None, keys=None)[source]¶
Constructs a formatted string of a dictionary.
- Parameters:
d (dict) – The dictionary to be formatted.
indent (int, optional) – The current level of indentation. Defaults to 0.
indent_delta (int, optional) – The amount of spaces to add for each level of indentation. Defaults to 4.
max_chars (int, optional) – The maximum number of characters for each line. Defaults to terminal width - 10.
keys (List[Str], optional) – the list of fields to print
- unitxt.text_utils.is_camel_case(s)[source]¶
Checks if a string is in camelCase.
- Parameters:
s (str) – The string to be checked.
- Returns:
True if the string is in camelCase, False otherwise.
- Return type:
bool
- unitxt.text_utils.is_snake_case(s)[source]¶
Checks if a string is in snake_case.
- Parameters:
s (str) – The string to be checked.
- Returns:
True if the string is in snake_case, False otherwise.
- Return type:
bool
- unitxt.text_utils.lines_defining_obj_in_card(all_lines: List[str], obj_name: str, start_search_at_line: int = 0) Tuple[int, int][source]¶
- unitxt.text_utils.nested_tuple_to_string(nested_tuple: tuple) str[source]¶
Converts a nested tuple to a string, with elements separated by underscores.
- Parameters:
nested_tuple (tuple) – The nested tuple to be converted.
- Returns:
The string representation of the nested tuple.
- Return type:
str