"""D5b · ACCO. Empresas responsables según el fallo, por reglas (interno, 700): copia de d5/py/fallo_d5.py con config_acco; el bloque empieza en el último «RESUELVE»/«RESOL» (la ACCO no escribe «Primero. Declarar…») y acaba en «Acordar comunicar»/«Firmas». Marca d5b-fallo-acco.""" import re, json, sys, glob sys.path.insert(0, '/colusion/d5b/py') from config_acco import CASOS D = '/colusion/d5b/interno/texto_acco/' INI = re.compile(r'\b(?:RESUELVE|RESOL)\b') # d5b-fallo-acco FIN = re.compile(r'(?i)Comun[íi]quese|Notif[íi]quese|Comuniqueu|Notifiqueu|VOTO PARTICULAR|Contra esta resoluci|Acordar comunicar|\(Firmas\)|\(Signatures\)|Firmas\.') FJ = r'(?:S\.?\s?A\.?\s?U\.?|S\.?\s?L\.?\s?U\.?|S\.?\s?L\.?\s?P\.?|S\.?\s?L\.?(?!\w)|S\.?\s?A\.?\s?L\.?|S\.?\s?A\.?(?!\w)|S\.?\s?C\.?\s?A\.?|S\.?\s?COOP\.?|SOCIEDAD COOPERATIVA ANDALUZA|SOCIEDAD AN[ÓO]NIMA|SOCIEDAD LIMITADA|SL|SA|SLU|SAU)' RX = re.compile(r"((?:[A-ZÁÉÍÓÚÑÇÀÈÒÏÜ0-9][A-ZÁÉÍÓÚÑÇÀÈÒÏÜ0-9&'.,/-]*\s+){0,9}?[A-ZÁÉÍÓÚÑÇÀÈÒÏÜ0-9][A-ZÁÉÍÓÚÑÇÀÈÒÏÜ0-9&'.-]*),?\s+" + FJ + r"(?![a-z])", re.I) NIF = re.compile(r'\b([A-HJNP-SUVW])[-\s.]?(\d{7})[-\s.]?([0-9A-J])\b') CONECT = {'y', 'e', 'i', 'de', 'del', 'la', 'las', 'los', 'el', 'da', 'do', 'das', 'dos', 'and', '&', 'cía', 'cia'} def limpia(n): """Se queda con la cola de palabras que empiezan por mayúscula o cifra (con conectores) y quita guiones de corte de línea.""" n = re.sub(r'(\w)- (\w)', r'\1\2', n) n = re.sub(r'\s*Página \d+ de \d+\s*', ' ', n).strip() toks = n.split(); cola = [] for tk in reversed(toks): if tk[:1].isupper() or tk[:1].isdigit() or tk.lower() in CONECT or tk[:1] in '(«“"': cola.append(tk) else: break while cola and cola[-1].lower() in CONECT: cola.pop() return ' '.join(reversed(cola)).strip(' ,.-') out = {} for clave, cfg in CASOS.items(): if cfg['banco'] not in ('positivo',): continue f = sorted(glob.glob(D + glob.escape(cfg['texto']) + '*.txt'))[0] t = re.sub(r'\s+', ' ', open(f, encoding='utf-8', errors='replace').read()) ms = list(INI.finditer(t)) if ms: a = ms[-1].start(); m2 = FIN.search(t, a + 50); b = m2.start() if m2 else min(len(t), a + 30000); via = 'fallo' else: # sin «Declarar acreditada»: último tramo con «(CIF …)» y «sanción» (p. ej. AVC 130-SAN-2016) cifs = [m.start() for m in re.finditer(r'\((?:CIF|NIF)', t)] if not cifs: out[clave] = dict(fallo=False, empresas=[], nifs=[]); continue a = max(0, cifs[0] - 200) if len(t) - cifs[0] < 60000 else max(0, len(t) - 40000); b = len(t); via = 'tramo final con CIF' s = t[a:b] emp = [] for m in RX.finditer(s): n = m.group(1).strip(' ,.-') n = re.sub(r'^(?:Y|E|I|A|DE|LA|LAS|LOS|EL|SU MATRIZ|MATRIZ|SOLIDARIAMENTE|EMPRESA|EMPRESAS|ENTIDAD|ENTIDADES|SIGUIENTES|MERCANTIL|AS|ÁS|AS EMPRESAS|\d+\.?-?)\s+', '', n, flags=re.I) n = re.sub(r'^(?:[\d/.]+\s+)+', '', n).strip(' ,.-') if len(n) < 3 or re.fullmatch(r'[\d.,\s]+', n) or n.upper() in ('LDC', 'TFUE', 'CNMC', 'BOE', 'LCSP'): continue if not re.search(r'[A-ZÁÉÍÓÚÑ]{2}', n): continue n = limpia(n) # d5-limpia-nombres if len(n) >= 3 and n not in emp: emp.append(n) for m in re.finditer(r'[“"«]([^”"»]{3,80}?),?\s+' + FJ + r'[”"»]', s): n = limpia(m.group(1).strip(' ,.-')) if len(n) >= 3 and n not in emp: emp.append(n) nifs = sorted({''.join(g) for g in NIF.findall(s)}) if via != 'fallo': # d5-fallback-sancion: solo pares «RAZÓN SOCIAL (CIF X), una sanción» pares = re.findall(r"((?:[A-ZÁÉÍÓÚÑ0-9][A-ZÁÉÍÓÚÑ0-9&'.-]*,?\s+){1,10}?" + FJ + r")\s*\((?:CIF|NIF)[:\s]*([A-Z]\d{7}[0-9A-J])\),?\s+una\s+sanci", s) emp = [] for n, cif in pares: n2 = limpia(re.sub(FJ + r'$', '', n.strip(' ,')).strip(' ,')) n2 = re.sub(r'^A\s+', '', n2) if n2 and n2 not in emp: emp.append(n2) nifs = sorted({cif for _, cif in pares}) if clave == 'AVC contrato telefónico Bilbao': emp, nifs = [], [] # infracción sin multa: sin V2 (solo V3) out[clave] = dict(fallo=True, via=via, caracteres=b - a, empresas=emp, nifs=nifs) json.dump(out, open('/colusion/d5b/interno/fallo_acco.json', 'w'), ensure_ascii=False, indent=1) for k, v in out.items(): print(f"{k:32s} fallo={v['fallo']} car={v.get('caracteres')} empresas={len(v['empresas'])} nifs={len(v['nifs'])}")