From 11a498ba4e76a56a6797b2f99081f2bf84d8fb0f Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Fri, 22 May 2026 14:55:01 +0000 Subject: [PATCH] =?UTF-8?q?Map=20an=20unrecognised=20classification=20repl?= =?UTF-8?q?y=20to=20UNKNOWN=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatgpt/chatgpt_property_type_classifier.py | 10 +++++++++- .../chatgpt/test_chatgpt_property_type_classifier.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/infrastructure/chatgpt/chatgpt_property_type_classifier.py b/infrastructure/chatgpt/chatgpt_property_type_classifier.py index d4f0c060..75ec1556 100644 --- a/infrastructure/chatgpt/chatgpt_property_type_classifier.py +++ b/infrastructure/chatgpt/chatgpt_property_type_classifier.py @@ -33,6 +33,14 @@ class ChatGptPropertyTypeClassifier(PropertyTypeClassifier): ) raw: dict[str, Any] = json.loads(reply) return { - description: PropertyType(raw[description]) + description: self._to_property_type(raw[description]) for description in descriptions } + + @staticmethod + def _to_property_type(value: Any) -> PropertyType: + """Map a reply value to a PropertyType, defaulting to UNKNOWN.""" + try: + return PropertyType(value) + except ValueError: + return PropertyType.UNKNOWN diff --git a/tests/infrastructure/chatgpt/test_chatgpt_property_type_classifier.py b/tests/infrastructure/chatgpt/test_chatgpt_property_type_classifier.py index 8c697eb2..d4801154 100644 --- a/tests/infrastructure/chatgpt/test_chatgpt_property_type_classifier.py +++ b/tests/infrastructure/chatgpt/test_chatgpt_property_type_classifier.py @@ -31,3 +31,15 @@ def test_classifies_description_into_property_type() -> None: # Assert assert result == {"semi-detached": PropertyType.HOUSE} + + +def test_unrecognised_category_maps_to_unknown() -> None: + # Arrange + chat_gpt = _FakeChatGPT(reply='{"garden shed": "Shed"}') + classifier = ChatGptPropertyTypeClassifier(chat_gpt) + + # Act + result = classifier.classify({"garden shed"}) + + # Assert + assert result == {"garden shed": PropertyType.UNKNOWN}