pat2vec.util.methods_get_medcat

Functions

get_cat(config_obj)

Loads and returns a MedCAT model instance based on configuration.

pat2vec.util.methods_get_medcat.get_cat(config_obj)[source]

Loads and returns a MedCAT model instance based on configuration.

This function determines which MedCAT model to load based on the provided

configuration object. It supports several loading strategies:

  1. Dummy Model: If config_obj.testing and config_obj.dummy_medcat_model are True, it returns a dummy_CAT instance for testing without a real model.

  2. Automatic Path Detection: If config_obj.override_medcat_model_path is set to β€œauto”, it searches sys.path for a medcat_models directory and loads the first .zip model pack found.

  3. Explicit Path: It checks for a model path in this order: a. medcat_path variable imported from a local paths.py file. b. config_obj.override_medcat_model_path.

  4. No Model: If config_obj.medcat is False, it returns None.

Parameters:

config_obj (Any) – The configuration object containing settings like testing, medcat, and model paths.

Return type:

Union[CAT, dummy_CAT, None]

Returns:

An instance of a MedCAT CAT object, a dummy_CAT object for testing, or None if MedCAT processing is disabled.

Raises:

ValueError – If MedCAT is enabled but no valid model path can be found. # type: ignore