Download engine/verify.py from Alaa75/CV-Engine: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/spaces/Alaa75/CV-Engine/resolve/main/engine/verify.py
- Command line
-
hf download hf://spaces/Alaa75/CV-Engine/engine/verify.py
-
curl -L -o verify.py https://huggingface.co/spaces/Alaa75/CV-Engine/resolve/main/engine/verify.py
2.56 kB
| """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 | |