Spaces:
Runtime error
Runtime error
File size: 4,906 Bytes
f0322a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
"""
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))
|