def rename( self, value: str, path: str, cbk: Callable[[], None] = lambda: None ) -> str: """ Checks whether the given value needs to be renamed, and returns the old or new value it should be set to. Logs the change if it happens. """ if value == self.from_uri: log_change( f"Renaming class {self.from_str} to {self.to_str} in {stylize_json(path)}" ) cbk() return self.to_uri return value
def visit_SNode(self, json: semtk.SemTKJSON, path: str, sNode: semtk.SNode) -> None: super().visit_SNode(json, path, sNode) for index, node in enumerate(sNode.nodeList): if node.UriConnectBy == self.uri: this_path = f"{path}.nodeList[{index}].UriConnectBy" log_change( f"Deleting property {stylize_property(self.uri)} in {stylize_json(this_path)}" ) sNode.nodeList.pop(index) # cleanup for sparqlID in node.SnodeSparqlIDs: for index, importSpecNode in enumerate( json.importSpec.nodes): if importSpecNode.sparqlID == sparqlID: field = stylize_json("sparqlID") log_additional_deletion( f"importSpec.nodes[{index}]", f"it has {field} = {sparqlID}", ) json.importSpec.nodes.pop(index) for index, sNode in enumerate(json.sNodeGroup.sNodeList): if sNode.SparqlID == sparqlID: log_additional_deletion( f"sNodeGroup.sNodeList[{index}]", f"it has {field} = {sparqlID}", ) json.sNodeGroup.sNodeList.pop(index) # unconditional cleanup for index, prop in enumerate(sNode.propList): if prop.UriRelationship == self.uri: this_path = stylize_json(f"{path}.propList[{index}]") field = stylize_json("UriRelationship") log_change( f"Deleting {this_path} because it has {field} = {self.uri}" ) sNode.propList.pop(index)