<commit_before>"""Module used for converting Verto heading tree data.

The Verto result object is a tuple containing NamedTuples, however this
must be converted to a dictionary to be stored in a HStoreField Postgres
database field.
"""


def convert_heading_tree_to_dict(heading_tree_tuples):
    """Convert tuple heading tree to dictionary.

    Args:
        heading_tree_tuples: The heading tree from a Verto conversion.

    Returns:
        Dictionary of heading tree, or None if None provided as tree.
    """
    if heading_tree_tuples is None:
        return None
    else:
        root_nodes = []
        for heading_node in heading_tree_tuples:
            root_nodes.append(convert_heading_node(heading_node))
        return root_nodes


def convert_heading_node(heading_node):
    """Convert a heading node to a dictionary.

    Args:
        heading_node: A tuple for a heading node.

    Returns:
        A dictionary of data for a heading node.
    """
    children = []
    for child in heading_node.children:
        children.append(convert_heading_node(child))
    heading_node_data = {
        "text": heading_node.title,
        "slug": heading_node.title_slug,
        "level": heading_node.level,
        "children": children,
    }
    return heading_node_data<commit_msg>Alter conversion function name<commit_after>"""Module used for converting Verto heading tree data.

The Verto result object is a tuple containing NamedTuples, however this
must be converted to a dictionary to be stored in a HStoreField Postgres
database field.
"""


def convert_heading_tree_to_dict(heading_tree_tuples):
    """Convert tuple heading tree to dictionary.

    Args:
        heading_tree_tuples: The heading tree from a Verto conversion.

    Returns:
        Dictionary of heading tree, or None if None provided as tree.
    """
    return [convert_heading_node_to_dict(heading_node) for heading_node in heading_tree_tuples]


def convert_heading_node_to_dict(heading_node):
    """Convert a heading node to a dictionary.

    Args:
        heading_node: A tuple for a heading node.

    Returns:
        A dictionary of data for a heading node.
    """
    children = []
    for child in heading_node.children:
        children.append(convert_heading_node_to_dict(child))
    heading_node_data = {
        "text": heading_node.title,
        "slug": heading_node.title_slug,
        "level": heading_node.level,
        "children": children,
    }
    return heading_node_data
{'fraction_non_alphanumeric': 0.06631832797427653, 'fraction_numerical': 0.0, 'mean_word_length': 3.1345514950166113, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '408441', 'n_tokens_mistral': 694, 'n_tokens_neox': 681, 'n_words': 235}