Skip to content

medcat.utils.defaults

Classes:

Functions:

Attributes:

AVOID_LEGACY_CONVERSION_ENVIRON module-attribute

AVOID_LEGACY_CONVERSION_ENVIRON = 'MEDCAT_AVOID_LECACY_CONVERSION'

COMPONENTS_FOLDER module-attribute

COMPONENTS_FOLDER = 'saved_components'

DEFAULT_MINOR_FOR_INFO module-attribute

DEFAULT_MINOR_FOR_INFO = 3

DEFAULT_PACK_NAME module-attribute

DEFAULT_PACK_NAME = 'medcat2_model_pack'

DEFAULT_PATCH_FOR_INFO module-attribute

DEFAULT_PATCH_FOR_INFO = 3

DEFAULT_PYPI_URL module-attribute

DEFAULT_PYPI_URL = 'https://pypi.org/pypi'

DEFAULT_SPACY_MODEL module-attribute

DEFAULT_SPACY_MODEL = 'en_core_web_md'

DEFAULT_VERSION_INFO_LEVEL module-attribute

DEFAULT_VERSION_INFO_LEVEL = 'INFO'

DEFAULT_VERSION_INFO_YANKED_LEVEL module-attribute

DEFAULT_VERSION_INFO_YANKED_LEVEL = 'WARNING'

MEDCAT_DISABLE_VERSION_CHECK_ENVIRON module-attribute

MEDCAT_DISABLE_VERSION_CHECK_ENVIRON = 'MEDCAT_DISABLE_VERSION_CHECK'

MEDCAT_MINOR_UPDATE_THRESHOLD_ENVIRON module-attribute

MEDCAT_MINOR_UPDATE_THRESHOLD_ENVIRON = 'MEDCAT_MINOR_UPDATE_THRESHOLD'

MEDCAT_PATCH_UPDATE_THRESHOLD_ENVIRON module-attribute

MEDCAT_PATCH_UPDATE_THRESHOLD_ENVIRON = 'MEDCAT_PATCH_UPDATE_THRESHOLD'

MEDCAT_PYPI_URL_ENVIRON module-attribute

MEDCAT_PYPI_URL_ENVIRON = 'MEDCAT_PYPI_URL'

MEDCAT_VERSION_UPDATE_LOG_LEVEL_ENVIRON module-attribute

MEDCAT_VERSION_UPDATE_LOG_LEVEL_ENVIRON = 'MEDCAT_VERSION_UPDATE_LOG_LEVEL'

MEDCAT_VERSION_UPDATE_YANKED_LOG_LEVEL_ENVIRON module-attribute

MEDCAT_VERSION_UPDATE_YANKED_LOG_LEVEL_ENVIRON = 'MEDCAT_VERSION_UPDATE_YANKED_LOG_LEVEL'

LegacyConversionDisabledError

LegacyConversionDisabledError(component_name: str)

Bases: Exception

Raised when legacy conversion is disabled.

Source code in medcat-v2/medcat/utils/defaults.py
36
37
38
39
40
def __init__(self, component_name: str):
    super().__init__(
        f"Legacy conversion is disabled (while loading {component_name}). "
        f"Set the environment variable {AVOID_LEGACY_CONVERSION_ENVIRON} "
        "to `False` to allow conversion.")

StatusTypes

Attributes:

ALLOWED_STATUS class-attribute instance-attribute

AUTOMATIC class-attribute instance-attribute

AUTOMATIC = 'A'

DO_DISAMBUGATION class-attribute instance-attribute

MUST_DISAMBIGATE class-attribute instance-attribute

MUST_DISAMBIGATE = 'N'

PRIMARY_STATUS class-attribute instance-attribute

PRIMARY_STATUS_NO_DISAMB class-attribute instance-attribute

PRIMARY_STATUS_NO_DISAMB = 'P'

PRIMARY_STATUS_W_DISAMB class-attribute instance-attribute

PRIMARY_STATUS_W_DISAMB = 'PD'

avoid_legacy_conversion

avoid_legacy_conversion() -> bool
Source code in medcat-v2/medcat/utils/defaults.py
28
29
30
def avoid_legacy_conversion() -> bool:
    return os.environ.get(
        AVOID_LEGACY_CONVERSION_ENVIRON, "False").lower() == "true"

default_weighted_average cached

default_weighted_average(step: int, factor: float = 0.0004) -> float
Source code in medcat-v2/medcat/utils/defaults.py
55
56
57
@lru_cache(maxsize=100)
def default_weighted_average(step: int, factor: float = 0.0004) -> float:
    return max(0.1, 1 - (step ** 2 * factor))

doing_legacy_conversion_message

doing_legacy_conversion_message(logger: Logger, component_name: str, file_path: str = '', level: int = WARNING) -> None
Source code in medcat-v2/medcat/utils/defaults.py
43
44
45
46
47
48
49
50
51
52
def doing_legacy_conversion_message(
        logger: logging.Logger, component_name: str, file_path: str = '',
        level: int = logging.WARNING
        ) -> None:
    logger.log(
        level,
        "Doing legacy conversion on %s (at '%s'). "
        "Set the environment variable %s "
        "to `True` to avoid this.",
        component_name, file_path, AVOID_LEGACY_CONVERSION_ENVIRON)

workers

workers(workers_override: Optional[int] = None) -> int

Get number of workers.

Either the number of workers specified (if done so). Or the number of workers available (i.e cpu count - 1).

Parameters:

  • workers_override

    (Optional[int], default: None ) –

    The number of workers to use. Defaults to None.

Returns:

  • int ( int ) –

    description

Source code in medcat-v2/medcat/utils/defaults.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def workers(workers_override: Optional[int] = None) -> int:
    """Get number of workers.

    Either the number of workers specified (if done so).
    Or the number of workers available (i.e cpu count - 1).

    Args:
        workers_override (Optional[int], optional):
            The number of workers to use. Defaults to None.

    Returns:
        int: _description_
    """
    if workers_override is not None:
        return workers_override
    return max(cpu_count() - 1, 1)