-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy original repository from x-m-el to cultuurnet
- Loading branch information
Stan Vertessen
committed
Sep 18, 2024
1 parent
89f84b3
commit 8f9d2da
Showing
6 changed files
with
297 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: check rdf syntax | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
name: checkout the repository | ||
- uses: actions/setup-python@v4 | ||
name: install python | ||
with: | ||
python-version: '3.12' | ||
cache: 'pip' | ||
- run: pip install -r requirements.txt | ||
name: install dependencies | ||
shell: sh | ||
- run: python check_rdf.py | ||
name: run the script to check for valid rdf | ||
shell: sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# uitwisselingsplatform-codelijsten | ||
OSLO codelijsten voor data uitwisseling op uitwisselingsplatform | ||
# codelijsten Uitwisselingsplatform | ||
|
||
IN PROGRESS: de codelijsten zijn nog niet in gebruik. | ||
|
||
Deze repository omvat een aantal codelijsten voor het uitwisselingsplatform https://data.uitwisselingsplatform.be. | ||
|
||
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'. | ||
|
||
# vormafspraken over de codelijsten | ||
|
||
|
||
- eigenschappen te gebruiken met conceptschemes: | ||
|
||
|eigenschap | nota | | ||
|-----------|------| | ||
skos:prefLabel | een unieke naam voor het conceptscheme | ||
skos:definition | een definitie van de codelijst | ||
|
||
- eigenschappen te gebruiken met concepts: | ||
|
||
|eigenschap | nota | | ||
|-----------|------| | ||
skos:prefLabel | een unieke naam voor het concept | ||
skos:definition | een definitie van het concept | ||
skos:inscheme | het conceptscheme waartoe dit concept behoort | ||
skos:topConceptOf | het conceptscheme waarvan dit concept een top concept is | ||
skos:broader | de concepten die boven dit concept hangen in de conceptscheme boom. | ||
owl:sameAs | verwijzing naar een identiek concept. | ||
|
||
- gebruik language-tagged strings i.p.v. plain literals | ||
Dus `"mijn label@nl` i.p.v. `"mijn label"` | ||
|
||
- 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from rdflib import Graph | ||
from pyshacl import validate | ||
import os | ||
|
||
schemes_dir = './conceptschemes' | ||
|
||
def validate_shape(graph): | ||
return validate(data_graph=graph, shacl_graph="shacl_codelists.ttl") | ||
|
||
def validate_turtle(file_path): | ||
try: | ||
g = Graph() | ||
g.parse(file_path, format="turtle") | ||
except Exception as e: | ||
print(f"Error validating {file_path}: {e}") | ||
return False | ||
(is_valid, _, failure_reason)= validate_shape(g) | ||
if is_valid: | ||
return True | ||
else: | ||
print(f"Error validating shape {file_path}: {failure_reason}") | ||
return False | ||
|
||
for filename_codelist in os.listdir(schemes_dir): | ||
print("### Parsing file ", filename_codelist, "###") | ||
file = os.path.join(schemes_dir, filename_codelist) | ||
validate_turtle(file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rdflib==7.0.0 | ||
pyshacl==0.25.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
@prefix : <http://skohub.io/skohub-shacl> . | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix xml: <http://www.w3.org/XML/1998/namespace> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix skos: <http://www.w3.org/2004/02/skos/core#> . | ||
@prefix dct: <http://purl.org/dc/terms/> . | ||
@prefix sdo: <https://schema.org> . | ||
@prefix vann: <http://purl.org/vocab/vann/> . | ||
|
||
# ConceptScheme | ||
:ConceptSchemeShape | ||
a sh:NodeShape ; | ||
sh:targetClass skos:ConceptScheme ; | ||
sh:property [ | ||
sh:path skos:prefLabel ; | ||
sh:minCount 1 ; | ||
sh:datatype xsd:string ; | ||
sh:message "Each skos:ConceptScheme has to provide a skos:prefLabel" ; | ||
sh:severity: sh:Violation ; | ||
] ; | ||
sh:property [ | ||
sh:path skos:definition ; | ||
sh:minCount 1 ; | ||
sh:datatype xsd:string ; | ||
sh:message "Each skos:ConceptScheme has to provide a skos:definition" ; | ||
sh:severity: sh:Violation ; | ||
] ; | ||
. | ||
|
||
# Concept | ||
:ConceptShape | ||
a sh:NodeShape ; | ||
sh:targetClass skos:Concept ; | ||
sh:property [ | ||
sh:path skos:prefLabel ; | ||
sh:minCount 1 ; | ||
sh:datatype rdf:langString ; | ||
sh:uniqueLang true ; | ||
sh:message "Each skos:Concept has to provide a skos:prefLabel in a unique language" ; | ||
sh:severity: sh:Violation ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:prefLabel ; | ||
sh:qualifiedValueShape [ | ||
sh:datatype rdf:langString ; | ||
sh:languageIn ("nl") ; | ||
] ; | ||
sh:qualifiedMinCount 1 ; | ||
sh:message "Each skos:Concept has to provide a skos:prefLabel in at least @nl language" ; | ||
] ; | ||
sh:property [ | ||
sh:path skos:definition ; | ||
sh:qualifiedValueShape [ | ||
sh:datatype rdf:langString ; | ||
sh:languageIn ("nl") ; | ||
] ; | ||
sh:qualifiedMinCount 1 ; | ||
sh:message "Each skos:Concept has to provide a skos:definition in at least @nl language" ; | ||
] ; | ||
sh:property [ | ||
sh:path skos:altLabel ; | ||
sh:severity sh:Violation ; | ||
sh:datatype rdf:langString ; | ||
sh:message "Alternative label should be provided with a language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:hiddenLabel ; | ||
sh:severity sh:Violation ; | ||
sh:datatype rdf:langString ; | ||
sh:message "Hidden label should be provided with a language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:definition ; | ||
sh:severity sh:Violation ; | ||
sh:minCount 1 ; | ||
sh:uniqueLang true ; | ||
sh:datatype rdf:langString ; | ||
sh:message "At least one definition should be provided with a unique language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:scopeNote ; | ||
sh:severity sh:Violation ; | ||
sh:datatype rdf:langString ; | ||
sh:message "Scope Note should be provided with a language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:note ; | ||
sh:severity sh:Violation ; | ||
sh:datatype rdf:langString ; | ||
sh:message "Note should be provided with a language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:notation ; | ||
sh:severity sh:Violation ; | ||
sh:datatype xsd:string ; | ||
sh:message "Notation should be provided as a string." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:example ; | ||
sh:severity sh:Violation ; | ||
sh:datatype rdf:langString ; | ||
sh:message "Example should be provided with a language tag." ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:narrower ; | ||
sh:class skos:Concept ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:narrower should be a skos:Concept" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:class skos:Concept ; | ||
sh:path skos:narrowerTransitive ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:narrowerTransitive should be a skos:Concept" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:narrowMatch ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:narrowMatch should be a URI" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:broader ; | ||
sh:class skos:Concept ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:broader should be a skos:Concept" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:broaderTransitive ; | ||
sh:class skos:Concept ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:broaderTransitive should be a skos:Concept" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:broadMatch ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:broadMatch should be a URI" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:related ; | ||
sh:class skos:Concept ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:related should be a skos:Concept" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:relatedMatch ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:relatedMatch should be a URI" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:closeMatch ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:closeMatch should be a URI" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:exactMatch ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:exactMatch should be a URI" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:inScheme ; | ||
sh:class skos:ConceptScheme ; | ||
sh:minCount 1 ; | ||
sh:severity sh:Violation ; | ||
sh:message "Each skos:inScheme should have at least one skos:inScheme of type skos:ConceptScheme" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path skos:topConceptOf ; | ||
sh:class skos:ConceptScheme ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of skos:topConceptOf should be a skos:ConceptScheme" ; | ||
|
||
] ; | ||
sh:property [ | ||
sh:path owl:sameAs ; | ||
sh:nodeKind sh:IRI ; | ||
sh:severity sh:Violation ; | ||
sh:message "Target class of owl:sameAs should be a URI" ; | ||
|
||
] ; | ||
. |