<commit_before>from collections import namedtuple


KeyValuePair = namedtuple('KeyValuePair', ['key', 'value'])


class Metadata:
    def __init__(self, id = None, title = None, description = None,
                 classes = None, links = None, ref = None) -> None:
        self.id = id
        self.title = title
        self.description = description
        self.classes = classes
        self.links = links
        self.ref = ref


class Element(object):
    """
    Base Refract Element
    """

    def __init__(self, element: str = None, meta: Metadata = None,
                 attributes = None, content=None) -> None:
        if element and not hasattr(self, 'element'):
            self.element = element
        self.meta = meta or Metadata()
        self.attributes = attributes or {}
        self.content = content

    def __repr__(self):
        if isinstance(self.content, Element):
            return "<Element({}) content={}>".format(self.element, 'Element')

        return "<Element({}) content={}>".format(
            self.element, repr(self.content)
        )

    @property
    def defract(self):
        """
        Returns the underlying (unrefracted) value of element

        >>> Element(content='Hello').defract
        'Hello'

        >>> Element(content=Element(content='Hello')).defract
        'Hello'

        >>> Element(content=[Element(content='Hello')]).defract
        ['Hello']
        """

        from refract.elements.object import Object

        def get_value(item):
            if isinstance(item, KeyValuePair):
                return (get_value(item.key), get_value(item.value))
            elif isinstance(item, list):
                return [get_value(element) for element in item]
            elif isinstance(item, Element):
                if isinstance(item, Object) or item.element == 'object':
                    return dict(get_value(item.content))
                return get_value(item.content)

            return item

        return get_value(self)

    # Meta Accessors

    @property
    def id(self):
        return self.meta.id

    @id.setter
    def id(self, new_value):
        self.meta.id = new_value

    @property
    def title(self):
        return self.meta.title

    @title.setter
    def title(self, new_value):
        self.meta.title = new_value

    @property
    def description(self):
        return self.meta.description

    @description.setter
    def description(self, new_value):
        self.meta.description = new_value

    @property
    def ref(self):
        return self.meta.ref

    @ref.setter
    def ref(self, new_value):
        self.meta.ref = new_value

    @property
    def links(self):
        return self.meta.links

    @links.setter
    def links(self, new_value):
        self.meta.links = new_value

    @property
    def classes(self):
        return self.meta.classes

    @classes.setter
    def classes(self, new_value):
        self.meta.classes = new_value

    #

    @property
    def children(self):
        """
        Returns all of the children elements.
        """

        if isinstance(self.content, list):
            return self.content
        elif isinstance(self.content, Element):
            return [self.content]
        else:
            return []

    @property
    def recursive_children(self):
        """
        Generator returning all recursive children elements.<commit_msg>feat: Accessors allow non-refracted values<commit_after>from collections import namedtuple


KeyValuePair = namedtuple('KeyValuePair', ['key', 'value'])


class Metadata:
    def __init__(self, id = None, title = None, description = None,
                 classes = None, links = None, ref = None) -> None:
        self.id = id
        self.title = title
        self.description = description
        self.classes = classes
        self.links = links
        self.ref = ref


class Element(object):
    """
    Base Refract Element
    """

    def __init__(self, element: str = None, meta: Metadata = None,
                 attributes = None, content=None) -> None:
        if element and not hasattr(self, 'element'):
            self.element = element
        self.meta = meta or Metadata()
        self.attributes = attributes or {}
        self.content = content

    def __repr__(self):
        if isinstance(self.content, Element):
            return "<Element({}) content={}>".format(self.element, 'Element')

        return "<Element({}) content={}>".format(
            self.element, repr(self.content)
        )

    @property
    def defract(self):
        """
        Returns the underlying (unrefracted) value of element

        >>> Element(content='Hello').defract
        'Hello'

        >>> Element(content=Element(content='Hello')).defract
        'Hello'

        >>> Element(content=[Element(content='Hello')]).defract
        ['Hello']
        """

        from refract.elements.object import Object

        def get_value(item):
            if isinstance(item, KeyValuePair):
                return (get_value(item.key), get_value(item.value))
            elif isinstance(item, list):
                return [get_value(element) for element in item]
            elif isinstance(item, Element):
                if isinstance(item, Object) or item.element == 'object':
                    return dict(get_value(item.content))
                return get_value(item.content)

            return item

        return get_value(self)

    # Meta Accessors

    @property
    def id(self):
        return self.meta.id

    @id.setter
    def id(self, new_value):
        from refract.refraction import refract
        self.meta.id = refract(new_value)

    @property
    def title(self):
        return self.meta.title

    @title.setter
    def title(self, new_value):
        from refract.refraction import refract
        self.meta.title = refract(new_value)

    @property
    def description(self):
        return self.meta.description

    @description.setter
    def description(self, new_value):
        from refract.refraction import refract
        self.meta.description = refract(new_value)

    @property
    def ref(self):
        return self.meta.ref

    @ref.setter
    def ref(self, new_value):
        from refract.refraction import refract
        self.meta.ref = refract(new_value)

    @property
    def links(self):
        return self.meta.links

    @links.setter
    def links(self, new_value):
        from refract.refraction import refract
        self.meta.links = refract(new_value)

    @property
    def classes(self):
        return self.meta.classes

    @classes.setter
    def classes(self, new_value):
        from refract.refraction import refract
        self.meta.classes = refract(new_value)

    #

    @property
    def children(self):
        """
        Returns all of the children elements.
        """

        if isinstance(self.content, list):
            return self.content
        elif isinstance(self.content, Element):
            return [self.content]
        else:
            return []

    @property
    def recursive_children(self):
        """
        Generator returning all recursive children elements.
{'fraction_non_alphanumeric': 0.10423905489923559, 'fraction_numerical': 0.0, 'mean_word_length': 2.0752136752136754, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '4705604', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1888, 'n_words': 501}