<commit_before>DELIMITER = '-'

def concat_paths(name, parent_names):
    return DELIMITER.join(
        [*parent_names, name]
    )

def concat_xpath(name, parent_names):
    return '/'.join(
        [*parent_names, name]
    )

def get_name(row):
    return row.get('name',
        row.get('$autoname')
    )

def insert_full_paths_in_place(content):
    '''
    insert an absolute path to each question based on parent
    groups

    the delimiter is set in the DELIMITER variable
    '''
    hierarchy = []
    for row in content.get('survey', []):
        if row.get('type') == 'end_group':
            hierarchy.pop()
        else:
            rowname = get_name(row)
            row['$qpath'] = concat_paths(rowname, hierarchy)
            row['$xpath'] = concat_xpath(rowname, hierarchy)
            if row.get('type') == 'begin_group':
                hierarchy.append(get_name(row))<commit_msg>qpath related tests should pass<commit_after>DELIMITER = '-'
pairers = ['score', 'group', 'repeat']
BEGINNERS = map(lambda ss: f'begin_{ss}', pairers)
ENDERS = map(lambda ss: f'end_{ss}', pairers)


def concat_paths(name, parent_names):
    return DELIMITER.join(
        [*parent_names, name]
    )

def concat_xpath(name, parent_names):
    return '/'.join(
        [*parent_names, name]
    )

def get_name(row):
    return row.get('name',
        row.get('$autoname')
    )

def insert_full_paths_in_place(content):
    '''
    insert an absolute path to each question based on parent
    groups

    the delimiter is set in the DELIMITER variable
    '''
    hierarchy = []
    for row in content.get('survey', []):
        if row.get('type') in ENDERS:
            hierarchy.pop()
        else:
            rowname = get_name(row)
            # if rowname is not None:
            row['$qpath'] = concat_paths(rowname, hierarchy)
            row['$xpath'] = concat_xpath(rowname, hierarchy)
            if row.get('type') in BEGINNERS:
                hierarchy.append(get_name(row))
{'fraction_non_alphanumeric': 0.12988966900702106, 'fraction_numerical': 0.0, 'mean_word_length': 2.5435168738898755, 'pattern_counts': {'":': 0, '<': 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': '3072693', 'n_tokens_mistral': 648, 'n_tokens_neox': 651, 'n_words': 150}