invert_by_prefix_pair

invert_by_prefix_pair(mappings: Iterable[MappingTypeVar], source_prefix: str, object_prefix: str, *, converter: Converter, justification_policy: InversionJustificationPolicy | str | None = None) Iterable[MappingTypeVar][source]

Invert mappings with the given subject and object (SO) prefixes.

Parameters:
  • mappings – An iterable of semantic mappings

  • source_prefix – Invert mappings that have this source prefix

  • object_prefix – Invert mappings that have this object prefix

  • converter – A converter function hashing the mapping to fill the “derives_from” field

  • justification_policy – The policy for how the original evidence is mutated during inversion. Defaults to InversionDerivationPolicy.retain, where the original justification is retained

Returns:

An iterable of semantic mappings, with the correct ones inverted

>>> from curies import Converter
>>> from curies.vocabulary import mapping_inversion
>>> from sssom_pydantic import SemanticMapping, NOT, hash_triple_to_reference
>>> converter = Converter.from_prefix_map(
...     {
...         "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
...         "mesh": "http://id.nlm.nih.gov/mesh/",
...         "skos": "http://www.w3.org/2004/02/skos/core#",
...         "semapv": "https://w3id.org/semapv/vocab/",
...         "mapping": "https://w3id.org/mapping/",
...     }
... )
>>> m1 = SemanticMapping.exact("mesh:C000089", "CHEBI:28646")
>>> m1_inv = SemanticMapping.exact(
...     "CHEBI:28646",
...     "mesh:C000089",
...     derived_from=[hash_triple_to_reference(m1, converter)],
... )
>>> m2 = SemanticMapping.exact("CHEBI:10001", "mesh:C067604")
>>> assert [m1_inv, m2] == list(
...     invert_by_prefix_pair([m1, m2], "mesh", "CHEBI", converter=converter)
... )