Class ValidationEngine

java.lang.Object
org.topbraid.shacl.engine.AbstractEngine
org.topbraid.shacl.validation.ValidationEngine
All Implemented Interfaces:
NodeExpressionContext

public class ValidationEngine extends AbstractEngine
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
  • 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 on
      shapesGraphURI - the URI of the shapes graph (must be in the dataset)
      shapesGraph - the ShapesGraph with the shapes to validate against
      report - the sh:ValidationReport object in the results Model, or null to create a new one
  • Method Details

    • getCurrent

      public static ValidationEngine getCurrent()
    • setCurrent

      public static void setCurrent(ValidationEngine value)
    • 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

      public ClassesCache getClassesCache()
    • getConfiguration

      public ValidationEngineConfiguration getConfiguration()
    • getLabel

      public String getLabel(org.apache.jena.rdf.model.RDFNode node)
    • getLabelFunction

      public Function<org.apache.jena.rdf.model.RDFNode,String> getLabelFunction()
    • getProfile

      public ValidationProfile 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

      public ValidationReport 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 validate
      shape - the sh:Shape to validate against
      Returns:
      true if there were no validation results, false for violations
    • setClassesCache

      public void setClassesCache(ClassesCache value)
    • setFocusNodeFilter

      public void setFocusNodeFilter(Predicate<org.apache.jena.rdf.model.RDFNode> value)
      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

      public void setLabelFunction(Function<org.apache.jena.rdf.model.RDFNode,String> value)
    • updateConforms

      public void updateConforms()
    • validateAll

      public org.apache.jena.rdf.model.Resource validateAll() throws InterruptedException
      Validates all target nodes against all of their shapes. To further narrow down which nodes to validate, use setFocusNodeFilter(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 validate
      shape - 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, use setFocusNodeFilter(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

      public void setConfiguration(ValidationEngineConfiguration configuration)
    • setProfile

      public void setProfile(ValidationProfile profile)