Improve sparse and structured catalog matching

This commit is contained in:
Fiden committed 2026-08-07 18:31:59 +03:00
1 parent 2982161374
commit 42f8f07207
8 files changed
+739 -20

No files matched your search

+15 -2
View File
@@ -30,7 +30,11 @@ _VOLTAGE_RE = re.compile(
rf"(?<![a-zа-я0-9-])({_NUMBER})\s*(?:v|в|вольт\w*)\b", re.IGNORECASE
)
_POWER_RE = re.compile(rf"\b({_NUMBER})\s*(?:w|вт|ватт\w*)\b", re.IGNORECASE)
_TEETH_RE = re.compile(r"\b(\d+)\s*(?:зуб(?:ьев|а|ов)?|z)\b", re.IGNORECASE)
_TEETH_RE = re.compile(r"\b(\d+)\s*(?:зуб(?:ьев|а|ов)?|[zt])\b", re.IGNORECASE)
_SAW_COMPACT_RE = re.compile(
rf"(?<![a-zа-я0-9.])({_NUMBER})(?:x|\s+)(\d+)\s*[zt]\b",
re.IGNORECASE,
)
_PACK_SIZE_RE = re.compile(
r"(?:пачк\w*|упаковк\w*|\bуп\.?)(?:\s+(?:по|на))?\s*(\d+)\s*(?:шт\w*)?",
re.IGNORECASE,
@@ -377,8 +381,15 @@ def parse_attributes(
normalized = normalize_text(text)
dimensions = _extract_dimensions(normalized)
compact_saw_match = _SAW_COMPACT_RE.search(normalized)
teeth_match = _TEETH_RE.search(normalized)
teeth = int(teeth_match.group(1)) if teeth_match else None
teeth = (
int(compact_saw_match.group(2))
if compact_saw_match is not None
else int(teeth_match.group(1))
if teeth_match is not None
else None
)
if not dimensions and product_type in _PAIR_DIMENSION_TYPES:
pair_match = _PAIR_WITH_NA_RE.search(normalized)
@@ -395,6 +406,8 @@ def parse_attributes(
mm_values = [_decimal(match.group(1)) for match in _MM_RE.finditer(normalized)]
meter_values = [_decimal(match.group(1)) for match in _METER_RE.finditer(normalized)]
if compact_saw_match is not None:
mm_values.append(_decimal(compact_saw_match.group(1)))
# ``190 на 48 зубьев`` describes diameter and tooth count, not 190x48.
saw_pair = re.search(