ValidationPresenter class¶
In addition to support presentation and editing, RDForms-templates can also be used to validate RDF. Unfulfilled cardinality restrictions for minimum and maximum will be reported as errors. Unfullfilled preferred cardinality will be reported as warnings.
const presenter = new rdforms.ValidationPresenter({
resource,
graph,
template,
fuzzy: true
},
'rdformsValidationPresenterAnchor');
As indicated in the example above, the validation presenter also supports the fuzzy parameter to allow more relaxed matching of statements. This is useful for reporting problems with nodetype, datatypes, patterns and explicit constraints.
The behaviour of the ValidationPresenter is tightly bound to the underlying validation module. The validation module can be used independent of the ValidationPresenter UI, e.g. to generate reports in an API environment. Below we outline the functionality of the validation module. Note that the ValidationPresenter uses the function bindingReport
not the graphReport
.
bindingReport - validation report for a single resource¶
Based on cardinality restrictions in RDForms-templates (max, min and prefferred cardinality) a report can be generated with errors and warnings with the function bindingReport
:
var groupBinding = rdforms.validate.match(graph, resourceURI, template);
var report = rdforms.model.bindingReport(groupBinding);
To also get information about problems with nodetype, datatype, constraints or pattern use the function fuzzyMatch
instead of match
.
var groupBinding = rdforms.validate.fuzzyMatch(graph, resourceURI, template);
var report = rdforms.model.bindingReport(groupBinding);
Note that using fuzzyMatch may result in too many validation errors / warnings, especially if you are using the same property for multiple purposes. In some situations the styles strictmatch
and relaxedDatatypeMatch
can be used wisely as an alternative to using fuzzyMatch.
The validation report divides the issues into errors and warnings and contains references to the binding / item where the problem occurred. A typical report looks like this:
{
errors: [{
parentBinding: a_binding_reference,
item: an_item_reference,
code: "min"
}, {
...
}],
warnings: [{
parentBinding: a_binding_reference,
item: an_item_reference,
code: "pref"
}, {
...
}]
}
The code values used are:
Engine.CODES | Code | Severity | explanation |
---|---|---|---|
UNKNOWN | unknown | Internal | Initial code value, used internally to not mark everything red initially. |
OK | correct | Internal | Nothing wrong, used internally. |
TOO_FEW_VALUES_MIN | min | ERROR | The amount of bindings found is fewer than what is indicated in min cardinality. |
TOO_MANY_VALUES | many | ERROR | The amount of bindings found are larger than what is indicated as the max cardinality. |
TOO_FEW_VALUES_PREF | pref | WARNING | The amount of bindings found are fewer than what is indicated in min cardinality. |
AT_MOST_ONE_CHILD | atmostonechild | ERROR | More than one binding found for items inside of group item with style atMostOneChild . |
AT_LEAST_ONE_CHILD | atleastonechild | ERROR | No binding found for items inside of group with style atLeastOneChild |
EXACTLY_ONE_CHILD | exactlyonechild | ERROR | No binding or more than one binding found for items inside of group with style exactlyOneChild |
WRONG_VALUE | value | ERROR | If a value is provided which does not match against one of the fixed choices. Only appears if the style strictmatch is set or if fuzzyMatch is used. |
WRONG_PATTERN | pattern | ERROR | If a value does not match the pattern. Only appears if fuzzyMatch is used. |
WRONG_NODETYPE | nodetype | ERROR | If a value has the wrong node type. Only appears if fuzzyMatch is used. |
WRONG_DATATYPE | datatype | ERROR | If a value has the wrong datatype. Only appears if the style relaxedDatatypeMatch is set or if fuzzyMatch is used. |
MISSING_CONSTRAINTS | constraints | ERROR | If a value does not have the neccessary constraints. Only appears if fuzzyMatch is used. |
graphReport - validation report of many resources¶
The graphReport
function can be used to validate many resources within the same graph. Resources are detected based on their type.
var report = rdforms.validate.graphReport(graph, type2template, mandatoryTypes);
The parameters are:
- graph - the RDF graph to find resources to validate, must be an instance of rdfjson/Graph.
- type2template - an object that indicates which template (a group item) to use per type (class).
- mandatoryTypes - a list of classes where at least one instance are expected.
The result is a report that looks like:
{
errors: 2,
warnings: 1,
mandatoryError: ["uri_of_class_with_missing_instances"],
resources: [{
uri: "resource_uri",
type: "uri_of_class_this_resource_is_instance_of",
template: "id_of_template_used_to_validate_this_resource",
errors: [{
path: "predicate1",
code: "few"
}],
warnings: [{
path: "predicate1 > predicate2",
code: "pref"
}]
}]
}
The total error count includes the number of mandatory classes with missing instances. If there are no mandatory classes with missing instances the attribute mandatoryError
will not be present in the report. The path attribute corresponds to either a single predicate or a list of predicates separated by the '>' character to indicate the path to the problem from the root resource. If possible the predicates will be namespace abbreviated to improve readability.