fix: match prefixed contract core aliases
This commit is contained in:
@@ -59,12 +59,27 @@ def _contract_number_identity(number):
|
|||||||
normalized = str(number or "").upper().translate(_HOMOGLYPHS)
|
normalized = str(number or "").upper().translate(_HOMOGLYPHS)
|
||||||
prefix_match = re.match(r"^(?:XXX|ХХХ)\d+[-_/](.+)$", normalized)
|
prefix_match = re.match(r"^(?:XXX|ХХХ)\d+[-_/](.+)$", normalized)
|
||||||
if not prefix_match:
|
if not prefix_match:
|
||||||
return {"full": full_key, "suffix": full_key, "prefixed": False}
|
suffix_aliases = [full_key]
|
||||||
|
numbered_suffix = re.match(r"^(.+)_\d+$", normalized)
|
||||||
|
if numbered_suffix:
|
||||||
|
core_key = canonicalize_contract_number(numbered_suffix.group(1))
|
||||||
|
if sum(character.isdigit() for character in core_key) >= 4:
|
||||||
|
suffix_aliases.append(core_key)
|
||||||
|
return {
|
||||||
|
"full": full_key, "suffix": full_key,
|
||||||
|
"suffix_aliases": suffix_aliases, "prefixed": False,
|
||||||
|
}
|
||||||
suffix_key = canonicalize_contract_number(prefix_match.group(1))
|
suffix_key = canonicalize_contract_number(prefix_match.group(1))
|
||||||
digit_count = sum(character.isdigit() for character in suffix_key)
|
digit_count = sum(character.isdigit() for character in suffix_key)
|
||||||
if digit_count < 4:
|
if digit_count < 4:
|
||||||
return {"full": full_key, "suffix": full_key, "prefixed": True}
|
return {
|
||||||
return {"full": full_key, "suffix": suffix_key, "prefixed": True}
|
"full": full_key, "suffix": full_key,
|
||||||
|
"suffix_aliases": [full_key], "prefixed": True,
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"full": full_key, "suffix": suffix_key,
|
||||||
|
"suffix_aliases": [suffix_key], "prefixed": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def canonicalize_counterparty(name, inn):
|
def canonicalize_counterparty(name, inn):
|
||||||
@@ -112,7 +127,12 @@ def _shared_contract_match(left_keys, right_keys):
|
|||||||
for right_key, right in right_keys.items():
|
for right_key, right in right_keys.items():
|
||||||
if left_key == right_key:
|
if left_key == right_key:
|
||||||
return left_key, left, right
|
return left_key, left, right
|
||||||
same_suffix = left.get("suffix") == right.get("suffix")
|
if left.get("prefixed") and not right.get("prefixed"):
|
||||||
|
same_suffix = left.get("suffix") in right.get("suffix_aliases", [])
|
||||||
|
elif right.get("prefixed") and not left.get("prefixed"):
|
||||||
|
same_suffix = right.get("suffix") in left.get("suffix_aliases", [])
|
||||||
|
else:
|
||||||
|
same_suffix = left.get("suffix") == right.get("suffix")
|
||||||
if same_suffix and (left.get("prefixed") or right.get("prefixed")):
|
if same_suffix and (left.get("prefixed") or right.get("prefixed")):
|
||||||
if left.get("prefixed") and right.get("prefixed"):
|
if left.get("prefixed") and right.get("prefixed"):
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user