BlueBrain / BlueBrain/nexus-forge
Issues with resource validation
- Dominant language
- Python
- Stars
- 52
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I was playing with the KnowledgeGraphForge.validate. There's a few issues.
### Can't pre-validate if there are files
If I call validate on a resource that has files to it, to check if it's valid before registering it, I get:
```
_validate_one
False
ValidationError: resource has lazy actions which need to be executed before
```
if I do:
```
forge.validate(resource, execute_actions_before=True)
_validate_one
False
```
and the validation fails, and if I do not register the resource due to it failing, I have now effectively uploaded a file that will never be used by anything in Nexus.
### Error message is unclear
If I validate a registered resource, in this case `DetailedCircuit`, the output is:
```
_validate_one
False
ValidationError:
Validation Report
Conforms: False
Results (1):
Constraint Violation in AndConstraintComponent (http://www.w3.org/ns/shacl#AndConstraintComponent):
Severity: sh:Violation
Source Shape: this:DetailedCircuitShape
Focus Node:
Value Node:
Message: Node does not conform to all shapes in [ sh:node this1:ModelInstanceShape ] , [ sh:property [ rdfs:seeAlso ; sh:class nsg:EdgeCollection ; sh:description Literal("Location of nrn synapse file and additional circuit description files: start.ncs and start.target") ; sh:name Literal("nrnPath") ; sh:path nsg:edgeCollection ], [ rdfs:seeAlso ; sh:class nsg:NodeCollection ; sh:description Literal("Node collection entity.") ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:name Literal("Node collection") ; sh:path nsg:nodeCollection ], [ rdfs:seeAlso ; sh:class nsg:Target ; sh:description Literal("Optional parameter giving location of predefined targets stored in the named file") ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:name Literal("TargetFile") ; sh:path nsg:target ; skos:editorialNote Literal("constrain with application/bbp-target", datatype=xsd:string) ] ]
```
I investigated this further, and went all the way to
`kgforge/specializations/models/rdf/store_service.py:StoreService._validate`
to realize that the error message comes as such from the `pyshacl.Validator` and is of type `rdflib.term.Literal` which is basically a string.
I don't know if you can do a more customized validator with pyshacl that would give more meaningful error messages. Like by inheriting the validator and creating a custom `create_validation_report` (https://github.com/RDFLib/pySHACL/blob/master/pyshacl/validate.py#L125) but I feel the current error message is not clear enough.
Like I know that the current message means it's missing properties but it is not clear from that message. It would be nice if instead of all that it'd output something like:
```
_validate_one
False
ValidationError:
Validation Report
Conforms: False
Results (1):
Constraint Violation in AndConstraintComponent (http://www.w3.org/ns/shacl#AndConstraintComponent):
Severity: sh:Violation
Source Shape: this:DetailedCircuitShape
Focus Node:
Value Node:
Message: Node is missing following properties: EdgeCollection, NodeCollection, TargetFile
```
or, even with less output if possible, like:
```
_validate_one
False
ValidationError: is missing following properties: EdgeCollection, NodeCollection, TargetFile
```
Contributor guide
Assessment
This issue has not been assessed yet.