Skip to content

string_utils

camel_to_snake(text)

Converts camel-case string to snake-case

Parameters:

Name Type Description Default
text str

string to convert

required

Returns:

Name Type Description
str str

converted string

Source code in exe_kg_lib/utils/string_utils.py
 7
 8
 9
10
11
12
13
14
15
16
17
def camel_to_snake(text: str) -> str:
    """
    Converts camel-case string to snake-case
    Args:
        text: string to convert

    Returns:
        str: converted string
    """
    text = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text)
    return re.sub("([a-z0-9])([A-Z])", r"\1_\2", text).lower()

property_name_to_field_name(property_name)

Extracts property name from IRI and converts it to snake-case

Parameters:

Name Type Description Default
property_name str

IRI to parse

required

Returns:

Name Type Description
str str

converted string

Source code in exe_kg_lib/utils/string_utils.py
20
21
22
23
24
25
26
27
28
29
def property_name_to_field_name(property_name: str) -> str:
    """
    Extracts property name from IRI and converts it to snake-case
    Args:
        property_name: IRI to parse

    Returns:
        str: converted string
    """
    return camel_to_snake(property_name.split("#")[1])

Last update: October 20, 2023