<commit_before>from operator import add
from functools import reduce
from collections import Counter
from itertools import combinations


def preprocessing(data):
    """ preprocesses data to be applicable to apriori

    Parameters
    ----------
    data : tbd

    Returns
    ---------
    list of sets
    """
    pass


class Apriori():
    """ Frequent Itemsets using the apriori algorithm

    Parameters
    ----------
    baskets : list of sets

    max_set_size : int, default None
                   determine frequent item sets up to max_set_size items
                   if None, determine alls frequent item sets

    threshold : real number >= 0 and <=1
        minimum threshold for item sets to count as frequent

    Raises
    ----------
    ValueError : if baskets is an empty list or if threshold is not in the
        interval [0,1]
    """
    def __init__(self, baskets, max_set_size=None, threshold=0.1):
        if baskets == []:
            raise ValueError("baskets must not be an empty list")
        if threshold > 1 or threshold < 0:
            raise ValueError("threshold must be in the range [0,1]")

        self.baskets = baskets
        self.max_set_size = max_set_size
        self.threshold = threshold

    def compute(self):
        """ Applies the apriori algorithm to baskets
        """
        pass

    def _initialize(self):
        pass

    def _construct(self):
        pass

    def _filter(self):
        pass

    def _construct_and_count(self, baskets, frequent_itemsets, j):
        if j == 1:
            item_counts = reduce(add, map(Counter, self.baskets))
            return item_counts
        if j > 1:
            # for every basket, filter tuples subset of basket
            # double loop through filtered tuples
                # if tuple difference is j-2, unite and count unison
            # if count(unison) = j add tuple to output and increase count
            pass
<commit_msg>adds baskets length computation in Apriori class<commit_after>from operator import add
from functools import reduce
from collections import Counter
from itertools import combinations


def preprocessing(data):
    """ preprocesses data to be applicable to apriori

    Parameters
    ----------
    data : tbd

    Returns
    ---------
    list of sets
    """
    pass


class Apriori():
    """ Frequent Itemsets using the apriori algorithm

    Parameters
    ----------
    baskets : list of sets

    max_set_size : int, default None
                   determine frequent item sets up to max_set_size items
                   if None, determine alls frequent item sets

    threshold : real number >= 0 and <=1
        minimum threshold for item sets to count as frequent

    Raises
    ----------
    ValueError : if baskets is an empty list or if threshold is not in the
        interval [0,1]
    """
    def __init__(self, baskets, max_set_size=None, threshold=0.1):
        if baskets == []:
            raise ValueError("baskets must not be an empty list")
        if threshold > 1 or threshold < 0:
            raise ValueError("threshold must be in the range [0,1]")

        self.baskets = baskets
        self.max_set_size = max_set_size
        self.threshold = threshold
        self.baskets_length = len(self.baskets)

    def compute(self):
        """ Applies the apriori algorithm to baskets
        """
        pass

    def _initialize(self):
        pass

    def _construct(self):
        pass

    def _filter(self):
        pass

    def _construct_and_count(self, baskets, frequent_itemsets, j):
        if j == 1:
            item_counts = reduce(add, map(Counter, self.baskets))
            return item_counts
        if j > 1:
            # for every basket, filter tuples subset of basket
            # double loop through filtered tuples
                # if tuple difference is j-2, unite and count unison
            # if count(unison) = j add tuple to output and increase count
            pass

{'fraction_non_alphanumeric': 0.07908611599297012, 'fraction_numerical': 0.006527742907356264, 'mean_word_length': 1.9642857142857142, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2514214', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1042, 'n_words': 408}