Skip to content

Commit

Permalink
Implementing add/remove subset for all impls
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Mar 9, 2024
1 parent 68566f2 commit 56431ae
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/oaklib/implementations/pronto/pronto_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,12 @@ def apply_patch(
# rather than forcing all synonyms to be related.
scope = str(patch.qualifier.value).upper() if patch.qualifier else "RELATED"
t.add_synonym(description=patch.new_value, scope=scope)
elif isinstance(patch, kgcl.AddNodeToSubset):
t = self._entity(patch.about_node, strict=True)
t.subsets = t.subsets.union({patch.in_subset})
elif isinstance(patch, kgcl.RemoveNodeFromSubset):
t = self._entity(patch.about_node, strict=True)
t.subsets = t.subsets.difference({patch.in_subset})
elif isinstance(patch, kgcl.EdgeCreation):
self.add_relationship(patch.subject, patch.predicate, patch.object)
elif isinstance(patch, kgcl.EdgeDeletion):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ def apply_patch(
t = self._stanza(patch.about_node, strict=True)
t.add_tag_value(TAG_SUBSET, patch.in_subset)
modified_entities.append(patch.about_node)
elif isinstance(patch, kgcl.RemoveNodeFromSubset):
t = self._stanza(patch.about_node, strict=True)
t.remove_simple_tag_value(TAG_SUBSET, patch.in_subset)
modified_entities.append(patch.about_node)
elif isinstance(patch, kgcl.NewTextDefinition):
t = self._stanza(patch.about_node, strict=True)
t.add_quoted_tag_value(TAG_DEFINITION, patch.new_value.strip("'"), xrefs=[])
Expand Down
23 changes: 22 additions & 1 deletion src/oaklib/implementations/sqldb/sql_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,28 @@ def apply_patch(
)
)
)

elif isinstance(patch, kgcl.AddNodeToSubset):
# TODO: implement deterministic subset mapping
pfx = about.split(":")[0].lower()
subset_curie = f"obo:{pfx}#{patch.in_subset}"
self._execute(
insert(Statements).values(
subject=about, predicate=IN_SUBSET, object=subset_curie
)
)
elif isinstance(patch, kgcl.RemoveNodeFromSubset):
# TODO: implement deterministic subset mapping
pfx = about.split(":")[0].lower()
subset_curie = f"obo:{pfx}#{patch.in_subset}"
self._execute(
delete(Statements).where(
and_(
Statements.subject == about,
Statements.predicate == IN_SUBSET,
Statements.object == subset_curie,
)
)
)
elif isinstance(patch, kgcl.NodeObsoletion):
self.check_node_exists(about)
self._set_predicate_value(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_implementations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,17 @@ def test_patcher(
),
None,
),
(
kgcl.RemoveNodeFromSubset(
id=generate_change_id(), about_node=NUCLEAR_ENVELOPE, in_subset="goslim_generic"
),
False,
lambda oi: test.assertNotIn(
NUCLEAR_ENVELOPE,
oi.subset_members("goslim_generic"),
),
None,
),
(
kgcl.RemoveSynonym(
id=generate_change_id(),
Expand Down

0 comments on commit 56431ae

Please sign in to comment.