mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from enum import Enum
|
|
from typing import Generic, TypeVar
|
|
|
|
E = TypeVar("E", bound=Enum)
|
|
|
|
|
|
class ClassificationError(Exception):
|
|
"""Raised when classifying a column's descriptions fails wholesale.
|
|
|
|
A whole-batch failure (the AI backend is unreachable, or returns a reply
|
|
that cannot be parsed) raises this. A single description that merely
|
|
cannot be resolved is not an error -- it maps to the enum's UNKNOWN member.
|
|
"""
|
|
|
|
|
|
class BaseColumnClassifier(ABC, Generic[E]):
|
|
"""Adapter base: shared scaffolding for concrete column classifiers.
|
|
|
|
One classifier handles one landlord-CSV column. Implementations decide
|
|
*how* the mapping is performed (an LLM, a lookup table, a rules engine).
|
|
Consumers do not depend on this class -- they depend on the structural
|
|
``ColumnClassifier`` Protocol declared in the orchestration layer; this
|
|
ABC merely gives adapters a common base for the ``classify`` contract.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def classify(self, descriptions: set[str]) -> dict[str, E]:
|
|
"""Classify each description into a category enum member.
|
|
|
|
Every input description appears as a key in the result. A description
|
|
that cannot be resolved maps to the enum's UNKNOWN member.
|
|
|
|
Raises:
|
|
ClassificationError: If the classification call fails wholesale
|
|
(e.g. the backend is unreachable or returns an unparseable
|
|
response).
|
|
"""
|
|
...
|