:py:mod:`medcat.utils.spacy_compatibility` ========================================== .. py:module:: medcat.utils.spacy_compatibility .. autoapi-nested-parse:: This module attempts to read the spacy compatibilty of a model pack and (if necessary) compare it to the installed spacy version. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: medcat.utils.spacy_compatibility._is_spacy_model_folder medcat.utils.spacy_compatibility._find_spacy_model_folder medcat.utils.spacy_compatibility.get_installed_spacy_version medcat.utils.spacy_compatibility.get_installed_model_version medcat.utils.spacy_compatibility._get_name_and_meta_of_spacy_model_in_medcat_modelpack medcat.utils.spacy_compatibility.get_name_and_version_of_spacy_model_in_medcat_modelpack medcat.utils.spacy_compatibility._is_spacy_version_within_range medcat.utils.spacy_compatibility.medcat_model_pack_has_compatible_spacy_model medcat.utils.spacy_compatibility.is_older_spacy_version medcat.utils.spacy_compatibility.medcat_model_pack_has_semi_compatible_spacy_model Attributes ~~~~~~~~~~ .. autoapisummary:: medcat.utils.spacy_compatibility.SPACY_MODEL_REGEX .. py:data:: SPACY_MODEL_REGEX .. py:function:: _is_spacy_model_folder(folder_name) Check if a folder within a model pack contains a spacy model. The idea is to do this without loading the model. That is because the version of the model may be incompatible with what we've got. And as such, loading may not be possible. :param folder_name: The folder to check. :type folder_name: str :Returns: **bool** -- Whether the folder contains a spacy model. .. py:function:: _find_spacy_model_folder(model_pack_folder) Find the spacy model folder in a model pack folder. :param model_pack_folder: The model pack folder :type model_pack_folder: str :raises ValueError: If it's ambiguous or there's no model folder. :Returns: **str** -- The full path to the model folder. .. py:function:: get_installed_spacy_version() Get the spacy version installed currently. :Returns: **str** -- The currently installed spacy verison. .. py:function:: get_installed_model_version(model_name) Get the version of a model installed in spacy. :param model_name: The model name. :type model_name: str :Returns: **str** -- The version of the installed model. .. py:function:: _get_name_and_meta_of_spacy_model_in_medcat_modelpack(model_pack_path) Gets the name and meta information about a spacy model within a medcat model pack. PS: This gets the raw (folder) name of the spacy model. While this is usually (in models created after v1.2.4) identical to the spacy model version, that may not always be the case. :param model_pack_path: The model pack path. :type model_pack_path: str :Returns: **Tuple[str, dict]** -- The name of the spacy model, and the meta information. .. py:function:: get_name_and_version_of_spacy_model_in_medcat_modelpack(model_pack_path) Get the name, version, and compatible spacy versions of a spacy model within a medcat model pack. PS: This gets the real name of the spacy model. While this is usually (in models created after v1.2.4) identical to the folder name, that may not always be the case. :param model_pack_path: The model pack path. :type model_pack_path: str :Returns: **Tuple[str, str, str]** -- The name of the spacy model, its version, and supported spacy version. .. py:function:: _is_spacy_version_within_range(spacy_version_range) Checks whether the spacy version is within the specified range. The expected format of the version range is similar to that used in requirements and/or pip installs. E.g: - >=3.1.0,<3.2.0 - ==3.1.0 - >=3.1.0 - <3.20 :param spacy_version_range: The requires spacy version range. :type spacy_version_range: str :Returns: **bool** -- Whether the specified range is compatible. .. py:function:: medcat_model_pack_has_compatible_spacy_model(model_pack_path) Checks whether a medcat model pack has a spacy model compatible with installed spacy version. :param model_pack_path: The model pack path. :type model_pack_path: str :Returns: **bool** -- Whether the spacy model in the model pack is compatible. .. py:function:: is_older_spacy_version(model_version) Checks if the specified version is older than the installed version. :param model_version: The specified spacy version. :type model_version: str :Returns: **bool** -- Whether the specified version is older. .. py:function:: medcat_model_pack_has_semi_compatible_spacy_model(model_pack_path) Checks whether the spacy model within a medcat model pack is compatible or older than the installed spacy version. This method returns `True` if the spacy model is compatible or released with a lower version number compared to the spacy version currently installed. We've found that most of the time older models will work with a newer version of spacy. Though there is a warning on spacy's side and they do not guarantee 100% compatibility, we've not seen issues so far. E.g for installed spacy 3.4.4 all the following will be suiable: - en_core_web_md-3.1.0 - en_core_web_md-3.2.0 - en_core_web_md-3.3.0 - en_core_web_md-3.4.1 However, for the same version, the following would not be suitable: - en_core_web_md-3.5.0 - en_core_web_md-3.6.0 - en_core_web_md-3.7.1 :param model_pack_path: The model pack path. :type model_pack_path: str :Returns: **bool** -- Whether the spacy model in the model pack is compatible.