Search in sources :

Example 1 with ValidationContext

use of org.apache.jena.shacl.engine.ValidationContext in project webofneeds by researchstudio-sat.

the class AuthShapeTest method assertConformsTo.

private void assertConformsTo(Node focusNode, Node shapeNode, Shapes shapes, Graph data, boolean expected) {
    data = new Union(data, shapes.getGraph());
    ResettableErrorHandler handler = new ResettableErrorHandler();
    Shape shape = shapes.getShape(shapeNode);
    if (shape == null) {
        throw new IllegalArgumentException("no such shape: " + shapeNode);
    }
    boolean isFocusNode = VLib.isFocusNode(shape, focusNode, data);
    if (expected && !isFocusNode) {
        Assert.fail(String.format("%s should be focus node of %s", focusNode, shape));
    }
    if (!expected && isFocusNode) {
        Assert.fail(String.format("%s should not be focus node of %s", focusNode, shape));
    }
    if (isFocusNode) {
        ValidationContext vCtx = ValidationContext.create(shapes, shapes.getGraph(), handler);
        VLib.validateShape(vCtx, data, shapes.getShape(shapeNode), focusNode);
        if (vCtx.hasViolation()) {
            ValidationReport report = vCtx.generateReport();
            printNonconformingReport(report);
            Assert.fail(String.format("Data does not conform to shapes"));
        }
        if (handler.isError() || handler.isFatal()) {
            Assert.fail(String.format("Node %s %s to shape %s", focusNode, expected ? "does not conform" : "unexpectedly conforms", shapeNode));
        }
    }
}
Also used : Shape(org.apache.jena.shacl.parser.Shape) ValidationReport(org.apache.jena.shacl.ValidationReport) ResettableErrorHandler(won.shacl2java.validation.ResettableErrorHandler) Union(org.apache.jena.graph.compose.Union) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Example 2 with ValidationContext

use of org.apache.jena.shacl.engine.ValidationContext in project jena by apache.

the class QualifiedValueShape method conforms.

private static boolean conforms(ValidationContext vCxt, Shape shape, Node v) {
    ValidationContext vCxt2 = ValidationContext.create(vCxt);
    ValidationProc.execValidateShape(vCxt2, vCxt.getDataGraph(), shape, v);
    ValidationReport report = vCxt2.generateReport();
    return report.conforms();
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Example 3 with ValidationContext

use of org.apache.jena.shacl.engine.ValidationContext in project jena by apache.

the class ShNode method validate.

@Override
public ReportItem validate(ValidationContext vCxt, Graph data, Node node) {
    ValidationContext vCxt2 = ValidationContext.create(vCxt);
    ValidationProc.execValidateShape(vCxt2, data, other, node);
    boolean innerConforms = vCxt2.generateReport().conforms();
    if (innerConforms)
        return null;
    String msg = toString() + " at focusNode " + displayStr(node);
    return new ReportItem(msg, node);
}
Also used : ReportItem(org.apache.jena.shacl.validation.ReportItem) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Example 4 with ValidationContext

use of org.apache.jena.shacl.engine.ValidationContext in project jena by apache.

the class ShOr method validate.

@Override
public ReportItem validate(ValidationContext vCxt, Graph data, Node node) {
    for (Shape sh : others) {
        ValidationContext vCxt2 = ValidationContext.create(vCxt);
        ValidationProc.execValidateShape(vCxt2, data, sh, node);
        boolean innerConforms = vCxt2.generateReport().conforms();
        if (innerConforms)
            return null;
    }
    String msg = toString() + " at focusNode " + displayStr(node);
    return new ReportItem(msg, node);
}
Also used : Shape(org.apache.jena.shacl.parser.Shape) ReportItem(org.apache.jena.shacl.validation.ReportItem) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Example 5 with ValidationContext

use of org.apache.jena.shacl.engine.ValidationContext in project jena by apache.

the class ShAnd method validate.

@Override
public ReportItem validate(ValidationContext vCxt, Graph data, Node node) {
    for (Shape sh : others) {
        ValidationContext vCxt2 = ValidationContext.create(vCxt);
        ValidationProc.execValidateShape(vCxt2, data, sh, node);
        boolean innerConforms = vCxt2.generateReport().conforms();
        if (!innerConforms) {
            String msg = toString() + " at focusNode " + displayStr(node);
            return new ReportItem(msg, node);
        }
    }
    return null;
}
Also used : Shape(org.apache.jena.shacl.parser.Shape) ReportItem(org.apache.jena.shacl.validation.ReportItem) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Aggregations

ValidationContext (org.apache.jena.shacl.engine.ValidationContext)9 Shape (org.apache.jena.shacl.parser.Shape)5 ReportItem (org.apache.jena.shacl.validation.ReportItem)5 Node (org.apache.jena.graph.Node)2 ValidationReport (org.apache.jena.shacl.ValidationReport)2 Individual (won.shacl2java.annotation.Individual)2 ShapeNode (won.shacl2java.annotation.ShapeNode)2 ClassName (com.squareup.javapoet.ClassName)1 FieldSpec (com.squareup.javapoet.FieldSpec)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 io.github.classgraph (io.github.classgraph)1 MethodHandles (java.lang.invoke.MethodHandles)1 java.lang.reflect (java.lang.reflect)1 URI (java.net.URI)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Graph (org.apache.jena.graph.Graph)1 NodeFactory (org.apache.jena.graph.NodeFactory)1