def normalize_node(self, node: BaseEntity) -> Optional[BaseEntity]: """Normalize a node if possible, otherwise return None.""" namespace = node.get(NAMESPACE) if not namespace or namespace.lower() not in {'hbp', 'conso'}: return identifier = node.get(IDENTIFIER) name = node.get(NAME) if identifier is None and name is None: raise ValueError if identifier is not None: name = self.identifier_to_label.get(identifier) if name is not None: return node.__class__(namespace=namespace, name=name, identifier=identifier) identifier = self.label_to_identifier.get(name) if identifier is not None: return node.__class__(namespace=namespace, name=name, identifier=identifier)
def normalize_node(self, node: BaseEntity) -> Optional[BaseEntity]: """Normalize a node if possible, otherwise return None.""" namespace = node.get(NAMESPACE) if not namespace or namespace.lower() not in {'hbp', 'conso'}: return identifier = node.get(IDENTIFIER) name = node.get(NAME) if identifier is None and name is None: raise ValueError elif identifier is not None: name = self.identifier_to_label.get(identifier) if name is not None: return node.__class__(namespace=namespace, name=name, identifier=identifier) logger.warning(f'Could not find CONSO name for {node:r}') elif name is not None: if name.startswith('CONSO'): identifier = self.identifier_to_label.get(name) if identifier is not None: # flip it! return node.__class__(namespace=namespace, name=identifier, identifier=name) logger.warning(f'Could not find CONSO name for {node:r}') else: identifier = self.label_to_identifier.get(name) if identifier is not None: return node.__class__(namespace=namespace, name=name, identifier=identifier) logger.warning(f'Could not find CONSO identifier for {node:r}')