Skip to content

Commit

Permalink
Handle RemoveTextDefinition (#720)
Browse files Browse the repository at this point in the history
* Handle `RemoveTextDefinition`

* formatted

* formatted

* formatted

* added old value

* added back remove defn column

* corrected syntex

* changed defn
  • Loading branch information
hrshdhgd authored Mar 19, 2024
1 parent 4f5e1cb commit c4d1cc8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def _tv_dict(stanza: Stanza) -> Dict[str, List[str]]:
id=_id(), about_node=t1id, new_value=td2, old_value=td1
)
elif vals1:
yield kgcl.RemoveTextDefinition(id=_id(), about_node=t1id)
yield kgcl.RemoveTextDefinition(id=_id(), about_node=t1id, old_value=td1)
else:
yield kgcl.NewTextDefinition(id=_id(), about_node=t2id, new_value=td2)
elif tag == TAG_IS_OBSOLETE:
Expand Down
14 changes: 13 additions & 1 deletion src/oaklib/interfaces/differ_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
PredicateChange,
RemoveNodeFromSubset,
RemoveSynonym,
RemoveTextDefinition,
SynonymPredicateChange,
)

Expand Down Expand Up @@ -250,6 +251,15 @@ def diff(
)
yield new_def

# definition removal
if self.definition(entity) is not None and other_ontology.definition(entity) is None:
yield RemoveTextDefinition(
id=_gen_id(),
about_node=entity,
old_value=self.definition(entity),
new_value=other_ontology.definition(entity),
)

# Synonyms - compute both sets of aliases
self_aliases[entity] = set(self.alias_relationships(entity, exclude_labels=True))
other_aliases[entity] = set(
Expand Down Expand Up @@ -335,7 +345,9 @@ def diff(

# Process the entities in parallel using a generator
yield from _parallely_get_relationship_changes(
self_ontology_without_obsoletes, self_out_rels, other_out_rels,
self_ontology_without_obsoletes,
self_out_rels,
other_out_rels,
)

def diff_summary(
Expand Down
10 changes: 10 additions & 0 deletions src/oaklib/utilities/writers/change_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ def handle_new_text_definition(self, value):
header = "| Term | New Text Definition |"
self.write_markdown_table(f"Text definitions added: {len(rows)}", header, rows)

def handle_remove_text_definition(self, value):
# Create rows for the table
rows = [
f"| {self._format_entity_labels(change.about_node)} | {change.old_value} |"
for change in value
]
header = "| Term | Removed Text Definition |"
self.write_markdown_table(f"Text definitions removed: {len(rows)}", header, rows)

def handle_node_obsoletion_with_direct_replacement(self, value):
rows = [
f"| {self._format_entity_labels(change.about_node)} |\
Expand Down Expand Up @@ -338,6 +347,7 @@ def process_changes(self, curie_or_change: Dict[str, Change]):
"ClassCreation": self.handle_class_creation,
"NodeDeletion": self.handle_node_deletion,
"NewTextDefinition": self.handle_new_text_definition, # ! same as NodeTextDefinition
"RemoveTextDefinition": self.handle_remove_text_definition,
"NodeObsoletionWithDirectReplacement": self.handle_node_obsoletion_with_direct_replacement,
"NodeObsoletion": self.handle_node_obsoletion,
"NodeDirectMerge": self.handle_node_direct_merge,
Expand Down

0 comments on commit c4d1cc8

Please sign in to comment.