<commit_before>from collections import namedtuple


_Predicate = namedtuple('_Predicate', ['operator', 'field_name', 'value'])


_HighOrderPredicate = namedtuple('HighOrder_Predicate', ['operator', 'operands', 'arity'])


_arity = namedtuple('_arity', ['ONE', 'MULTI'])('ONE', 'MULTI')


class Predicates(object):
    def __init__(self):
        self._predicates = {}

    def add_predicates(self, *predicates):
        for predicate in predicates:
            if predicate.operator not in self._predicates:
                self._predicates[predicate.operator] = {}
            merged_predicate = self._predicates[predicate.operator]
            merged_predicate[predicate.field_name] = predicate.value

    @property
    def json(self):
        if not self._predicates:
            return {}

        return {
            'predicates': [
                {k: v} for k, v in self._predicates.iteritems()]
        }


class PredicateBuilder(object):
    def __init__(self, field_name):
        self._field_name = field_name

    def __eq__(self, value):
        return self.equals(value)

    def equals(self, value):
        return _Predicate('equals', self._field_name, value)

    def deep_equals(self, value):
        return _Predicate('deepEquals', self._field_name, value)

    def contains(self, value):
        return _Predicate('contains', self._field_name, value)

    def startswith(self, value):<commit_msg>General structure to handle high-order predicates<commit_after>from collections import namedtuple


_Predicate = namedtuple('_Predicate', ['operator', 'field_name', 'value'])


_HighOrderPredicate = namedtuple('HighOrder_Predicate', ['operator', 'operands', 'arity'])


_arity = namedtuple('_arity', ['ONE', 'MULTI'])('ONE', 'MULTI')


class Predicates(object):
    def __init__(self):
        self._predicates = {}

    @staticmethod
    def _handle_normal_predicate(merged_predicate, predicate):
        merged_predicate[predicate.field_name] = predicate.value

    @staticmethod
    def _handle_high_order_predicate(merged_predicate, predicate):
        pass

    def add_predicates(self, *predicates):
        for predicate in predicates:
            if predicate.operator not in self._predicates:
                self._predicates[predicate.operator] = {}
            merged_predicate = self._predicates[predicate.operator]
            if isinstance(predicate, _Predicate):
                self._handle_normal_predicate(merged_predicate, predicate)
            elif isinstance(predicate, _HighOrderPredicate):
                self._handle_high_order_predicate(merged_predicate, predicate)
            else:
                assert False, 'Argument must be of type Predicate or HighOrderPredicate'

    @property
    def json(self):
        if not self._predicates:
            return {}

        return {
            'predicates': [
                {k: v} for k, v in self._predicates.iteritems()]
        }


class PredicateBuilder(object):
    def __init__(self, field_name):
        self._field_name = field_name

    def __eq__(self, value):
        return self.equals(value)

    def equals(self, value):
        return _Predicate('equals', self._field_name, value)

    def deep_equals(self, value):
        return _Predicate('deepEquals', self._field_name, value)

    def contains(self, value):
        return _Predicate('contains', self._field_name, value)

    def startswith(self, value):
{'fraction_non_alphanumeric': 0.10675636150921322, 'fraction_numerical': 0.0, 'mean_word_length': 3.018801410105758, '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': '2867003', 'n_tokens_mistral': 992, 'n_tokens_neox': 944, 'n_words': 220}