Spaces:
Running on Zero

File size: 2,558 Bytes
63e6dfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Contrôle qualité déterministe : tout chiffre / sigle / ID du CV généré doit exister dans la base."""
import re
from .kb import norm

NUM = re.compile(r"\d+(?:[.,]\d+)?")
ACR = re.compile(r"\b[A-Z][A-Z0-9/&+]{1,}[A-Z0-9]\b|\b[A-Z]{2,}\b")
# sigles génériques tolérés (pas des compétences)
OK_ACR = {"CV", "FR", "EN", "OK", "SA", "SARL"}


def _kb_text(kb) -> str:
    parts = [kb["profile_base"]["fr"], kb["profile_base"]["en"]]
    for e in kb["experiences"]:
        parts += [e["title_fr"], e["title_en"], e["company"]] + [b[k] for b in e["bullets"] for k in ("fr", "en")]
    parts += [s[k] for s in kb["skills"] for k in ("fr", "en")]
    parts += [c["name"] for c in kb["certifications"]]
    return " ".join(parts)


def verify(cv: dict, kb, valid_src: set) -> list[str]:
    issues, ktext = [], _kb_text(kb)
    knums = set(NUM.findall(ktext))
    kacr = set(ACR.findall(ktext)) | OK_ACR
    kn = norm(ktext)
    exp_ids = {e["id"] for e in kb["experiences"]}
    skill_txt = {norm(s[k]) for s in kb["skills"] for k in ("fr", "en")}

    def check(text, where):
        for n in NUM.findall(text):
            if n not in knums:
                issues.append(f"{where}: chiffre '{n}' absent de la base")
        for a in ACR.findall(text):
            if a not in kacr:
                issues.append(f"{where}: sigle '{a}' absent de la base")

    check(cv.get("summary", ""), "résumé")
    for s in cv.get("summary_src", []):
        if s not in valid_src: issues.append(f"résumé: source inconnue {s}")
    if not cv.get("summary_src"): issues.append("résumé: aucune source citée")
    for e in cv.get("experiences", []):
        if e.get("id") not in exp_ids:
            issues.append(f"expérience inconnue {e.get('id')}"); continue
        for b in e.get("bullets", []):
            check(b.get("text", ""), f"{e['id']}")
            srcs = b.get("src", [])
            if not srcs: issues.append(f"{e['id']}: puce sans source")
            for s in srcs:
                if s not in valid_src: issues.append(f"{e['id']}: source inconnue {s}")
                elif not s.startswith(e["id"] + ".") and not s.startswith("s"):
                    issues.append(f"{e['id']}: source {s} appartient à une autre expérience")
    for s in cv.get("skills", []):
        if norm(s) not in skill_txt: issues.append(f"compétence hors base : '{s}'")
    cert_ids = {c["id"] for c in kb["certifications"]}
    for c in cv.get("cert_ids", []):
        if c not in cert_ids: issues.append(f"certification inconnue {c}")
    return issues