def dict_to_node(node_dict): """ Convert a dictionary representation of a node into a Node object if it contains the minimum required fields. Otherwise, pass it through unchanged. """ minimum_fields = set(('text', 'label', 'node_type')) if minimum_fields.issubset(node_dict.keys()): node = Node(node_dict['text'], [], node_dict['label'], node_dict.get('title', None), node_dict['node_type']) if 'tagged_text' in node_dict: node.tagged_text = node_dict['tagged_text'] if 'child_labels' in node_dict: node.child_labels = node_dict['child_labels'] return node else: return node_dict
def dict_to_node(node_dict): """ Convert a dictionary representation of a node into a Node object if it contains the minimum required fields. Otherwise, pass it through unchanged. """ minimum_fields = set(('text', 'label', 'node_type')) if minimum_fields.issubset(node_dict.keys()): node = Node( node_dict['text'], [], node_dict['label'], node_dict.get('title', None), node_dict['node_type']) if 'tagged_text' in node_dict: node.tagged_text = node_dict['tagged_text'] if 'child_labels' in node_dict: node.child_labels = node_dict['child_labels'] return node else: return node_dict