import re class Group: def __init__(self, text: str): self.name = text def __repr__(self): return self.name class CombinedGroup: def __init__(self, grpA: Group, grpB: Group): self.clsA = grpA self.clsB = grpB def __repr__(self): return f'{self.clsA}/{self.clsB}' Group_t = Group | CombinedGroup class GroupParser: KIN = Group('Kin.') JUN = Group('Jun.') JUG = Group('Jug.') def __init__(self): self.mapNames = { 'Kin': self.KIN, 'Kin.': self.KIN, 'Kinder': self.KIN, 'Jun': self.JUN, 'Jun.': self.JUN, 'Junioren': self.JUN, 'Jug': self.JUG, 'Jug.': self.JUG, 'Jugend': self.JUG, } def parseClass(self, cls: str) -> Group_t: match = re.compile('^(\\w+\\.?)/(\\w+\\.?)$').match(cls) if match is not None: grpA = self.mapNames[match.group(1)] grpB = self.mapNames[match.group(2)] return CombinedGroup(grpA, grpB) else: return self.mapNames[cls] def isPureClass(self, cls: str) -> bool: parsedClass = self.parseClass(cls) return isinstance(parsedClass, Group)