feat(extraction): assess_quality — statut qualité dossier (4 niveaux)
complete / partial / needs_review / failed (priorité décroissante), matching rôle requis insensible casse+espaces, seuil min_confidence paramétrable (0.6). 16 tests ajoutés (31 au total, verts). Brique TDD via sous-agent, code révisé. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -189,6 +189,48 @@ def parse_vlm_json(text: str) -> dict:
|
||||
return {}
|
||||
|
||||
|
||||
def _norm_label(label: str) -> str:
|
||||
"""Normalise un label pour comparaison : minuscules + strip espaces."""
|
||||
return label.strip().lower()
|
||||
|
||||
|
||||
def assess_quality(
|
||||
fields: Sequence[MappedField],
|
||||
required_roles: Optional[Sequence[str]] = None,
|
||||
min_confidence: float = 0.6,
|
||||
) -> str:
|
||||
"""Évalue la qualité d'extraction d'un dossier à partir des champs reconstruits.
|
||||
|
||||
Renvoie l'un des 4 statuts (par priorité décroissante) :
|
||||
- "failed" : aucun champ, OU aucun champ ancré.
|
||||
- "needs_review" : au moins un rôle requis absent ou non ancré.
|
||||
- "partial" : rôles requis ok mais confidence insuffisante OU champs non ancrés.
|
||||
- "complete" : tout ancré, toutes confidences >= min_confidence, aucun non ancré.
|
||||
|
||||
Le matching required_role ↔ field.label est insensible à la casse et aux espaces.
|
||||
"""
|
||||
# --- failed : aucun champ du tout, ou aucun ancré ---
|
||||
anchored = [f for f in fields if f.anchored]
|
||||
if not fields or not anchored:
|
||||
return "failed"
|
||||
|
||||
# --- needs_review : rôle requis absent ou non ancré ---
|
||||
if required_roles:
|
||||
anchored_labels = {_norm_label(f.label) for f in anchored}
|
||||
for role in required_roles:
|
||||
if _norm_label(role) not in anchored_labels:
|
||||
return "needs_review"
|
||||
|
||||
# --- partial : confidence basse sur un champ ancré OU champs non ancrés ---
|
||||
has_low_confidence = any(f.confidence < min_confidence for f in anchored)
|
||||
has_unanchored = any(not f.anchored for f in fields)
|
||||
if has_low_confidence or has_unanchored:
|
||||
return "partial"
|
||||
|
||||
# --- complete ---
|
||||
return "complete"
|
||||
|
||||
|
||||
def map_roles(
|
||||
image_path: str,
|
||||
tokens: Sequence[OcrToken],
|
||||
|
||||
Reference in New Issue
Block a user