<commit_before>import yaml
import os.path as op

from features.featuremode import FeatureMode


class Configuration:

    def __init__(self, path=None, name='config.yaml'):
        """ Creates a configuration class by loading a configuration file.

        :param path: Path to config file.
        :param name: Name of the config file.
        """

        if path is None:
            return

        # Load the configuration file and stores values in properties.
        with open(op.join(path, name)) as fin:
            self.__config = yaml.load(fin)

        # Properties for SIFT extraction.
        self.__edge_threshold = self.__config['edge_threshold']
        self.__peak_threshold = self.__config['peak_threshold']

        # Properties for principal component analysis.
        self.__descriptor_weight = self.__config['descriptor_weight']
        self.__neutral_factor = self.__config['neutral_factor']

        feature_mode = self.__config['feature_mode'].upper()
        if feature_mode == 'ALL':
            self.__feature_mode = FeatureMode.All
        elif feature_mode == 'DESCRIPTORS':
            self.__feature_mode = FeatureMode.Descriptors
        elif feature_mode == 'COLORS':
            self.__feature_mode = FeatureMode.Colors
        else:
            raise ValueError('Unknown feature mode (must be ALL, DESCRIPTORS or COLORS)')

        # Properties for feature vector distance measuring.
        self.__pc_projection_count = self.__config['pc_projection_count']
        self.__closest_group = self.__config['closest_group']
        self.__representative = self.__config['representative']

        # General properties.
        self.__processes = self.__config['processes']

        # Plot properties
        self.__save_plot = self.__config['save_plot']
        self.__ticks = self.__config['ticks']

    @property
    def descriptor_weight(self):
        """ The weight of the descriptors with respect to the L2 norm of the combined feature vector. """
        return self.__descriptor_weight<commit_msg>Default values for configuration.<commit_after>import yaml
import os.path as op

from features.featuremode import FeatureMode


class Configuration:

    def __init__(self, path=None, name='config.yaml'):
        """ Creates a configuration class by loading a configuration file.

        :param path: Path to config file.
        :param name: Name of the config file.
        """

        if path is not None:
            # Load the configuration file and stores values in properties.
            with open(op.join(path, name)) as fin:
                self.__config = yaml.load(fin)
        else:
            self.__config = {}

        # Properties for SIFT extraction.
        self.__edge_threshold = self.__config.get('edge_threshold', 10)
        self.__peak_threshold = self.__config.get('peak_threshold', 0.01)

        # Properties for principal component analysis.
        self.__descriptor_weight = self.__config.get('descriptor_weight', 0.725)
        self.__neutral_factor = self.__config.get('neutral_factor', 0.8)

        feature_mode = self.__config.get('feature_mode', 'ALL').upper()
        if feature_mode == 'ALL':
            self.__feature_mode = FeatureMode.All
        elif feature_mode == 'DESCRIPTORS':
            self.__feature_mode = FeatureMode.Descriptors
        elif feature_mode == 'COLORS':
            self.__feature_mode = FeatureMode.Colors
        else:
            raise ValueError('Unknown feature mode (must be ALL, DESCRIPTORS or COLORS)')

        # Properties for feature vector distance measuring.
        self.__pc_projection_count = self.__config.get('pc_projection_count', 30)
        self.__closest_group = self.__config.get('closest_group', 0.3)
        self.__representative = self.__config.get('representative', 0.05)

        # General properties.
        self.__processes = self.__config.get('processes', 6)

        # Plot properties
        self.__save_plot = self.__config.get('save_plot', False)
        self.__ticks = self.__config.get('ticks', False)

    @property
    def descriptor_weight(self):
        """ The weight of the descriptors with respect to the L2 norm of the combined feature vector. """
        return self.__descriptor_weight
{'fraction_non_alphanumeric': 0.0911875589066918, 'fraction_numerical': 0.004948162111215834, 'mean_word_length': 2.6848958333333335, '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': '4477799', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1063, 'n_words': 309}