Improve sparse and structured catalog matching
This commit is contained in:
1 parent
2982161374
commit
42f8f07207
8 files changed
+739
-20
No files matched your search
+15
-2
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user