def _use_pattern_dict()

in src/engine/step2/disambiguation_helpers.py [0:0]


def _use_pattern_dict(name, standard2pattern):
    """Standarize a name based on pre-defined mappings and regex matching.

    Args:
        name (str): Name to be standarized.
        standard2pattern (dict): Dictionary where key are the standarized names and values are the matching patterns.

    Returns:
        str: Returns standarized name if found. Else '[NOT FOUND]-name'

    """
    for standard, pattern in standard2pattern.items():
        if re.match(pattern, name):
            return standard
    return f"[NOT FOUND]-{name}"

    # Error handeling
    standards = "".join([i[0] for i in standard2pattern])
    raise ValueError(
        f"Name {name} don't match any pattern in dict with standards: {standards}"
    )