Skip to content

[Demo] Implement mapping sameness identifier - #658

Draft
cthoyt wants to merge 7 commits into
masterfrom
mapping-sameness-identifier
Draft

[Demo] Implement mapping sameness identifier#658
cthoyt wants to merge 7 commits into
masterfrom
mapping-sameness-identifier

Conversation

@cthoyt

@cthoyt cthoyt commented Apr 17, 2026

Copy link
Copy Markdown
Member

Part of #657

This demo PR shows how the mapping sameness identifier could be implemented.

However, it needs a design. How would someone using sssom-py use this, considering that the primary data structure is a dataframe, whose columns correspond to SSSOM fields?

@gouttegd

gouttegd commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

However, it needs a design. How would someone using sssom-py use this, considering that the primary data structure is a dataframe, whose columns correspond to SSSOM fields?

Well, your proposed design (i.e. a method on the MappingSetDataFrame class which returns a list of hashes) doesn’t look too bad to me. It’s consistent with the idea that the MappingSetDataFrame is, in SSSOM-Py, the primary way of manipulating SSSOM sets.

For convenience, maybe the method could take an optional parameter to filter the rows of the dataframe, so that if the caller only wants the hash for one particular record (or a particular group of records), the method would only return the hash(es) for the selected record(s).

Something like:

def get_mapping_sameness_identifiers(self, selector=None) -> list[str]:
    """Get mapping sameness identifiers for all records (selector == None) or all selected records."""
    if selector is not None:
        df = self.df.loc[selector]
    else:
        df = self.df
    expand = partial(self.converter.expand, strict=True)
    return [
        encode_uri_triple(
            (expand(subject_curie), expand(predicate_curie), expand(object_curie)),
            negate=predicate_modifier == "Not",
        )
        for subject_curie, predicate_curie, object_curie, predicate_modifier in df[
            ["subject_id", "predicate_id", "object_id", "predicate_modifier"]
        ].values
    ]

If you want all the hashes, just call msdf.get_mapping_sameness_identifiers().

If you only want the hash for the second record, call msdf.get_mapping_sameness_identifiers(selector=[2]) (beware that the method will still return a list, even if it contains a single hash).

If you only want the hash for the records whose subject ID is EX:123, call msdf.get_mapping_sameness_identifiers(selector=msdf.df["subject_id"] == "EX:123").

Etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants