-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_schema.py
More file actions
36 lines (30 loc) · 1.21 KB
/
verify_schema.py
File metadata and controls
36 lines (30 loc) · 1.21 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
from rdflib import Graph, Namespace
def verify_ontology_schema(ontology_file):
print(f"Loading {ontology_file}...")
g = Graph()
g.parse(ontology_file, format="turtle")
print(f"Loaded {len(g)} triples.")
EX = Namespace("http://example.org/course-ontology#")
# Expected Predicates
expected_predicates = {
"hasCourse": EX.hasCourse,
"relatedTo": EX.relatedTo,
"hasCourseGrade": EX.hasCourseGrade,
"prerequisite": EX.prerequisite
}
print("\nVerifying Key Predicates:")
all_present = True
for name, uri in expected_predicates.items():
# Check if predicate exists in any triple
if (None, uri, None) in g:
count = len(list(g.triples((None, uri, None))))
print(f"[OK] {name} ({uri}) found in {count} triples.")
else:
print(f"[FAIL] {name} ({uri}) NOT found.")
all_present = False
if all_present:
print("\nSUCCESS: All key predicates verified.")
else:
print("\nWARNING: Some predicates are missing. Check build_ontology.py or the ttl file.")
if __name__ == "__main__":
verify_ontology_schema("course_ontology.ttl")