<commit_before>import inspect
import multiprocessing

import numpy
from scipy.spatial.distance import cdist
from pathos.multiprocessing import ProcessingPool as Pool

from utils import get_connections, read_file_data
from utils import get_depth_threshold_mask_connections
from utils import ELE_TO_NUM, SMOOTHING_FUNCTIONS


def _func_star(args):
    '''
    A function and argument expanding helper function

    The first item in args is callable, and the remainder of the items are
    used as expanded arguments. This is to make the function header for reduce
    the same for the normal and parallel versions. Otherwise, the functions
    would have to do their own unpacking of arguments.
    '''
    f = args[0]
    args = args[1:]
    return f(*args)


class BaseFeature(object):
    '''
    A base class for all the features.

    Parameters
    ----------
    input_type : string, default='list'
        Specifies the format the input values will be (must be one of 'list'
        or 'filename').

    n_jobs : int, default=1
        Specifies the number of processes to create when generating the
        features. Positive numbers specify a specifc amount, and numbers less
        than 1 will use the number of cores the computer has.
    '''
    def __init__(self, input_type='list', n_jobs=1):
        self.input_type = input_type
        self.n_jobs = n_jobs

    def __repr__(self):
        argspec = inspect.getargspec(type(self).__init__)
        # Delete the only non-keyword argument
        args = [x for x in argspec.args if x != "self"]
        values = [getattr(self, x) for x in args]
        params = ["%s=%r" % (x, y) for x, y in zip(args, values)]
        return "%s(%s)" % (type(self).__name__, ', '.join(params))

    def convert_input(self, X):
        '''
        Converts the input (as specified in self.input_type) to a usable form

        Parameters
        ----------
        X : list or string (depends on the instance value of input_type)
            If input_type is 'list', then it must be an iterable of (elements,
            coodinates pairs) for each molecule. Where the elements are an
            iterable of the form (ele1, ele2, ..., elen) and coordinates are an
            iterable of the form [(x1, y1, z1), (x2, y2, z2), ..., (xn, yn,
            zn)].

            If input_type is 'filename', then it must be an iterable of
            paths/filenames for each molecule. The files must then be of the
            form
            ele1 x1 y1 z1
            ele2 x2 y2 z2<commit_msg>Add example of a connection<commit_after>import inspect
import multiprocessing

import numpy
from scipy.spatial.distance import cdist
from pathos.multiprocessing import ProcessingPool as Pool

from utils import get_connections, read_file_data
from utils import get_depth_threshold_mask_connections
from utils import ELE_TO_NUM, SMOOTHING_FUNCTIONS


def _func_star(args):
    '''
    A function and argument expanding helper function

    The first item in args is callable, and the remainder of the items are
    used as expanded arguments. This is to make the function header for reduce
    the same for the normal and parallel versions. Otherwise, the functions
    would have to do their own unpacking of arguments.
    '''
    f = args[0]
    args = args[1:]
    return f(*args)


class BaseFeature(object):
    '''
    A base class for all the features.

    Parameters
    ----------
    input_type : string, default='list'
        Specifies the format the input values will be (must be one of 'list'
        or 'filename').

    n_jobs : int, default=1
        Specifies the number of processes to create when generating the
        features. Positive numbers specify a specifc amount, and numbers less
        than 1 will use the number of cores the computer has.
    '''
    def __init__(self, input_type='list', n_jobs=1):
        self.input_type = input_type
        self.n_jobs = n_jobs

    def __repr__(self):
        argspec = inspect.getargspec(type(self).__init__)
        # Delete the only non-keyword argument
        args = [x for x in argspec.args if x != "self"]
        values = [getattr(self, x) for x in args]
        params = ["%s=%r" % (x, y) for x, y in zip(args, values)]
        return "%s(%s)" % (type(self).__name__, ', '.join(params))

    def convert_input(self, X):
        '''
        Converts the input (as specified in self.input_type) to a usable form

        Parameters
        ----------
        X : list or string (depends on the instance value of input_type)
            If input_type is 'list', then it must be an iterable of (elements,
            coodinates pairs) for each molecule. Where the elements are an
            iterable of the form (ele1, ele2, ..., elen) and coordinates are an
            iterable of the form [(x1, y1, z1), (x2, y2, z2), ..., (xn, yn,
            zn)]. This allows allows for connections to be incldued. This is a
            dictonary where the keys are the indices of the atoms and the
            values are dictonaries with the key being another index and the
            value is the bond order (one of '1', 'Ar', '2', or '3').
            Example for methane
            {
                0: {1: "1", 2: "1", 3: "1", 4: "1"},
                1: {0: "1"},
                2: {0: "1"},
                3: {0: "1"},
                4: {0: "1"},
            }

            If input_type is 'filename', then it must be an iterable of
            paths/filenames for each molecule. The files must then be of the
            form
            ele1 x1 y1 z1
            ele2 x2 y2 z2
{'fraction_non_alphanumeric': 0.08579088471849866, 'fraction_numerical': 0.011796246648793566, 'mean_word_length': 2.2937021777516184, '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': '1021847', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1562, 'n_words': 681}