<commit_before>import os
import yaml

def load_config(config_filename):
    '''Load configuration from yaml file.'''
    if not os.path.exists(config_filename):
        raise Exception('Error: configuration file %s does not exist!'
                        % config_filename)
    return yaml.load(open(config_filename).read())


def check_config(config):
    yaml_keys = [
        'COORDINATE_FROM_FILENAME',
        'COORDINATES_IN_FILENAME_ONE_BASED',
        'SHIFT_DESCRIPTOR_FILE_LOCATION',
        'CYCLE_SUBDIRECTORY_NAME_FORMAT',
        'CYCLE_NR_FROM_FILENAME',
        'EXPERIMENT_NAME_FROM_FILENAME',
        'IMAGE_FOLDER_LOCATION',
        'SEGMENTATION_FOLDER_LOCATION',
        'SHIFT_FOLDER_LOCATION',
        'STATS_FOLDER_LOCATION',
        'STATS_FILE_FORMAT',
        'CHANNEL_NR_FROM_FILENAME',
        'MEASUREMENT_FOLDER_LOCATION',
        'CELL_ID_FORMAT'
    ]
    for key in yaml_keys:
        if key not in config:
            print('Error: configuration file must contain the key "%s"' % key)
<commit_msg>Adapt to changes in configuration file<commit_after>import yaml
from os.path import exists
import re

"""
Utility functions for filename and path routines.
"""


def regex_from_format_string(format_string):
    '''
    Convert a format string of the sort
    '{name}_bla/something_{number}'
    to a named regular expression.
    '''
    # Extract the names of all placeholders from the format string
    placeholders_inner_parts = re.findall(r'{(.+?)}', format_string)
    # Remove format strings
    placeholder_names = [pl.split(':')[0] for pl in placeholders_inner_parts]
    placeholder_regexes = [re.escape('{%s}') % pl
                           for pl in placeholders_inner_parts]

    regex = format_string
    for pl_name, pl_regex in zip(placeholder_names, placeholder_regexes):
        if re.search(r'number', pl_name):
            regex = re.sub(pl_regex, '(?P<%s>\d+)' % pl_name, regex)
        else:
            regex = re.sub(pl_regex, '(?P<%s>.*)' % pl_name, regex)

    return regex


def load_config(cfg_filename):
    '''Load configuration from yaml file.'''
    if not exists(cfg_filename):
        raise Exception('Error: configuration file %s does not exist!'
                        % cfg_filename)
    return yaml.load(open(cfg_filename).read())


def check_config(cfg):
    yaml_keys = [
        'COORDINATES_FROM_FILENAME',
        'COORDINATES_IN_FILENAME_ONE_BASED',
        'SUBEXPERIMENT_FOLDER_FORMAT',
        'SUBEXPERIMENT_FILE_FORMAT',
        'CYCLE_FROM_FILENAME',
        'EXPERIMENT_FROM_FILENAME',
        'IMAGE_FOLDER_LOCATION',
        'SUBEXPERIMENTS_EXIST',
        'SEGMENTATION_FOLDER_LOCATION',
        'OBJECT_FROM_FILENAME',
        'SHIFT_FOLDER_LOCATION',
        'SHIFT_FILE_FORMAT',
        'STATS_FOLDER_LOCATION',
        'STATS_FILE_FORMAT',
        'CHANNEL_FROM_FILENAME',
        'MEASUREMENT_FOLDER_LOCATION',
        'CELL_ID_FORMAT'
    ]
    for key in yaml_keys:
        if key not in cfg:
            raise Exception('Configuration file must contain the key "%s"' % key)

{'fraction_non_alphanumeric': 0.09833930315858026, 'fraction_numerical': 0.00032562683165092806, 'mean_word_length': 2.913375796178344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5838881', 'n_tokens_mistral': 1002, 'n_tokens_neox': 961, 'n_words': 207}