<commit_before>"""Serializer classes for fes comparison operator types"""

from __future__ import absolute_import
from __future__ import unicode_literals
import logging

from lxml import etree

from ... import types
from ...namespaces import namespaces
from .base import BaseSerializer
from .fesxml import FesXmlSerializer

logger = logging.getLogger(__name__)


class BinaryOperatorSerializer(BaseSerializer):

    @classmethod
    def _deserialize(cls, xml_element):
        match_case = False
        if xml_element.get("matchCase", "true") == "true":
            match_case = True
        return cls.TYPE_(
            first_expression=FesXmlSerializer.deserialize(xml_element[0]),
            second_expression=FesXmlSerializer.deserialize(xml_element[1]),
            match_case=match_case,
            match_action=xml_element.get("matchAction")
        )

    @classmethod
    def _serialize(cls, operator):
        xml_element = etree.Element(
            "{{{0[fes]}}}{1.__class__.__name__}".format(namespaces, operator),
            matchCase="true" if operator.match_case else "false",
            matchAction=operator.match_action, nsmap=namespaces
        )
        first = FesXmlSerializer.serialize(operator.first_expression,
                                           as_string=False)
        second = FesXmlSerializer.serialize(operator.second_expression,
                                            as_string=False)
        xml_element.append(first)
        xml_element.append(second)
        return xml_element


class PropertyIsEqualToSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsEqualTo


class PropertyIsNotEqualToSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsNotEqualTo


class PropertyIsLessThanSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsLessThan


class PropertyIsGreaterThanSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsGreaterThan


class PropertyIsLessThanOrEqualToSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsLessThanOrEqualTo


class PropertyIsGreaterThanOrEqualToSerializer(BinaryOperatorSerializer):
    TYPE_ = types.PropertyIsGreaterThanOrEqualTo


class PropertyIsLikeSerializer(BaseSerializer):
    TYPE_ = types.PropertyIsLike

    @classmethod
    def _deserialize(cls, xml_element):
        return cls.TYPE_(
            first_expression=FesXmlSerializer.deserialize(xml_element[0]),
            second_expression=FesXmlSerializer.deserialize(xml_element[1]),
            wild_card=xml_element.get("wildCard"),
            single_char=xml_element.get("singleChar"),
            escape_char=xml_element.get("escapeChar")
        )

    @classmethod<commit_msg>minor change to the name of a base class<commit_after>"""Serializer classes for fes comparison operator types"""

from __future__ import absolute_import
from __future__ import unicode_literals
import logging

from lxml import etree

from ... import types
from ...namespaces import namespaces
from .base import BaseSerializer
from .fesxml import FesXmlSerializer

logger = logging.getLogger(__name__)


class BinaryComparisonOperatorSerializer(BaseSerializer):

    @classmethod
    def _deserialize(cls, xml_element):
        match_case = False
        if xml_element.get("matchCase", "true") == "true":
            match_case = True
        return cls.TYPE_(
            first_expression=FesXmlSerializer.deserialize(xml_element[0]),
            second_expression=FesXmlSerializer.deserialize(xml_element[1]),
            match_case=match_case,
            match_action=xml_element.get("matchAction")
        )

    @classmethod
    def _serialize(cls, operator):
        xml_element = etree.Element(
            "{{{0[fes]}}}{1.__class__.__name__}".format(namespaces, operator),
            matchCase="true" if operator.match_case else "false",
            matchAction=operator.match_action, nsmap=namespaces
        )
        first = FesXmlSerializer.serialize(operator.first_expression,
                                           as_string=False)
        second = FesXmlSerializer.serialize(operator.second_expression,
                                            as_string=False)
        xml_element.append(first)
        xml_element.append(second)
        return xml_element


class PropertyIsEqualToSerializer(BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsEqualTo


class PropertyIsNotEqualToSerializer(BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsNotEqualTo


class PropertyIsLessThanSerializer(BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsLessThan


class PropertyIsGreaterThanSerializer(BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsGreaterThan


class PropertyIsLessThanOrEqualToSerializer(
        BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsLessThanOrEqualTo


class PropertyIsGreaterThanOrEqualToSerializer(
        BinaryComparisonOperatorSerializer):
    TYPE_ = types.PropertyIsGreaterThanOrEqualTo


class PropertyIsLikeSerializer(BaseSerializer):
    TYPE_ = types.PropertyIsLike

    @classmethod
    def _deserialize(cls, xml_element):
        return cls.TYPE_(
            first_expression=FesXmlSerializer.deserialize(xml_element[0]),
            second_expression=FesXmlSerializer.deserialize(xml_element[1]),
            wild_card=xml_element.get("wildCard"),
            single_char=xml_element.get("singleChar"),
            escape_char=xml_element.get("escapeChar")
        )

    @classmethod
{'fraction_non_alphanumeric': 0.07459713923592251, 'fraction_numerical': 0.0021727322107550242, 'mean_word_length': 3.4584342211460855, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '510799', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1409, 'n_words': 255}