Merge pull request #2384 from syfyra/fix/awc-names-family-suffix-number

awc_names: number family members by their suffix (AWC-NAMES-FAMILY-SUFFIX-NUMBER)
This commit is contained in:
Aslan2142
2026-12-01 16:21:47 +01:00
committed by GitHub
2 changed files with 18 additions and 2 deletions

View File

@ -172,6 +172,19 @@ class TestRules(unittest.TestCase):
self.assertNotIn("horn_qqq", d.bases(A.MIN_TOKEN))
self.assertIn("horn_qqq", d.bases(1))
def test_a_digit_that_ends_the_base_is_not_a_member_number(self):
# "2 with adjacent numbers" counts the members' numbered suffixes. The unsuffixed member of a base that ends
# in a digit has no suffix number either: amb_1 + amb_1_02 is no family, as horn + horn_02 is none.
d = A.Dictionary(["amb_1_02", "horn_02"])
for base, names in (("amb_1", ["amb_1", "amb_1_02"]), ("horn", ["horn", "horn_02"])):
with self.subTest(base):
self.assertEqual(A.attack(d, [base], self.index({"b": names}), ""), {})
# Two adjacent suffixes, or three members, still make a family on such a base.
for names in (["amb_1_01", "amb_1_02"], ["amb_1", "amb_1_02", "amb_1_05"]):
with self.subTest(names):
found = A.attack(d, ["amb_1"], self.index({"b": names}), "")
self.assertEqual(sorted(v[0] for v in found.values()), sorted(names))
def test_family_ok(self):
self.assertTrue(A.family_ok(["a_01", "a_02"]))
self.assertFalse(A.family_ok(["a_01", "a_03"]))

View File

@ -303,8 +303,11 @@ def _attack_split(dictionary: Dictionary, bases: list, index: Index, salt: str)
for b in banks:
families[(b, base)][i] = (salt + base + s, verbatim)
family_hits = {}
for (b, _base), members in families.items():
if family_ok(n for n, _v in members.values()) and any(v for _n, v in members.values()):
for (b, base), members in families.items():
# Number the members by their suffix (`_02`), not by a digit that ends the base: the unsuffixed member of
# `amb_1` has no number, as the one of `amb` has none, so `amb_1` + `amb_1_02` is no family.
cut = len(salt) + len(base)
if family_ok(n[cut:] for n, _v in members.values()) and any(v for _n, v in members.values()):
size = len(members)
for i, (name, _v) in members.items():
prev = family_hits.get((b, i))