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

rename edge to mapping #775

Merged
merged 10 commits into from
Jun 20, 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
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
Loading