Support incomplete model suffixes
This commit is contained in:
1 parent
42f8f07207
commit
6a2d912ca5
6 files changed
+113
-5
No files matched your search
+36
-1
@@ -44,6 +44,7 @@ _MODEL_RE = re.compile(
|
||||
r"(?<![a-zа-я0-9])([a-zа-я]{2,6}-\d+[a-zа-я]?|[a-zа-я]{2,6}\d+[a-zа-я]?)(?![a-zа-я0-9])",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
_NORMALIZED_MODEL_RE = re.compile(r"^([a-zа-я]{2,6})(\d+)([a-zа-я]?)$", re.IGNORECASE)
|
||||
|
||||
_PAIR_DIMENSION_TYPES = frozenset(
|
||||
{
|
||||
@@ -229,6 +230,31 @@ def _extract_model_codes(normalized: str) -> frozenset[str]:
|
||||
return frozenset(codes)
|
||||
|
||||
|
||||
def model_code_matches(query_code: str, candidate_code: str) -> bool:
|
||||
"""Match a complete model or a model with only its final letter omitted.
|
||||
|
||||
Numeric parts remain exact. Thus ``арс12`` may complete to
|
||||
``арс12л``, but it must not match the different model ``арс125``.
|
||||
"""
|
||||
|
||||
if query_code == candidate_code:
|
||||
return True
|
||||
|
||||
query_match = _NORMALIZED_MODEL_RE.fullmatch(query_code)
|
||||
candidate_match = _NORMALIZED_MODEL_RE.fullmatch(candidate_code)
|
||||
if query_match is None or candidate_match is None:
|
||||
return False
|
||||
|
||||
query_prefix, query_number, query_suffix = query_match.groups()
|
||||
candidate_prefix, candidate_number, candidate_suffix = candidate_match.groups()
|
||||
return (
|
||||
query_prefix == candidate_prefix
|
||||
and query_number == candidate_number
|
||||
and not query_suffix
|
||||
and bool(candidate_suffix)
|
||||
)
|
||||
|
||||
|
||||
def _detect_sds(normalized: str) -> str | None:
|
||||
flattened = normalized.replace("-", " ")
|
||||
if "sds max" in flattened or "сдс макс" in flattened:
|
||||
@@ -645,7 +671,16 @@ def compare_attributes(
|
||||
return conflict
|
||||
|
||||
if query.model_codes:
|
||||
conflict = require(query.model_codes.issubset(candidate.model_codes), "model")
|
||||
conflict = require(
|
||||
all(
|
||||
any(
|
||||
model_code_matches(query_code, candidate_code)
|
||||
for candidate_code in candidate.model_codes
|
||||
)
|
||||
for query_code in query.model_codes
|
||||
),
|
||||
"model",
|
||||
)
|
||||
if conflict:
|
||||
return conflict
|
||||
|
||||
|
||||
Reference in new issue
Block a user