| from __future__ import annotations |
|
|
| import json |
| import sys |
| from pathlib import Path |
|
|
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| if str(ROOT) not in sys.path: |
| sys.path.insert(0, str(ROOT)) |
|
|
| from answering import evaluate_query |
| from clause_retrieval import evaluate_clause_query |
| from engine import bootstrap_once |
| from proof_bundle import parse_and_validate_llm_claims |
|
|
|
|
| FALSE_DUTY_QUESTION = ( |
| "Üniversiteler alt düzeydeki kurumlara eğitim vermekle yükümlü müdür? " |
| "Bununla ilgili madde var mı?" |
| ) |
|
|
|
|
| def _synthetic_proof() -> dict: |
| return { |
| "evidence": [ |
| { |
| "evidence_id": "EV-F", |
| "article_title": "Üniversite", |
| "source_text": "f) Ön lisans düzeyinde ara insangücü yetiştiren meslek yüksekokulları;", |
| }, |
| { |
| "evidence_id": "EV-G", |
| "article_title": "Üniversite", |
| "source_text": ( |
| "g) Belirli bilimsel ve teknolojik alanlarda araştırma ve uygulama " |
| "yapmakla yükümlü araştırma ve uygulama merkezleri;" |
| ), |
| }, |
| ] |
| } |
|
|
|
|
| def main() -> int: |
| failures: list[str] = [] |
|
|
| invented = json.dumps( |
| { |
| "claims": [ |
| { |
| "type": "synthesis", |
| "text": ( |
| "Üniversiteler meslek yüksekokulları aracılığıyla alt düzeydeki " |
| "kurumlara eğitim vermekle yükümlüdür." |
| ), |
| "evidence_ids": ["EV-F", "EV-G"], |
| } |
| ] |
| }, |
| ensure_ascii=False, |
| ) |
| if parse_and_validate_llm_claims(invented, _synthetic_proof()): |
| failures.append("cross-evidence invented duty passed claim validation") |
|
|
| valid = json.dumps( |
| { |
| "claims": [ |
| { |
| "type": "atomic", |
| "text": ( |
| "Araştırma ve uygulama merkezleri belirli bilimsel ve teknolojik " |
| "alanlarda araştırma ve uygulama yapmakla yükümlüdür." |
| ), |
| "evidence_ids": ["EV-G"], |
| } |
| ] |
| }, |
| ensure_ascii=False, |
| ) |
| if len(parse_and_validate_llm_claims(valid, _synthetic_proof())) != 1: |
| failures.append("directly grounded research-center duty was rejected") |
|
|
| bootstrap_once() |
| internal = evaluate_clause_query(FALSE_DUTY_QUESTION) |
| proof = internal.get("proof_bundle", {}) or {} |
| contract = proof.get("relation_contract", {}) or {} |
| public_result = evaluate_query(FALSE_DUTY_QUESTION) |
| answer = str(public_result.get("answer", "") or "") |
| if proof.get("status") != "insufficient": |
| failures.append(f"false duty proof status: {proof.get('status')}") |
| if not contract.get("required") or contract.get("aligned"): |
| failures.append(f"false duty relation contract was not rejected: {contract}") |
| if "çıkarılamaz" not in answer: |
| failures.append(f"contrastive grounded abstention missing: {answer}") |
| if "eğitim vermekle yükümlüdür" in answer: |
| failures.append("false university duty leaked into public answer") |
|
|
| positive = evaluate_clause_query( |
| "Araştırma ve uygulama merkezleri araştırma ve uygulama yapmakla yükümlü müdür?", |
| allowed_documents=["TR-KANUN-2809"], |
| allowed_articles=["Madde 3"], |
| ) |
| positive_proof = positive.get("proof_bundle", {}) or {} |
| positive_contract = positive_proof.get("relation_contract", {}) or {} |
| if positive_proof.get("status") != "supported" or not positive_contract.get("aligned"): |
| failures.append( |
| "explicit research-center duty did not pass: " |
| f"status={positive_proof.get('status')} contract={positive_contract}" |
| ) |
|
|
| print(f"Context-chain checks: {len(failures)} failure(s)") |
| for failure in failures: |
| print("FAIL:", failure) |
| return 1 if failures else 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|