<commit_before>#
#   Copyright (c) 2013-2015, <NAME>
#
#   This file is part of openbandparams.
#
#   openbandparams is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published
#   by the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   openbandparams is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with openbandparams.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

from .parameter import Parameter, MethodParameter


class Alloy(object):

    def __init__(self, name, elements, parameters=None):
        self.name = name
        self.elements = elements
        self._parameters = {}
        self._aliases = {}
        if parameters is not None:
            for parameter in parameters:
                self.set_parameter(parameter)

    def __eq__(self, other):
        return (type(self) == type(other) and
                self.name == other.name and
                self.elements == other.elements,
                self._parameters == other._parameters)
    
    def __getattribute__(self, name):
        if name in ['_parameters', '_aliases']:
            return super(Alloy, self).__getattribute__(name)
        if name in self._parameters:
            return self._parameters[name]
        elif name in self._aliases:
            return self._parameters[self._aliases[name]]

        item = super(Alloy, self).__getattribute__(name)
        if isinstance(item, MethodParameter):
            # make sure MethodParameters defined with the class
            # are bound to this Alloy
            return item.bind(alloy=self)
        else:
            return item

    def __str__(self):
        return self.name
    
#     def __repr__(self):
#         return self.name
    
    def latex(self):
        '''
        Returns a LaTeX representation of the alloy.
        '''
        raise NotImplementedError()

    def element_fraction(self, element):
        '''
        Returns the atomic fraction of the given ``element``.
        '''
        raise NotImplementedError()

    def _add_parameter(self, parameter):<commit_msg>improve `Alloy` error message<commit_after>#
#   Copyright (c) 2013-2015, <NAME>
#
#   This file is part of openbandparams.
#
#   openbandparams is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published
#   by the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   openbandparams is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with openbandparams.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

from .parameter import Parameter, MethodParameter


class Alloy(object):

    def __init__(self, name, elements, parameters=None):
        self.name = name
        self.elements = elements
        self._parameters = {}
        self._aliases = {}
        if parameters is not None:
            for parameter in parameters:
                self.set_parameter(parameter)

    def __eq__(self, other):
        return (type(self) == type(other) and
                self.name == other.name and
                self.elements == other.elements,
                self._parameters == other._parameters)
    
    def __getattribute__(self, name):
        if name in ['_parameters', '_aliases']:
            return super(Alloy, self).__getattribute__(name)
        if name in self._parameters:
            return self._parameters[name]
        elif name in self._aliases:
            return self._parameters[self._aliases[name]]
        
        try:
            item = super(Alloy, self).__getattribute__(name)
        except AttributeError as e:
            msg = e.message.replace('object',
                                    "object '{}'".format(self.name))
            raise AttributeError(msg)
        if isinstance(item, MethodParameter):
            # make sure MethodParameters defined with the class
            # are bound to this Alloy
            return item.bind(alloy=self)
        else:
            return item

    def __str__(self):
        return self.name
    
#     def __repr__(self):
#         return self.name
    
    def latex(self):
        '''
        Returns a LaTeX representation of the alloy.
        '''
        raise NotImplementedError()

    def element_fraction(self, element):
        '''
        Returns the atomic fraction of the given ``element``.
        '''
        raise NotImplementedError()

    def _add_parameter(self, parameter):
{'fraction_non_alphanumeric': 0.10837438423645321, 'fraction_numerical': 0.0034103827207275484, 'mean_word_length': 2.3883183568677793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2200259', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1307, 'n_words': 479}