diff --git a/domain/epc/property_overrides/roof_party_ceiling_guard.py b/domain/epc/property_overrides/roof_party_ceiling_guard.py index 97cdb09b1..c4b446c3e 100644 --- a/domain/epc/property_overrides/roof_party_ceiling_guard.py +++ b/domain/epc/property_overrides/roof_party_ceiling_guard.py @@ -1,9 +1,23 @@ from __future__ import annotations +import re from typing import Optional from domain.epc.property_overrides.roof_type import RoofType +# The roof-type token (before any ``: `` suffix), normalised to lower +# alphanumerics, → its party-ceiling RoofType member. Normalising strips spacing +# and case so both ``"another dwelling above"`` and ``"anotherdwellingabove"`` +# match the same marker. +_PARTY_CEILING_MARKERS: dict[str, RoofType] = { + "anotherdwellingabove": RoofType.ADJACENT_ANOTHER_DWELLING_ABOVE, +} + + +def _normalise_roof_token(description: str) -> str: + token = description.split(":", 1)[0] + return re.sub(r"[^a-z0-9]", "", token.lower()) + def roof_party_ceiling_guard(description: str) -> Optional[RoofType]: """Deterministically resolve a party-ceiling roof description to its RoofType. @@ -20,4 +34,4 @@ def roof_party_ceiling_guard(description: str) -> Optional[RoofType]: that is not a party-ceiling marker so the LLM classifier still handles it (#1376). """ - raise NotImplementedError + return _PARTY_CEILING_MARKERS.get(_normalise_roof_token(description))