Spaces:
Runtime error
Runtime error
| ##PARA.AI/core/normalizer.py | |
| """ | |
| Normalizer V13.6 - Fase 1 (Python puro, sem LLM) | |
| Extrai metadados e cria estrutura base | |
| """ | |
| import re | |
| import hashlib | |
| from datetime import datetime | |
| from typing import Dict, Any | |
| class Normalizer: | |
| """Normaliza input e cria estrutura base V13.6""" | |
| def __init__(self): | |
| self.version = "v13.6" | |
| def normalize(self, raw_input: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Normaliza input bruto e retorna estrutura base | |
| INPUT: {"inteiro_teor": "...", "ementa": "...", ...} | |
| OUTPUT: Estrutura V13.6 com campos base preenchidos | |
| """ | |
| # Extrair campos básicos | |
| inteiro_teor = raw_input.get("inteiro_teor", raw_input.get("integra", "")) | |
| ementa = raw_input.get("ementa", "") | |
| # Criar estrutura base | |
| normalized = { | |
| "protocolo_versao": self.version, | |
| "id_manifestacao": raw_input.get("acordaoid", 0), | |
| "hashes": self._generate_hashes(raw_input), | |
| "metadados": self._extract_metadata(raw_input), | |
| "classificacao_tematica": None, # Fase 2.1 | |
| "RELATORIO": None, # Fase 3.1 | |
| "FUNDAMENTACAO": None, # Fase 3.2 | |
| "DECISAO": None, # Fase 3.3 | |
| "analise_arquivista": None, # Fase 4 | |
| "secoes_originais": { | |
| "ementa": ementa, | |
| "inteiro_teor_bruto": inteiro_teor | |
| }, | |
| "metadados_processamento": { | |
| "protocolo_origem": self.version, | |
| "data_processamento": datetime.utcnow().isoformat(), | |
| "versao_preprocessador": "v13.6.0" | |
| }, | |
| "campos_futuros": { | |
| "embeddings_metadata": None | |
| } | |
| } | |
| return normalized | |
| def _generate_hashes(self, raw: Dict[str, Any]) -> Dict[str, str]: | |
| """Gera hashes SHA-256 para deduplicação""" | |
| processo = raw.get("processo", "") | |
| ementa = raw.get("ementa", "") | |
| inteiro_teor = raw.get("inteiro_teor", raw.get("integra", "")) | |
| return { | |
| "hash_numero_processo": hashlib.sha256(processo.encode()).hexdigest() if processo else None, | |
| "hash_ementa": hashlib.sha256(ementa.encode()).hexdigest() if ementa else None, | |
| "hash_inteiro_teor": hashlib.sha256(inteiro_teor.encode()).hexdigest() if inteiro_teor else None | |
| } | |
| def _extract_metadata(self, raw: Dict[str, Any]) -> Dict[str, Any]: | |
| """Extrai metadados básicos""" | |
| return { | |
| "tribunal": "TJPR", | |
| "orgao_julgador": raw.get("orgaojulgador", ""), | |
| "classe_processual": raw.get("classe_processual", ""), | |
| "numeros_processo": [raw.get("processo", "")], | |
| "relator": raw.get("relator", ""), | |
| "data_julgamento": raw.get("datadojulgamento", ""), | |
| "data_publicacao": raw.get("fontedatadapublicacao", ""), | |
| "url_original": raw.get("urldocumento", "") | |
| } | |