<commit_before>import inspect
from fedoralink.fedorans import RDF


def _type_matches(types_from_metadata, types_being_matched):
    for a_type in types_being_matched:
        if a_type not in types_from_metadata:
            return False
    return True


def _has_predicates(metadata, predicates):
    for predicate in predicates:
        if not metadata[predicate]:
            return False
    return True


class FedoraTypeManager:
    """
    A singleton responsible for creating instance of FedoraObject (and subclasses) out of RDFMetadata
    """

    models = set()

    # clazz -> (rdf_types, priority)
    on_rdf_types = {}

    # clazz -> (rdf_predicates, priority)
    on_rdf_predicates = {}

    @staticmethod
    def register_model(model_class, on_rdf_type=(), on_has_predicate=(), priority=1.0):
        """
        Register a model class

        :param model_class:         model class, must be inherited from FedoraObject
        :param on_rdf_type:         a tuple of rdf types which this class requires in the metadata
        :param on_has_predicate:    a tuple of predicates which this class required in the metadata
        :param priority:            priority which this class has in mro
        :return:
        """

        if model_class in FedoraTypeManager.models:
            return                              # already registered

        FedoraTypeManager.models.add(model_class)
        if on_rdf_type:
            FedoraTypeManager.on_rdf_types[model_class] = (on_rdf_type, priority)

        if on_has_predicate:
            FedoraTypeManager.on_rdf_predicates[model_class] = (on_has_predicate, priority)

    @staticmethod
    def get_model_class(classname):
        for model in FedoraTypeManager.models:
            if model.__name__ == classname:
                return model
        raise TypeError('Class with name %s is not registered as a model' % classname)

    @staticmethod
    def get_object_class(metadata, model_class=None):
        """<commit_msg>Added get_model_class_from_fullname<commit_after>import inspect
from fedoralink.fedorans import RDF
from fedoralink.utils import fullname


def _type_matches(types_from_metadata, types_being_matched):
    for a_type in types_being_matched:
        if a_type not in types_from_metadata:
            return False
    return True


def _has_predicates(metadata, predicates):
    for predicate in predicates:
        if not metadata[predicate]:
            return False
    return True


class FedoraTypeManager:
    """
    A singleton responsible for creating instance of FedoraObject (and subclasses) out of RDFMetadata
    """

    models = set()

    # clazz -> (rdf_types, priority)
    on_rdf_types = {}

    # clazz -> (rdf_predicates, priority)
    on_rdf_predicates = {}

    @staticmethod
    def register_model(model_class, on_rdf_type=(), on_has_predicate=(), priority=1.0):
        """
        Register a model class

        :param model_class:         model class, must be inherited from FedoraObject
        :param on_rdf_type:         a tuple of rdf types which this class requires in the metadata
        :param on_has_predicate:    a tuple of predicates which this class required in the metadata
        :param priority:            priority which this class has in mro
        :return:
        """

        if model_class in FedoraTypeManager.models:
            return                              # already registered

        FedoraTypeManager.models.add(model_class)
        if on_rdf_type:
            FedoraTypeManager.on_rdf_types[model_class] = (on_rdf_type, priority)

        if on_has_predicate:
            FedoraTypeManager.on_rdf_predicates[model_class] = (on_has_predicate, priority)

    @staticmethod
    def get_model_class(classname):
        for model in FedoraTypeManager.models:
            if model.__name__ == classname:
                return model
        raise TypeError('Class with name %s is not registered as a model' % classname)

    @staticmethod
    def get_model_class_from_fullname(classname):
        for model in FedoraTypeManager.models:
            if fullname(model) == classname:
                return model
        raise TypeError('Class with name %s is not registered as a model' % classname)

    @staticmethod
    def get_object_class(metadata, model_class=None):
        """
{'fraction_non_alphanumeric': 0.06314819082737957, 'fraction_numerical': 0.0009218713989398478, 'mean_word_length': 2.5779060181368507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4481195', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1198, 'n_words': 355}