<commit_before>from .Node import Node
from .BitField import BitField
from .Register import Register
from .RegisterMap import RegisterMap

class NodeFactory():
    classes = {
            'Node'       : Node,
            'BitField'   : BitField,
            'Register'   : Register,
            'RegisterMap': RegisterMap,
            }
    @classmethod
    def make(cls, to_make, *args, **kwargs):
        return cls.classes[to_make](*args, **kwargs)

def deserialize(d):
    objs = {}
    for uuid, node in d.items():
        node_copy = node.copy()
        class_type = node_copy.pop('class_type')
        objs[uuid] = NodeFactory.make(class_type, uuid=uuid, **node_copy)

    root = None
    #now walk through all the items again and setup node references
    for uuid, node in objs.items():
        parent_uuid = node.parent
        if parent_uuid != None:
            try:
                parent_node = objs[parent_uuid]
            except KeyError as e:
                raise KeyError(
                    "Can't find parent for node: {} (parent={})".format(node,
                        parent_uuid))
            parent_node[node.name] = node
            node.parent = parent_node

        else: #this node is the root
            root = node
            root.parent = None
        #print('Now on node: {}, parent: {}'.format(node, node.parent))<commit_msg>removed class factory as it is redundant<commit_after>from .Node import Node
def deserialize(d):
    objs = {}
    for uuid, node in d.items():
        node_copy = node.copy()
        _class = Node.class_registry[node_copy.pop('class_type')]
        objs[uuid] = _class(uuid=uuid, **node_copy)

    root = None
    #now walk through all the items again and setup node references
    for uuid, node in objs.items():
        parent_uuid = node.parent
        if parent_uuid != None:
            try:
                parent_node = objs[parent_uuid]
            except KeyError as e:
                raise KeyError(
                    "Can't find parent for node: {} (parent={})".format(node,
                        parent_uuid))
            parent_node[node.name] = node
            node.parent = parent_node

        else: #this node is the root
            root = node
            root.parent = None
        #print('Now on node: {}, parent: {}'.format(node, node.parent))
{'fraction_non_alphanumeric': 0.10316780821917808, 'fraction_numerical': 0.0, 'mean_word_length': 1.9067164179104477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4852258', 'n_tokens_mistral': 657, 'n_tokens_neox': 647, 'n_words': 194}