import re from typing import Tuple, Union THERMAL_TRANSMITTANCE_U_VALUE_REGEX = re.compile(r"(\d+\.\d+)") THERMAL_TRANSMITTANCE_UNIT_REGEX = re.compile(r"(w/m-¦k)") def extract_thermal_transmittence(description_lower: str) -> Tuple[Union[float, None], Union[str, None]]: """ Extracts thermal transmittance from the description. :param description_lower: Lowercase description. :return: Tuple containing U-value and unit. """ # Find U-value u_value = re.search(THERMAL_TRANSMITTANCE_U_VALUE_REGEX, description_lower) if u_value is not None: u_value = float(u_value.group(1)) else: u_value = None # Find unit unit = re.search(THERMAL_TRANSMITTANCE_UNIT_REGEX, description_lower) if unit is not None: unit = unit.group(1) else: unit = None return u_value, unit def search_split_description(desc: str) -> str: """ Searches split descriptions and looks for key words, determining a description about the roof's/floor's insulation. :param desc: Description to be searched. :return: Result of the search. """ outputs = { "insulated": "average", "limited": "below average", "no insulation": "none", "limited insulation": "below average", } out = outputs.get(desc, None) if out: return out raise NotImplementedError("Handle me")