diff --git a/src/oaklib/implementations/simpleobo/simple_obo_implementation.py b/src/oaklib/implementations/simpleobo/simple_obo_implementation.py index bcee7b2be..572d6538e 100644 --- a/src/oaklib/implementations/simpleobo/simple_obo_implementation.py +++ b/src/oaklib/implementations/simpleobo/simple_obo_implementation.py @@ -822,16 +822,22 @@ def _id(): return generate_change_id() node_is_deleted = False + node_is_created = False if stanza1 is None and stanza2 is None: raise ValueError("Both stanzas are None") if stanza1 is None: stanza1 = Stanza(id=stanza2.id, type=stanza2.type) if stanza2.type == "Term": - yield kgcl.ClassCreation(id=_id(), about_node=stanza2.id) + yield kgcl.ClassCreation( + id=_id(), about_node=stanza2.id, name=stanza2.singular_value(TAG_NAME) + ) elif stanza2.type == "Typedef": - yield kgcl.NodeCreation(id=_id(), about_node=stanza2.id) + yield kgcl.NodeCreation( + id=_id(), about_node=stanza2.id, name=stanza2.singular_value(TAG_NAME) + ) else: raise ValueError(f"Unknown stanza type: {stanza2.type}") + node_is_created = True if stanza2 is None: stanza2 = Stanza(id=stanza1.id, type=stanza1.type) if stanza1.type == "Term": @@ -867,16 +873,23 @@ def _tv_dict(stanza: Stanza) -> Dict[str, List[str]]: continue logging.info(f"Difference in {tag}: {vals1} vs {vals2}") if tag == TAG_NAME: - if node_is_deleted: + if node_is_deleted or node_is_created: continue if vals1 and vals2: yield kgcl.NodeRename( id=_id(), about_node=t1id, new_value=vals2list[0], old_value=vals1list[0] ) - elif vals1: - yield kgcl.NodeDeletion(id=_id(), about_node=t1id) + elif vals2: + # Existing node goes from having no name to having a name + # In future KGCL may have a NodeNewName. For now we use NodeRename. + yield kgcl.NodeRename( + id=_id(), about_node=t1id, new_value=vals2list[0], old_value=None + ) else: - yield kgcl.ClassCreation(id=_id(), about_node=t2id, name=vals2list[0]) + #! KGCL may have NameDeletion in the future. + yield kgcl.NodeRename( + id=_id(), about_node=t2id, old_value=vals2list[0], new_value=None + ) elif tag == TAG_DEFINITION: if node_is_deleted: continue diff --git a/src/oaklib/utilities/writers/change_handler.py b/src/oaklib/utilities/writers/change_handler.py index 3d49ecc38..4597e4fa8 100644 --- a/src/oaklib/utilities/writers/change_handler.py +++ b/src/oaklib/utilities/writers/change_handler.py @@ -307,11 +307,13 @@ def handle_add_node_to_subset(self, value): def handle_mapping_creation(self, value): rows = list( { - f"""| {self._format_entity_labels(change.subject)} - | {change.predicate} | {self._format_entity_labels(change.object)} |""" + f"""| {self._format_entity_labels(change.subject)} | """ + f"""{change.predicate} | """ + f"""{self._format_entity_labels(change.object)} |""" for change in value } ) + header = "| Subject | Predicate | Object |" self.write_markdown_table(f"Mappings added: {len(rows)}", header, rows) @@ -336,11 +338,13 @@ def handle_mapping_predicate_change(self, value): def handle_remove_mapping(self, value): rows = list( { - f"""| {self._format_entity_labels(change.about_node)} - | {change.predicate} | {self._format_entity_labels(change.object)} |""" + f"""| {self._format_entity_labels(change.about_node)} | """ + f"""{change.predicate} | """ + f"""{self._format_entity_labels(change.object)} |""" for change in value } ) + header = "| Subject | Predicate | Object |" self.write_markdown_table(f"Mappings removed: {len(rows)}", header, rows) diff --git a/tests/test_implementations/__init__.py b/tests/test_implementations/__init__.py index 96dadce99..9642b4da6 100644 --- a/tests/test_implementations/__init__.py +++ b/tests/test_implementations/__init__.py @@ -1081,7 +1081,6 @@ def test_diff(self, oi: DifferInterface, oi_modified: DifferInterface): old_value="enzyme activity", new_value="catalytic activity", ), - kgcl.ClassCreation(id=FIXED_ID, about_node="GO:0033673"), kgcl.MappingCreation( id=FIXED_ID, subject=CELLULAR_COMPONENT,