<commit_before>import os

import numpy as np


class FeatureContainer(object):
    """
    This class defines a container for storing features (of a given type) of all utterances.

    files : utterance-id --> feature-file-name
    """

    def __init__(self, path):
        self.files = {}
        self.path = path

    def load_features_of_utterance(self, utterance_idx):
        """ Return the features for the given utterance as numpy array. None if the given utterance has no features."""
        feature_file_path = os.path.join(self.path, '{}.npy'.format(utterance_idx))
        return np.load(feature_file_path)

    def add_features_for_utterance(self, utterance_idx, features):
        """ Stores the given features (numpy array) for the given utterance. """

        feature_file_path = os.path.join(self.path, utterance_idx)
        np.save(feature_file_path, features)<commit_msg>function to get feature dim<commit_after>import os
import glob

import numpy as np


class FeatureContainer(object):
    """
    This class defines a container for storing features (of a given type) of all utterances.

    files : utterance-id --> feature-file-name
    """

    def __init__(self, path):
        self.path = path

    def load_features_of_utterance(self, utterance_idx):
        """ Return the features for the given utterance as numpy array. None if the given utterance has no features."""
        feature_file_path = os.path.join(self.path, '{}.npy'.format(utterance_idx))
        return np.load(feature_file_path)

    def add_features_for_utterance(self, utterance_idx, features):
        """ Stores the given features (numpy array) for the given utterance. """

        feature_file_path = os.path.join(self.path, utterance_idx)
        np.save(feature_file_path, features)

    def feature_size(self):
        """ Return the feature dimension. Just reads a random utterance to get the feature size. """
        file = glob.glob(os.path.join(self.path, '*.npy'))[0]

        matrix = np.load(file)
        return np.size(matrix, 1)
{'fraction_non_alphanumeric': 0.10019550342130987, 'fraction_numerical': 0.0009775171065493646, 'mean_word_length': 3.194672131147541, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5593715', 'n_tokens_mistral': 603, 'n_tokens_neox': 582, 'n_words': 182}