mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from typing import Dict, List, Union
|
|
|
|
|
|
class WindowAttributes:
|
|
GLAZING_KEYWORDS = ["glazing", "glazed", "glaze"]
|
|
GLAZING_COVERAGE = ["fully", "mostly", "partial", "some"]
|
|
GLAZING_TYPES = ["double", "triple", "secondary", "multiple", "high performance"]
|
|
|
|
def __init__(self, description: str):
|
|
self.description: str = self._clean_description(description.lower())
|
|
|
|
if not description or not any(
|
|
rt in self.description for rt in
|
|
self.GLAZING_KEYWORDS + self.GLAZING_COVERAGE + self.GLAZING_TYPES
|
|
):
|
|
raise ValueError('Invalid description')
|
|
|
|
def process(self) -> Dict[str, Union[str, bool]]:
|
|
result: Dict[str, Union[str, bool]] = {f'has_{wt.replace(" ", "_")}': False for wt in self.WINDOW_TYPES}
|
|
|
|
description = self.description.split(',')
|
|
|
|
# Process each part separately
|
|
for part in description:
|
|
part = part.strip() # remove leading/trailing white spaces
|
|
self._process_part(result, part, self.WINDOW_TYPES, 'has_')
|
|
|
|
return result
|
|
|
|
@staticmethod
|
|
def _process_part(result: Dict[str, Union[str, bool]], part: str, attr_list: List[str], prefix: str):
|
|
"""
|
|
Process a part of the description with a given list of attributes
|
|
and update the result dictionary.
|
|
"""
|
|
part_words = part.split()
|
|
for attr in attr_list:
|
|
attr_words = attr.split()
|
|
if set(attr_words).issubset(set(part_words)):
|
|
result[f'{prefix}{attr.replace(" ", "_")}'] = True
|
|
|
|
return result
|