Package org.topbraid.shacl.validation
Class ValidationEngine
java.lang.Object
org.topbraid.shacl.engine.AbstractEngine
org.topbraid.shacl.validation.ValidationEngine
- All Implemented Interfaces:
NodeExpressionContext
A ValidationEngine uses a given shapes graph (represented via an instance of ShapesGraph)
and performs SHACL validation on a given Dataset.
Instances of this class should be created via the ValidatorFactory.
- Author:
- Holger Knublauch
-
Field Summary
Fields inherited from class org.topbraid.shacl.engine.AbstractEngine
dataset, monitor, shapesGraph, shapesGraphURI -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedValidationEngine(org.apache.jena.query.Dataset dataset, URI shapesGraphURI, ShapesGraph shapesGraph, org.apache.jena.rdf.model.Resource report) Constructs a new ValidationEngine. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResultMessage(org.apache.jena.rdf.model.Resource result, org.apache.jena.rdf.model.Literal message, org.apache.jena.query.QuerySolution bindings) org.apache.jena.rdf.model.RDFNodeapplyEntailments(org.apache.jena.rdf.model.Resource focusNode) Checks if entailments are active for the current shapes graph and applies them for a given focus node.org.apache.jena.rdf.model.ResourcecreateResult(org.apache.jena.rdf.model.Resource type, Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode) org.apache.jena.rdf.model.ResourcecreateValidationResult(Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode, org.apache.jena.rdf.model.RDFNode value, Supplier<String> defaultMessage) static ValidationEnginegetLabel(org.apache.jena.rdf.model.RDFNode node) org.apache.jena.rdf.model.ResourceGets the validation report as a Resource in the report Model.Collection<org.apache.jena.rdf.model.RDFNode>getValueNodes(Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode) booleannodesConformToShape(List<org.apache.jena.rdf.model.RDFNode> focusNodes, org.apache.jena.graph.Node shape) Validates a given list of focus nodes against a given Shape, and stops as soon as one validation result is reported.voidsetClassesCache(ClassesCache value) voidsetConfiguration(ValidationEngineConfiguration configuration) static voidsetCurrent(ValidationEngine value) voidsetFocusNodeFilter(Predicate<org.apache.jena.rdf.model.RDFNode> value) Sets a filter that can be used to skip certain focus node from validation.voidsetLabelFunction(Function<org.apache.jena.rdf.model.RDFNode, String> value) voidsetProfile(ValidationProfile profile) voidorg.apache.jena.rdf.model.ResourceValidates all target nodes against all of their shapes.org.apache.jena.rdf.model.ResourcevalidateNode(org.apache.jena.graph.Node focusNode) Validates a given focus node against all of the shapes that have matching targets.protected voidvalidateNodesAgainstConstraint(Collection<org.apache.jena.rdf.model.RDFNode> focusNodes, Constraint constraint) org.apache.jena.rdf.model.ResourcevalidateNodesAgainstShape(List<org.apache.jena.rdf.model.RDFNode> focusNodes, org.apache.jena.graph.Node shape) Validates a given list of focus node against a given Shape.org.apache.jena.rdf.model.ResourcevalidateShapes(Collection<Shape> shapes) Validates all target nodes of a given collection of shapes against these shapes.Methods inherited from class org.topbraid.shacl.engine.AbstractEngine
applyEntailments, checkCanceled, getDataset, getProgressMonitor, getShapesGraph, getShapesGraphURI, getShapesModel, setProgressMonitor
-
Constructor Details
-
ValidationEngine
protected ValidationEngine(org.apache.jena.query.Dataset dataset, URI shapesGraphURI, ShapesGraph shapesGraph, org.apache.jena.rdf.model.Resource report) Constructs a new ValidationEngine.- Parameters:
dataset- the Dataset to operate onshapesGraphURI- the URI of the shapes graph (must be in the dataset)shapesGraph- the ShapesGraph with the shapes to validate againstreport- the sh:ValidationReport object in the results Model, or null to create a new one
-
-
Method Details
-
getCurrent
-
setCurrent
-
applyEntailments
public org.apache.jena.rdf.model.RDFNode applyEntailments(org.apache.jena.rdf.model.Resource focusNode) Checks if entailments are active for the current shapes graph and applies them for a given focus node. This will only work for the sh:Rules entailment, e.g. to compute sh:values and sh:defaultValue. If any inferred triples exist, the focus node will be returned attached to the model that includes those inferences. The dataset used internally will also be switched to use that new model as its default model, so that if a node gets validated it will "see" the inferred triples too.- Parameters:
focusNode- the focus node- Returns:
- the focus node, possibly in a different Model than originally
-
addResultMessage
public void addResultMessage(org.apache.jena.rdf.model.Resource result, org.apache.jena.rdf.model.Literal message, org.apache.jena.query.QuerySolution bindings) -
createResult
public org.apache.jena.rdf.model.Resource createResult(org.apache.jena.rdf.model.Resource type, Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode) -
createValidationResult
public org.apache.jena.rdf.model.Resource createValidationResult(Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode, org.apache.jena.rdf.model.RDFNode value, Supplier<String> defaultMessage) -
getClassesCache
-
getConfiguration
-
getLabel
-
getLabelFunction
-
getProfile
-
getReport
public org.apache.jena.rdf.model.Resource getReport()Gets the validation report as a Resource in the report Model.- Returns:
- the report Resource
-
getValidationReport
-
getValueNodes
public Collection<org.apache.jena.rdf.model.RDFNode> getValueNodes(Constraint constraint, org.apache.jena.rdf.model.RDFNode focusNode) -
nodesConformToShape
public boolean nodesConformToShape(List<org.apache.jena.rdf.model.RDFNode> focusNodes, org.apache.jena.graph.Node shape) Validates a given list of focus nodes against a given Shape, and stops as soon as one validation result is reported. No results are recorded.- Parameters:
focusNodes- the nodes to validateshape- the sh:Shape to validate against- Returns:
- true if there were no validation results, false for violations
-
setClassesCache
-
setFocusNodeFilter
Sets a filter that can be used to skip certain focus node from validation. The filter must return true if the given candidate focus node shall be validated, and false to skip it.- Parameters:
value- the new filter
-
setLabelFunction
-
updateConforms
public void updateConforms() -
validateAll
Validates all target nodes against all of their shapes. To further narrow down which nodes to validate, usesetFocusNodeFilter(Predicate).- Returns:
- an instance of sh:ValidationReport in the results Model
- Throws:
InterruptedException- if the monitor has canceled this
-
validateNode
public org.apache.jena.rdf.model.Resource validateNode(org.apache.jena.graph.Node focusNode) throws InterruptedException Validates a given focus node against all of the shapes that have matching targets.- Parameters:
focusNode- the node to validate- Returns:
- an instance of sh:ValidationReport in the results Model
- Throws:
InterruptedException- if the monitor has canceled this
-
validateNodesAgainstShape
public org.apache.jena.rdf.model.Resource validateNodesAgainstShape(List<org.apache.jena.rdf.model.RDFNode> focusNodes, org.apache.jena.graph.Node shape) Validates a given list of focus node against a given Shape.- Parameters:
focusNodes- the nodes to validateshape- the sh:Shape to validate against- Returns:
- an instance of sh:ValidationReport in the results Model
-
validateShapes
public org.apache.jena.rdf.model.Resource validateShapes(Collection<Shape> shapes) throws InterruptedException Validates all target nodes of a given collection of shapes against these shapes. To further narrow down which nodes to validate, usesetFocusNodeFilter(Predicate).- Returns:
- an instance of sh:ValidationReport in the results Model
- Throws:
InterruptedException- if the monitor has canceled this
-
validateNodesAgainstConstraint
protected void validateNodesAgainstConstraint(Collection<org.apache.jena.rdf.model.RDFNode> focusNodes, Constraint constraint) -
setConfiguration
-
setProfile
-