Skip to content

Commit

Permalink
Extract constraints documented via sh:message
Browse files Browse the repository at this point in the history
See skohub-io#1 for discussion.
  • Loading branch information
nichtich committed Sep 13, 2023
1 parent 2fc1100 commit ce0075c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ At least with [Apache Jena SHACL](https://jena.apache.org/documentation/shacl/in

If you take our [template repo](https://github.com/skohub-io/vocab-template) as a starting point the validation against this shape is already built in.

Run `scripts/messages.sh` to get a list of shape messages to summarize the constraints checked by shapes.

## Check with Apache Jena SHACL

To use this shape with [Apache Jena](https://jena.apache.org/download/index.cgi) SHACL validate your file with `shacl validate --shapes skos.shacl.ttl --data YOUR-DATA.ttl`
Expand Down
11 changes: 11 additions & 0 deletions scripts/messages.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix sh: <http://www.w3.org/ns/shacl#>

SELECT DISTINCT ?type ?msg {
?shape sh:message ?msg .
#FILTER (lang(?msg) = 'en')

OPTIONAL { ?shape sh:severity ?severity }
BIND(STRAFTER(STR(COALESCE(?severity,sh:Violation)),'#') as ?type)

#filter(regex(?msg,"S[0-9]+"))
} ORDER BY ?type
9 changes: 9 additions & 0 deletions scripts/messages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

sparql() {
data=$1
query=$2
docker run --rm -v $query:/rdf/query.rq --mount type=bind,source=$data,target=/rdf/data.ttl skohub/jena:4.6.1 arq --data /rdf/data.ttl --query /rdf/query.rq --results=TSV
}

sparql $(pwd)/skos.shacl.ttl $(pwd)/scripts/messages.rq
12 changes: 6 additions & 6 deletions skos.shacl.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ skos:
sh:minCount 1;
sh:severity sh:Warning ;
sh:datatype rdf:langString ;
sh:message "Each skos:Concept has to provide a skos:prefLabel"
sh:message "Each skos:Concept should provide a skos:prefLabel"
] ;
sh:property [
sh:description "S14 A resource has no more than one value of skos:prefLabel per language tag." ;
sh:path skos:prefLabel ;
sh:datatype rdf:langString ;
sh:uniqueLang true ;
sh:message "Each skos:Concept has to provide a unique language for skos:prefLabel" ;
sh:message "S14: Each skos:Concept has to provide a unique language for skos:prefLabel" ;
] ;
sh:property [
sh:path skos:altLabel ;
Expand All @@ -62,15 +62,15 @@ skos:
# min count is checked above
sh:property [
sh:path skos:prefLabel ;
sh:description "\"Constraint S13: skos:prefLabel, skos:altLabel and skos:hiddenLabel must be disjoint\"" ;
sh:message "S13: skos:prefLabel, skos:altLabel and skos:hiddenLabel must be disjoint" ;
sh:disjoint skos:altLabel ;
sh:disjoint skos:hiddenLabel ;
# sh:minCount 1 ;
sh:name "pref label" ;
] ;
sh:property [
sh:path skos:altLabel ;
sh:description "\"Constraint S13: skos:prefLabel, skos:altLabel and skos:hiddenLabel must be disjoint\"" ;
sh:message "S13: skos:prefLabel, skos:altLabel and skos:hiddenLabel must be disjoint" ;
sh:disjoint skos:hiddenLabel ;
sh:disjoint skos:prefLabel ;
sh:name "alt label" ;
Expand Down Expand Up @@ -125,7 +125,7 @@ skos:
# ] ;
sh:property [
sh:path skos:related ;
sh:description "S27 skos:related is disjoint with the property skos:broaderTransitive." ;
sh:message "S27: skos:related is disjoint with the property skos:broaderTransitive" ;
sh:disjoint skos:broader ;
sh:disjoint skos:broaderTransitive ;
sh:disjoint skos:narrower ;
Expand Down Expand Up @@ -198,7 +198,7 @@ skos:
a sh:SPARQLConstraint ;
sh:prefixes skos: ;
rdfs:comment "Ambiguous Notation References" ;
sh:description "Concepts should not have identlical skos:notation literals." ;
sh:description "Concepts should not have identical skos:notation literals." ;
sh:message "the concept has the same notation {$value} as {$path}" ;
sh:select """
SELECT $this (?other as ?path) ?value
Expand Down

0 comments on commit ce0075c

Please sign in to comment.