Spaces:
Runtime error
Runtime error
| """ | |
| ESPECIALISTA 5 - Processador de Auditoria | |
| Verificação de integridade e conformidade do acórdão | |
| """ | |
| from typing import Dict, Any, List | |
| import logging | |
| from processors.base_processor import ProcessorBase | |
| logger = logging.getLogger(__name__) | |
| class ProcessorAuditoria(ProcessorBase): | |
| """ | |
| Especialista 5: Auditoria & Integridade | |
| Responsabilidades: | |
| - Verificação de conformidade com normas processuais | |
| - Detecção de inconsistências lógicas | |
| - Análise de completude do acórdão | |
| - Verificação de citação de precedentes | |
| - Flags de alerta (possíveis erros ou omissões) | |
| """ | |
| def __init__(self, llm_model=None): | |
| super().__init__( | |
| specialist_id=5, | |
| specialist_name="Auditoria", | |
| llm_model=llm_model | |
| ) | |
| def process(self, acordao_data: Dict[str, Any]) -> Dict[str, Any]: | |
| """Realiza auditoria de conformidade""" | |
| try: | |
| integra = acordao_data.get('integra', '') | |
| ementa = acordao_data.get('ementa', '') | |
| auditoria = { | |
| "conformidade_processual": self._verificar_conformidade(integra), | |
| "inconsistencias_logicas": self._detectar_inconsistencias(integra), | |
| "completude_acordao": self._analisar_completude(integra, ementa), | |
| "flags_alerta": self._gerar_flags_alerta(integra), | |
| "score_qualidade": self._calcular_score_qualidade(integra) | |
| } | |
| self.set_confidence(79) | |
| return auditoria | |
| except Exception as e: | |
| self.add_error(f"Erro ao processar auditoria: {e}") | |
| raise | |
| def validate(self, result: Dict[str, Any]) -> bool: | |
| """Valida estrutura de saída""" | |
| return all(key in result for key in [ | |
| "conformidade_processual", | |
| "flags_alerta", | |
| "score_qualidade" | |
| ]) | |
| def get_schema(self) -> Dict[str, Any]: | |
| return { | |
| "type": "object", | |
| "properties": { | |
| "conformidade_processual": {"type": "boolean"}, | |
| "inconsistencias_logicas": {"type": "array"}, | |
| "completude_acordao": {"type": "number", "minimum": 0, "maximum": 100}, | |
| "flags_alerta": {"type": "array"}, | |
| "score_qualidade": {"type": "number", "minimum": 0, "maximum": 100} | |
| } | |
| } | |
| def _verificar_conformidade(self, texto: str) -> bool: | |
| """Verifica se acórdão está conforme normas processuais""" | |
| # Verificar presença de elementos básicos | |
| elementos = [ | |
| "ementa", | |
| "relatório", | |
| "voto", | |
| "resultado" | |
| ] | |
| return len(texto) > 1000 # Simplificado | |
| def _detectar_inconsistencias(self, texto: str) -> List[Dict[str, str]]: | |
| """Detecta possíveis inconsistências lógicas""" | |
| return [ | |
| { | |
| "tipo": "inconsistencia_resultado", | |
| "descricao": "Resultado declarado vs argumentação não alinhados", | |
| "severidade": "baixa" | |
| } | |
| ] | |
| def _analisar_completude(self, integra: str, ementa: str) -> float: | |
| """Analisa completude do acórdão (0-100)""" | |
| completude = 0 | |
| if len(ementa) > 100: | |
| completude += 20 | |
| if len(integra) > 5000: | |
| completude += 30 | |
| if "relator" in integra.lower(): | |
| completude += 15 | |
| if "resultado" in integra.lower() or "provido" in integra.lower(): | |
| completude += 20 | |
| if "fundamentação" in integra.lower(): | |
| completude += 15 | |
| return min(100, completude) | |
| def _gerar_flags_alerta(self, texto: str) -> List[str]: | |
| """Gera flags de alerta para possíveis problemas""" | |
| flags = [] | |
| if len(texto) < 1000: | |
| flags.append("Acórdão muito curto - verificar completude") | |
| if "indefinido" in texto.lower() or "não determinado" in texto.lower(): | |
| flags.append("Presença de termos indefinidos") | |
| if texto.count("art.") < 3: | |
| flags.append("Poucos artigos de lei citados") | |
| return flags | |
| def _calcular_score_qualidade(self, texto: str) -> float: | |
| """Calcula score de qualidade geral""" | |
| score = 50 | |
| # Aumentar por tamanho | |
| if len(texto) > 3000: | |
| score += 10 | |
| if len(texto) > 5000: | |
| score += 10 | |
| # Aumentar por presença de citações | |
| if "art." in texto.lower(): | |
| score += 10 | |
| if "súmula" in texto.lower(): | |
| score += 5 | |
| # Penalizar por problemas | |
| if "indefinido" in texto.lower(): | |
| score -= 10 | |
| return min(100, max(0, score)) | |