<commit_before>from MyCapytain.common.base import Exportable
from MyCapytain.common.constants import get_graph, Mimetypes, RDF_NAMESPACES
from MyCapytain.errors import CitationDepthError
from copy import copy
from typing import Tuple
from abc import abstractmethod


class BaseCitationSet(Exportable):
    """ A citation set is a collection of citations that optionnaly can be matched using a .match() function

    :param children: List of Citation
    :type children: [BaseCitation]
    """

    def __repr__(self):
        return "<MyCapytain.common.reference.BaseCitationSet object at %s>" % id(self)

    EXPORT_TO = [Mimetypes.JSON.DTS.Std]

    def __init__(self, children=None):
        self._children = []

        if children:
            self.children = children

    @property
    def children(self):
        """ Children of a citation

        :rtype: [BaseCitation]
        """
        return self._children or []

    @children.setter
    def children(self, val: list):
        """ Sets children

        :param val: List of citation children
        """
        final_value = []
        if val is not None:
            for citation in val:
                if citation is None:
                    continue
                elif not isinstance(citation, (BaseCitation, type(self))):
                    raise TypeError("Citation children should be Citation")
                else:
                    if isinstance(self, BaseCitation):
                        citation.root = self.root
                    else:
                        citation.root = self
                    final_value.append(citation)

        self._children = final_value

    def add_child(self, child):
        """ Adds a child to the CitationSet

        :param child: Child citation to add
        :return:
        """
        if isinstance(child, BaseCitation):
            self._children.append(child)

    def __iter__(self):
        """ Iteration method

        Loop over the citation children

        :Example:
            >>>    c = BaseCitationSet(name="line")
            >>>    b = BaseCitationSet(name="poem", children=[c])
            >>>    b2 = BaseCitationSet(name="paragraph")
            >>>    a = BaseCitationSet(name="book", children=[b])
            >>>    [e for e in a] == [a, b, c, b2],

        """
        for child in self.children:
            yield from child

    @abstractmethod
    def match(self, passageId):
        """ Given a specific passageId, matches the citation to a specific citation object

        :param passageId: Passage Identifier
        :return: Citation that matches the passageId
        :rtype: BaseCitation
        """

    @property
    def depth(self):
        """ Depth of the citation scheme

        .. example:: If we have a Book, Poem, Line system,
         and the citation we are looking at is Poem, depth is 2


        :rtype: int
        :return: Depth of the citation scheme<commit_msg>(PR 3.0.0) Comment 1 of @sonofmun review : Use of Max in depth explained<commit_after>from MyCapytain.common.base import Exportable
from MyCapytain.common.constants import get_graph, Mimetypes, RDF_NAMESPACES
from MyCapytain.errors import CitationDepthError
from copy import copy
from typing import Tuple
from abc import abstractmethod


class BaseCitationSet(Exportable):
    """ A citation set is a collection of citations that optionnaly can be matched using a .match() function

    :param children: List of Citation
    :type children: [BaseCitation]
    """

    def __repr__(self):
        return "<MyCapytain.common.reference.BaseCitationSet object at %s>" % id(self)

    EXPORT_TO = [Mimetypes.JSON.DTS.Std]

    def __init__(self, children=None):
        self._children = []

        if children:
            self.children = children

    @property
    def children(self):
        """ Children of a citation

        :rtype: [BaseCitation]
        """
        return self._children or []

    @children.setter
    def children(self, val: list):
        """ Sets children

        :param val: List of citation children
        """
        final_value = []
        if val is not None:
            for citation in val:
                if citation is None:
                    continue
                elif not isinstance(citation, (BaseCitation, type(self))):
                    raise TypeError("Citation children should be Citation")
                else:
                    if isinstance(self, BaseCitation):
                        citation.root = self.root
                    else:
                        citation.root = self
                    final_value.append(citation)

        self._children = final_value

    def add_child(self, child):
        """ Adds a child to the CitationSet

        :param child: Child citation to add
        :return:
        """
        if isinstance(child, BaseCitation):
            self._children.append(child)

    def __iter__(self):
        """ Iteration method

        Loop over the citation children

        :Example:
            >>>    c = BaseCitationSet(name="line")
            >>>    b = BaseCitationSet(name="poem", children=[c])
            >>>    b2 = BaseCitationSet(name="paragraph")
            >>>    a = BaseCitationSet(name="book", children=[b])
            >>>    [e for e in a] == [a, b, c, b2],

        """
        for child in self.children:
            yield from child

    @abstractmethod
    def match(self, passageId):
        """ Given a specific passageId, matches the citation to a specific citation object

        :param passageId: Passage Identifier
        :return: Citation that matches the passageId
        :rtype: BaseCitation
        """

    @property
    def depth(self):
        """ Depth of the citation scheme: if multiple scheme are available,
        the deepest one from the current node is chosen (if there is two possibilities,
        a->((b->c)(d->e->f)) 4 is the depth

        .. example:: If we have a Book, Poem, Line system,
         and the citation we are looking at is Poem, depth is 2


        :rtype: int
        :return: Depth of the citation scheme
{'fraction_non_alphanumeric': 0.08766764802093556, 'fraction_numerical': 0.001799149492966961, 'mean_word_length': 1.994613124387855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '2347099', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1545, 'n_words': 545}