<commit_before>from bidict import bidict, ValueDuplicationError


def is_anonymous(name):
    return name.startswith("ANONYMOUS_ANONYMOUS_ANONYMOUS_")


class TohuNamespaceError(Exception):
    """
    Custom exception.
    """


class TohuNamespace:

    def __init__(self):
        self.generators = bidict()

    def __len__(self):
        return len(self.generators)

    def __getitem__(self, key):
        return self.generators[key]

    def add_generator(self, g, name=None):
        if name is None:
            name = f"ANONYMOUS_ANONYMOUS_ANONYMOUS_{g.tohu_id}"

        if name in self.generators and self.generators[name] is not g:
            raise TohuNamespaceError("A different generator with the same name already exists.")

        try:
            self.generators[name] = g
        except ValueDuplicationError:
            existing_name = self.generators.inv[g]
            if is_anonymous(existing_name) and not is_anonymous(name):
                self.generators.inv[g] = name<commit_msg>Add repr method for TohuNamespace<commit_after>from mako.template import Template
import textwrap
from bidict import bidict, ValueDuplicationError


def is_anonymous(name):
    return name.startswith("ANONYMOUS_ANONYMOUS_ANONYMOUS_")


class TohuNamespaceError(Exception):
    """
    Custom exception.
    """


class TohuNamespace:

    def __init__(self):
        self.generators = bidict()

    def __repr__(self):
        s = Template(textwrap.dedent("""\
            <TohuNameSpace:
               %for name, g in items:
               ${name}: ${g}
               %endfor
            >
            """)).render(items=self.generators.items())
        return s

    def __len__(self):
        return len(self.generators)

    def __getitem__(self, key):
        return self.generators[key]

    def add_generator(self, g, name=None):
        if name is None:
            name = f"ANONYMOUS_ANONYMOUS_ANONYMOUS_{g.tohu_id}"

        if name in self.generators and self.generators[name] is not g:
            raise TohuNamespaceError("A different generator with the same name already exists.")

        try:
            self.generators[name] = g
        except ValueDuplicationError:
            existing_name = self.generators.inv[g]
            if is_anonymous(existing_name) and not is_anonymous(name):
                self.generators.inv[g] = name
{'fraction_non_alphanumeric': 0.09006342494714588, 'fraction_numerical': 0.0, 'mean_word_length': 2.526080476900149, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4513564', 'n_tokens_mistral': 738, 'n_tokens_neox': 703, 'n_words': 167}