get_priority_reference

get_priority_reference(component: Iterable[NormalizedNamableReference], priority: list[str]) NormalizedNamableReference | None[source]

Get the priority reference from a component.

Parameters:
  • component – A set of references with the pre-condition that they’re all “equivalent”

  • priority – A priority list of prefixes, where earlier in the list means the priority is higher

Returns:

Returns the reference with the prefix that has the highest priority. If multiple references have the highest priority prefix, returns the first one encountered. If none have a priority prefix, return None.

>>> from semra import Reference
>>> curies = ["DOID:0050577", "mesh:C562966", "umls:C4551571"]
>>> references = [Reference.from_curie(curie) for curie in curies]
>>> get_priority_reference(references, ["mesh", "umls"]).curie
'mesh:C562966'
>>> get_priority_reference(references, ["DOID", "mesh", "umls"]).curie
'doid:0050577'
>>> get_priority_reference(references, ["hpo", "ordo", "symp"])