-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
84 lines (68 loc) · 2.59 KB
/
Copy pathmain.py
File metadata and controls
84 lines (68 loc) · 2.59 KB
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
import sys
import json
from pathlib import Path
import requests
from rdflib import Graph
ONTOLOGY_FILE = Path("docs/current/pso.ttl")
FOOPS_API_URL = "https://foops.linkeddata.es/assessOntologyFile"
MIN_FAIR_SCORE = 0.99
def validate_syntax():
print(f"-> [1/2] Checking local RDF syntax ({ONTOLOGY_FILE})...")
g = Graph()
try:
g.parse(ONTOLOGY_FILE, format="turtle")
print("✓ RDF Turtle syntax is valid.")
except Exception as e:
print(f"✗ RDF parsing error: {e}")
sys.exit(1)
def validate_fairness():
print(f"-> [2/2] Running FAIR assessment via FOOPS! API...")
if not ONTOLOGY_FILE.exists():
print(f"✗ File not found: {ONTOLOGY_FILE}")
sys.exit(1)
headers = {
"Accept": "application/json"
}
try:
with open(ONTOLOGY_FILE, "rb") as f:
files = {
"file": (ONTOLOGY_FILE.name, f, "text/turtle")
}
response = requests.post(
FOOPS_API_URL,
files=files,
headers=headers,
timeout=60
)
response.raise_for_status()
data = response.json()
except requests.exceptions.RequestException as e:
print(f"✗ FOOPS! API request failed: {e}")
if 'response' in locals() and response is not None:
print(f"Server response: {response.text}")
sys.exit(1)
overall_score = data.get("overall_score", 0.0)
checks = data.get("checks", [])
print("\n--- FOOPS! FAIR Assessment Report ---")
print(f"Overall FAIR Score: {overall_score * 100:.1f}%\n")
failed_checks = []
for check in checks:
title = check.get("title", check.get("id", "Check"))
status = check.get("status", "unknown")
category = check.get("principle_id", "FAIR")
if status == "passed" or check.get("total_passed_tests", 0) > 0:
print(f" [✓ PASS] [{category}] {title}")
else:
print(f" [✗ FAIL] [{category}] {title}")
failed_checks.append(f"[{category}] {title}: {check.get('description', '')}")
print("-------------------------------------")
if overall_score < MIN_FAIR_SCORE:
print(f"\n✗ Quality Gate Failed: FAIR score ({overall_score * 100:.1f}%) is below the minimum threshold ({MIN_FAIR_SCORE * 100:.1f}%).")
print("\nFailed Checks:")
for err in failed_checks:
print(f" - {err}")
sys.exit(1)
print(f"\n✓ FAIR assessment passed successfully ({overall_score * 100:.1f}%).")
if __name__ == "__main__":
validate_syntax()
validate_fairness()