Skip to content

Commit e2335ba

Browse files
author
Stan Vertessen
committed
Add ontology metadata to repository
- Add ontology/ directory with owl-uwp-oslo-cp.ttl - Update check_rdf.py to validate both concept schemes and ontology files - Update README.md to document repository structure and validation approach - Concept schemes validated with SHACL, ontology files validated syntax-only
1 parent ed13ff9 commit e2335ba

File tree

3 files changed

+1660
-11
lines changed

3 files changed

+1660
-11
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
IN PROGRESS: de codelijsten zijn nog niet in gebruik.
44

5-
Deze repository omvat een aantal codelijsten voor het uitwisselingsplatform https://data.uitwisselingsplatform.be.
5+
Deze repository omvat een aantal codelijsten en de ontologie voor het uitwisselingsplatform https://www.uitwisselingsplatform.be.
66

7-
Per codelijst wordt een RDF file in de turtle syntax volgens het [SKOS vocabularium](https://www.w3.org/TR/skos-primer/) toegevoegd aan de directory 'conceptschemes'.
7+
## Repository structuur
8+
9+
De repository bevat twee types metadata:
10+
11+
1. **Concept schemes** (`conceptschemes/` directory): Per codelijst wordt een RDF file in de turtle syntax volgens het [SKOS vocabularium](https://www.w3.org/TR/skos-primer/) toegevoegd aan de directory 'conceptschemes'.
12+
13+
2. **Ontologie** (`ontology/` directory): De OWL ontologie die de datamodellen voor het uitwisselingsplatform definieert. De ontologie bestanden worden alleen op syntax gevalideerd (geen SHACL validatie).
814

915
# vormafspraken over de codelijsten
1016

@@ -31,5 +37,14 @@ skos:related | verwijzing naar een gerelateerd concept.
3137
- gebruik language-tagged strings i.p.v. plain literals
3238
Dus `"mijn label@nl` i.p.v. `"mijn label"`
3339

34-
- We verwachten een hierarchie in 1 richting. Het is voldoende om de hierarchie in 1 richting uit te drukken. Het is aan de afnemers om indien voor hen nodig ook de omgekeerde relatie te berekenen. Dat maakt de data ook overzichtelijk.
40+
- We verwachten een hierarchie in 1 richting. Het is voldoende om de hierarchie in 1 richting uit te drukken. Het is aan de afnemers om indien voor hen nodig ook de omgekeerde relatie te berekenen. Dat maakt de data ook overzichtelijk.
41+
42+
## Validatie
43+
44+
De repository bevat een validatiescript (`check_rdf.py`) dat automatisch wordt uitgevoerd bij elke push of pull request:
45+
46+
- **Concept schemes**: Worden gevalideerd op zowel RDF/Turtle syntax als SHACL shapes (zie `shacl_codelists.ttl`)
47+
- **Ontologie**: Worden alleen gevalideerd op RDF/Turtle syntax (geen SHACL validatie)
48+
49+
Zowel concept schemes als ontologie bestanden moeten geldige Turtle syntax hebben om door de validatie te komen.
3550

check_rdf.py

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,68 @@
33
import os
44

55
schemes_dir = './conceptschemes'
6+
ontology_dir = './ontology'
67

78
def validate_shape(graph):
89
return validate(data_graph=graph, shacl_graph="shacl_codelists.ttl")
910

10-
def validate_turtle(file_path):
11+
def validate_turtle_with_shacl(file_path):
12+
"""Validate a turtle file with SHACL shapes (for concept schemes)."""
1113
try:
1214
g = Graph()
1315
g.parse(file_path, format="turtle")
1416
except Exception as e:
15-
print(f"Error validating {file_path}: {e}")
17+
print(f"Error parsing {file_path}: {e}")
1618
return False
17-
(is_valid, _, failure_reason)= validate_shape(g)
19+
(is_valid, _, failure_reason) = validate_shape(g)
1820
if is_valid:
1921
return True
2022
else:
2123
print(f"Error validating shape {file_path}: {failure_reason}")
2224
return False
23-
24-
for filename_codelist in os.listdir(schemes_dir):
25-
print("### Parsing file ", filename_codelist, "###")
26-
file = os.path.join(schemes_dir, filename_codelist)
27-
validate_turtle(file)
25+
26+
def validate_turtle_syntax_only(file_path):
27+
"""Validate a turtle file syntax only (for ontology files)."""
28+
try:
29+
g = Graph()
30+
g.parse(file_path, format="turtle")
31+
print(f"✓ Syntax validation passed for {file_path}")
32+
return True
33+
except Exception as e:
34+
print(f"Error validating syntax {file_path}: {e}")
35+
return False
36+
37+
# Track validation results
38+
all_valid = True
39+
40+
# Validate concept schemes with SHACL
41+
if os.path.exists(schemes_dir):
42+
print("### Validating concept schemes ###")
43+
for filename_codelist in os.listdir(schemes_dir):
44+
if filename_codelist.endswith('.ttl'):
45+
print(f"### Parsing file {filename_codelist} ###")
46+
file = os.path.join(schemes_dir, filename_codelist)
47+
if not validate_turtle_with_shacl(file):
48+
all_valid = False
49+
else:
50+
print(f"Warning: {schemes_dir} directory not found")
51+
52+
# Validate ontology files with syntax-only check
53+
if os.path.exists(ontology_dir):
54+
print("\n### Validating ontology files ###")
55+
for filename_ontology in os.listdir(ontology_dir):
56+
if filename_ontology.endswith('.ttl'):
57+
print(f"### Parsing file {filename_ontology} ###")
58+
file = os.path.join(ontology_dir, filename_ontology)
59+
if not validate_turtle_syntax_only(file):
60+
all_valid = False
61+
else:
62+
print(f"Warning: {ontology_dir} directory not found")
63+
64+
# Exit with appropriate code
65+
if not all_valid:
66+
print("\n❌ Validation failed. Please fix the errors above.")
67+
exit(1)
68+
else:
69+
print("\n✓ All validations passed.")
70+
exit(0)

0 commit comments

Comments
 (0)