Vocabulary validation checks the structure of the vocabulary graph by applying SHACL rules using the pySHACL library[^modified]. The SHACL rules are located in vocab_tools/data and are included with the code when this packae is installed.
1: The version of pySHACL used here is slightly modified to provide more metrics on rules applied during the validation process. It is retrieved from github.com/datadavev/pyshacl and is kept in sync with changes from upstream.
1 modified
Validation is generally performed on a single base or extension vocabulary using the vocab validate command with the target vocabulary source file as the only parameter:
vocab validate --help
Usage: vocab validate [OPTIONS] SOURCE
Validate vocabulary structure.
Options:
-v, --vocab TEXT Vocabulary to load
-s, --shape TEXT SHACL shape file for vocabulary structure validation
--help Show this message and exit.
Applying the rules against a valid vocabulary generates output similar to the following:
If the vocabulary does not conform with the SHACL rules then error messages are emitted. These can sometimes be a bit difficult to dechipher, though the target node mentioned in the error output is a good starting point. This example shows the output when the vocabulary has no top concept (skos:topConceptOf):
vocab validate example/data/example_notop.ttl
Loaded vocabulary https://example.net/my/minimal/vocab
SHACL conformance: False
Vocabulary not in conformance. Skipping further tests.
Validation Report
Conforms: False
Results (2):
19 of 21 applied.
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
Severity: sh:Violation
Source Shape: skos:VocabularyConceptShape
Focus Node: eg:thing
Value Node: eg:thing
Message: Node eg:thing does not conform to one or more shapes in skos:NarrowerConceptShape , skos:TopConceptShape
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
Severity: sh:Violation
Source Shape: skos:VocabularyShape
Focus Node: eg:vocab
Value Node: eg:vocab
Message: Node eg:vocab does not conform to one or more shapes in skos:ExtensionVocabularyShape , skos:BaseVocabularyShape
This example demonstrates output when the vocabulary has no skos:ConceptScheme:
Loaded vocabulary does not specify skos:ConceptScheme
SHACL conformance: False
Vocabulary not in conformance. Skipping further tests.
Validation Report
Conforms: False
Results (2):
18 of 21 applied.
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:description Literal("A vocabulary must have an instance of skos:ConceptScheme.", lang=en) ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path [ sh:inversePath rdf:type ] ]
Focus Node: skos:ConceptScheme
Result Path: [ sh:inversePath rdf:type ]
Message: Less than 1 values on skos:ConceptScheme->[ sh:inversePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
Severity: sh:Violation
Source Shape: skos:VocabularyConceptShape
Focus Node: eg:thing
Value Node: eg:thing
Message: Node eg:thing does not conform to one or more shapes in skos:NarrowerConceptShape , skos:TopConceptShape
A vocabulary concept has no skos:prefLabel:
vocab validate example/data/example_nolabel.ttl
Loaded vocabulary https://example.net/my/minimal/vocab
SHACL conformance: False
Vocabulary not in conformance. Skipping further tests.
Validation Report
Conforms: False
Results (1):
21 of 21 applied.
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:datatype rdf:langString ; sh:description Literal("A vocabulary concept must have a preferred name", lang=en) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path skos:prefLabel ]
Focus Node: eg:solid
Result Path: skos:prefLabel
Message: Less than 1 values on eg:solid->skos:prefLabel