Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solves ClassCreation duplication & formats Mappings md table properly #780

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/oaklib/implementations/simpleobo/simple_obo_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/oaklib/utilities/writers/change_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion tests/test_implementations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading