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

Fix mapping set inversion #555

Merged
merged 2 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ def invert_mappings(
inverted_df = df_to_invert.rename(
columns=_invert_column_names(list_of_subject_object_columns, columns_invert_map)
)
inverted_df = inverted_df[df.columns]
inverted_df = sort_df_rows_columns(inverted_df, by_rows=False)
inverted_df[PREDICATE_ID] = inverted_df[PREDICATE_ID].map(predicate_invert_map)
if update_justification:
inverted_df[MAPPING_JUSTIFICATION] = SEMAPV.MappingInversion.value
Expand Down
17 changes: 17 additions & 0 deletions tests/data/asymmetric.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#curie_map:
# orcid: https://orcid.org/
# x: http://example.org/x/
# y: http://example.org/y/
# z: http://example.org/z/
#mapping_set_id: https://w3id.org/sssom/mapping/tests/data/asymmetric.tsv
#creator_id:
# - orcid:1234
# - orcid:5678
#license: https://creativecommons.org/publicdomain/zero/1.0/
#mapping_date: 2020-05-30
subject_id subject_label predicate_id object_id mapping_justification object_source confidence
x:appendage appendage owl:equivalentClass y:appendage semapv:ManualMappingCuration y:example 0.841
x:appendage appendage owl:equivalentClass z:appendage semapv:LexicalMatching z:example 0.882
x:appendage appendage owl:equivalentClass z:appendage semapv:ManualMappingCuration z:example 0.841
x:bone_element bone element owl:equivalentClass y:bone semapv:LexicalMatching y:example 0.739
x:bone_element bone element owl:equivalentClass y:bone semapv:ManualMappingCuration y:example 0.535
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ def test_invert_nodes_without_prefix(self):
inverted_df = invert_mappings(df=self.msdf2.df, merge_inverted=False)
self.assertEqual(len(inverted_df), len(self.msdf2.df.drop_duplicates()))

def test_invert_asymmetric_nodes(self):
"""Test inverting sets containing imbalanced subject/object columns."""
msdf = parse_sssom_table(f"{data_dir}/asymmetric.tsv")
inverted_df = invert_mappings(msdf.df, merge_inverted=False)
self.assertEqual(len(inverted_df), len(msdf.df))
original_subject_labels = msdf.df["subject_label"].values
inverted_object_labels = inverted_df["object_label"].values
self.assertNotIn(False, original_subject_labels == inverted_object_labels)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have tried to use something like assertSequenceEqual for this but I zero priority as the current looks correct


def test_inject_metadata_into_df(self):
"""Test injecting metadata into DataFrame is as expected."""
expected_creators = "orcid:0000-0001-5839-2535|orcid:0000-0001-5839-2532"
Expand Down
Loading