Skip to content

Commit

Permalink
rename edge to mapping (#775)
Browse files Browse the repository at this point in the history
* rename edge to mapping

* Update differ_interface.py

* Added MappingReplacement and RemoveMapping

* MappingPredicateChange

* formatted

* Added mapping change

* simpleobo + mapping change implemented

* Edited expected changes

* replace hard-coding to vars

---------

Co-authored-by: Chris Mungall <cjm@berkeleybop.org>
Co-authored-by: Harshad Hegde <hegdehb@gmail.com>
Co-authored-by: Harshad <hrshdhgd@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 20, 2024
1 parent 8b25588 commit 2baba34
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 88 deletions.
31 changes: 23 additions & 8 deletions src/oaklib/implementations/simpleobo/simple_obo_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,14 @@ def _tv_dict(stanza: Stanza) -> Dict[str, List[str]]:
elif tag == TAG_SUBSET:
if node_is_deleted:
continue
subsets1 = stanza1.simple_values(TAG_SUBSET)
subsets2 = stanza2.simple_values(TAG_SUBSET)
for subset in subsets1:
if subset not in subsets2:
yield kgcl.RemoveNodeFromSubset(id=_id(), about_node=t1id, in_subset=subset)
for subset in subsets2:
if subset not in subsets1:
yield kgcl.AddNodeToSubset(id=_id(), about_node=t2id, in_subset=subset)
xrefs1 = stanza1.simple_values(TAG_SUBSET)
xrefs2 = stanza2.simple_values(TAG_SUBSET)
for xref in xrefs1:
if xref not in xrefs2:
yield kgcl.RemoveNodeFromSubset(id=_id(), about_node=t1id, in_subset=xref)
for xref in xrefs2:
if xref not in xrefs1:
yield kgcl.AddNodeToSubset(id=_id(), about_node=t2id, in_subset=xref)
elif tag == TAG_IS_A:
isas1 = stanza1.simple_values(TAG_IS_A)
isas2 = stanza2.simple_values(TAG_IS_A)
Expand Down Expand Up @@ -950,6 +950,21 @@ def _tv_dict(stanza: Stanza) -> Dict[str, List[str]]:
yield kgcl.NewSynonym(
id=_id(), about_node=t2id, new_value=syn[0], predicate=pred
)
elif tag == TAG_XREF:
if node_is_deleted:
continue
xrefs1 = stanza1.simple_values(TAG_XREF)
xrefs2 = stanza2.simple_values(TAG_XREF)
for xref in xrefs1:
if xref not in xrefs2:
yield kgcl.RemoveMapping(
id=_id(), about_node=t1id, object=xref, predicate=HAS_DBXREF
)
for xref in xrefs2:
if xref not in xrefs1:
yield kgcl.MappingCreation(
id=_id(), subject=t2id, object=xref, predicate=HAS_DBXREF
)

def different_from(self, entity: CURIE, other_ontology: DifferInterface) -> bool:
t1 = self._stanza(entity, strict=False)
Expand Down
23 changes: 13 additions & 10 deletions src/oaklib/interfaces/differ_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
Change,
ClassCreation,
Edge,
EdgeChange,
EdgeCreation,
EdgeDeletion,
MappingCreation,
# MappingReplacement,
MappingPredicateChange,
NewSynonym,
NewTextDefinition,
NodeCreation,
Expand All @@ -26,6 +27,7 @@
NodeTextDefinitionChange,
NodeUnobsoletion,
PredicateChange,
RemoveMapping,
RemoveNodeFromSubset,
RemoveSynonym,
RemoveTextDefinition,
Expand Down Expand Up @@ -275,34 +277,35 @@ def diff(
if mappings_added_set:
for mapping in mappings_added_set:
predicate, xref = mapping
edge_created = EdgeCreation(
mapping_created = MappingCreation(
id=_gen_id(),
subject=entity,
predicate=predicate,
object=xref,
)
yield edge_created
yield mapping_created
if mappings_removed_set:
for mapping in mappings_removed_set:
predicate, xref = mapping
deleted_edge = EdgeDeletion(
deleted_mapping = RemoveMapping(
id=_gen_id(),
subject=entity,
about_node=entity,
predicate=predicate,
object=xref,
)
yield deleted_edge
yield deleted_mapping
if mapping_changed_set:
for changes in mapping_changed_set:
object, new_predicate, old_predicate = changes
edge_change = EdgeChange(
mapping_change = MappingPredicateChange(
id=_gen_id(),
about_edge=Edge(subject=entity, predicate=old_predicate, object=object),
about_node=entity,
object=object,
old_value=old_predicate,
new_value=new_predicate,
)

yield edge_change
yield mapping_change

# ! Subset changes
self_subsets = set(self.terms_subsets([entity]))
Expand Down
Loading

0 comments on commit 2baba34

Please sign in to comment.