<commit_before>from utils import get_qualified_name, get_qualified_instance_name, IMMUTABLE, GIZMO_MODEL, GIZMO_NODE_TYPE
from entity import Edge, Vertex, GenericVertex, GenericEdge, _MAP, _BaseEntity
from gremlinpy.gremlin import Gremlin, Function
from exception import *

#Holds the model->mapper mappings for custom mappers
_MAPPER_MAP = {}
GENERIC_MAPPER = 'generic.mapper'
count = 0
query_count = 0


def get_mapper(gremlin, mapper, model=None, name=GENERIC_MAPPER):
    """
    function used to load a mapper based on the entity
    """
    if model is not None:
        if isinstance(model, _BaseEntity):
            name = get_qualified_instance_name(model)
        else:
            name = get_qualified_name(model)

    if name not in _MAPPER_MAP:
        name = GENERIC_MAPPER
        
    return _MAPPER_MAP[name](gremlin, mapper)


class _MapperVariableStorage(dict):
    """
    dictionary used to hold all of the variables mapped to the return entities
    used in the current executing script
    """
    def get_key_by_value(self, value):
        ret_key = None
        
        for key, def_val in self.iteritems():
            if value == def_val:
                ret_key = key
                break;
        
        return ret_key


class _RootMapper(type):
    """
    In the case of custom mappers, this metaclass will register the model name
    with the mapper object. This is done so that when models are loaded by name
    its mappers is used to CRUD it. 
    
    This only works when the mapper_instance.create_model() method is used to 
    create the model
    """
    def __new__(cls, name, bases, attrs):
        cls = super(_RootMapper, cls).__new__(cls, name, bases, attrs)
        model = attrs.pop('model', None)

        if model:
            map_name = '%s.%s' % (model.__module__, model.__name__)
            _MAPPER_MAP[map_name] = cls
        elif name == '_GenericMapper':
            _MAPPER_MAP[GENERIC_MAPPER] = cls
        
        return cls


class _GenericMapper(object):<commit_msg>cleanup<commit_after>from utils import get_qualified_name, get_qualified_instance_name, IMMUTABLE, GIZMO_MODEL, GIZMO_NODE_TYPE
from entity import Edge, Vertex, GenericVertex, GenericEdge, _MAP, _BaseEntity
from gremlinpy.gremlin import Gremlin, Function
from exception import *

#Holds the model->mapper mappings for custom mappers
_MAPPER_MAP = {}
GENERIC_MAPPER = 'generic.mapper'
count = 0
query_count = 0


def get_mapper(gremlin, mapper, model=None, name=GENERIC_MAPPER):
    """
    function used to load a mapper based on the entity
    """
    if model is not None:
        if isinstance(model, _BaseEntity):
            name = get_qualified_instance_name(model)
        else:
            name = get_qualified_name(model)

    if name not in _MAPPER_MAP:
        name = GENERIC_MAPPER
        
    return _MAPPER_MAP[name](gremlin, mapper)


class _RootMapper(type):
    """
    In the case of custom mappers, this metaclass will register the model name
    with the mapper object. This is done so that when models are loaded by name
    its mappers is used to CRUD it. 
    
    This only works when the mapper_instance.create_model() method is used to 
    create the model
    """
    def __new__(cls, name, bases, attrs):
        cls = super(_RootMapper, cls).__new__(cls, name, bases, attrs)
        model = attrs.pop('model', None)

        if model:
            map_name = '%s.%s' % (model.__module__, model.__name__)
            _MAPPER_MAP[map_name] = cls
        elif name == '_GenericMapper':
            _MAPPER_MAP[GENERIC_MAPPER] = cls
        
        return cls


class _GenericMapper(object):
{'fraction_non_alphanumeric': 0.07504793207340454, 'fraction_numerical': 0.0010955902492467817, 'mean_word_length': 2.8121085594989563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '864846', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1093, 'n_words': 354}