<commit_before>class OperatorEq:
    def apply(self, q, attr, v):
        return q.filter(attr == v)

class OperatorLike:
    def apply(self, q, attr, v):
        return q.filter(attr.like('%{0}%'.format(v)))

class OperatorBetween:
    def apply(self, q, attr, v):
        return q.filter(attr.between(v[0], v[1]))

class RelationshipOperatorContains:
    def apply(self, q, attr, v):
        return q.filter(attr.contains(v))

FILTER_HINT = 'hint'
FILTER_VALUES = 'values'

class QueryFilter(object):
    def __init__(self, query_filter, mappings = []):
        self._query_filter = query_filter
        self._mappings = mappings

    def apply_query_filter(self, q, cls):
        hints = self._query_filter[FILTER_HINT]
        values = self._query_filter[FILTER_VALUES]

        for (k, v) in values.items():
            if v == None:
                continue

            if k in self._mappings:
                (cls, field) = self._mappings[k]
                attr = getattr(cls, field)
            else:
                attr = getattr(cls, k)

            q = hints[k]().apply(q, attr, v)

        return q
<commit_msg>Support #7220 - Osobnosti na novom CMS<commit_after>class OperatorEq:
    def apply(self, q, attr, v):
        return q.filter(attr == v)

class OperatorLike:
    def apply(self, q, attr, v):
        return q.filter(attr.like('%{0}%'.format(v)))

class OperatorLeftLike:
    '''
        Left side of string is like ...
    '''
    def apply(self, q, attr, v):
        return q.filter(attr.like('{0}%'.format(v)))

class OperatorRightLike:
    '''
        Right side of string is like ...
    '''
    def apply(self, q, attr, v):
        return q.filter(attr.like('%{0}'.format(v)))

class OperatorBetween:
    def apply(self, q, attr, v):
        return q.filter(attr.between(v[0], v[1]))

class RelationshipOperatorContains:
    def apply(self, q, attr, v):
        return q.filter(attr.contains(v))

FILTER_HINT = 'hint'
FILTER_VALUES = 'values'

class QueryFilter(object):
    def __init__(self, query_filter, mappings = []):
        self._query_filter = query_filter
        self._mappings = mappings

    def apply_query_filter(self, q, cls):
        hints = self._query_filter[FILTER_HINT]
        values = self._query_filter[FILTER_VALUES]

        for (k, v) in values.items():
            if v == None:
                continue

            if k in self._mappings:
                (cls, field) = self._mappings[k]
                attr = getattr(cls, field)
            else:
                attr = getattr(cls, k)

            q = hints[k]().apply(q, attr, v)

        return q

{'fraction_non_alphanumeric': 0.13088404133180254, 'fraction_numerical': 0.004592422502870264, 'mean_word_length': 2.2512437810945274, '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': '99320', 'n_tokens_mistral': 863, 'n_tokens_neox': 823, 'n_words': 213}