filter_subsets

filter_subsets(mappings: Iterable[Mapping], prefix_to_references: Mapping[str, list[NormalizedNamableReference]]) list[Mapping][source]

Filter mappings that don’t appear in the given subsets.

Parameters:
  • mappings – An iterable of semantic mappings

  • prefix_to_references

    A dictionary whose keys are prefixes and whose values are collections of references for a subset of terms in the resource to keep.

    In situations where a mapping’s subject or object’s prefix does not appear in this dictionary, the check is skipped.

Returns:

A list that has been filtered based on the prefix_to_identifiers dict

Raises:

ValueError – If CURIEs are given instead of identifiers

If you have a simple configuration dictionary that contains the parent terms, like {"mesh": [Reference.from_curie("mesh:D002477")]}, you’ll want to do the following first:

from semra import Reference
from semra.api import hydrate_subsets, filter_subsets

mappings = [...]
configuration = {"mesh": [Reference.from_curie("mesh:D002477")]}
prefix_to_identifiers = hydrate_subsets(configuration)
filter_subsets(mappings, prefix_to_identifiers)