use of org.apache.jena.shacl.parser.Constraint in project jena by apache.
the class QualifiedValueShape method validatePropertyShape.
@Override
public void validatePropertyShape(ValidationContext vCxt, Graph data, Shape shape, Node focusNode, Path path, Set<Node> valueNodes) {
/*
* Let Q be a shape in shapes graph G that declares a qualified cardinality
* constraint (by having values for sh:qualifiedValueShape and at least one of
* sh:qualifiedMinCount or sh:qualifiedMaxCount). Let ps be the set of shapes in G
* that have Q as a value of sh:property.
*
* If Q has true as a value for
* sh:qualifiedValueShapesDisjoint then the set of sibling shapes for Q is defined as
* the set of all values of the SPARQL property path
* sh:property/sh:qualifiedValueShape for any shape in ps minus the value of
* sh:qualifiedValueShape of Q itself.
*
* The set of sibling shapes is empty
* otherwise.
*/
/* TEXTUAL DEFINITION of sh:qualifiedMinCount
*
* Let C be the number of value nodes v where v conforms to $qualifiedValueShape and
* where v does not conform to any of the sibling shapes for the current shape, i.e.
* the shape that v is validated against and which has $qualifiedValueShape as its
* value for sh:qualifiedValueShape.
*
* A failure MUST be produced if any of the said conformance checks produces a failure.
* Otherwise, there is a validation result if C is less than $qualifiedMinCount.
*
* The constraint component for sh:qualifiedMinCount is sh:QualifiedMinCountConstraintComponent.
*/
Collection<Node> sibs = siblings(vCxt.getShapesGraph(), shape);
Set<Node> valueNodes2;
if (qDisjoint) {
valueNodes2 = new HashSet<>();
for (Node v : valueNodes) {
// Ignore disjoint on siblings?
if (!conformsSiblings(vCxt, v, sibs)) {
// No sibling => candidate.
valueNodes2.add(v);
}
}
} else {
valueNodes2 = valueNodes;
}
int x = 0;
for (Node v : valueNodes2) {
boolean b = conforms(vCxt, sub, v);
if (b)
x++;
}
if (qMin >= 0 && qMin > x) {
String msg = toString() + ": Min = " + qMin + " but got " + x + " validations";
vCxt.reportEntry(msg, shape, focusNode, path, null, new ReportConstraint(SHACL.QualifiedMinCountConstraintComponent));
}
if (qMax >= 0 && qMax < x) {
String msg = toString() + ": Max = " + qMax + " but got " + x + " validations";
vCxt.reportEntry(msg, shape, focusNode, path, null, new ReportConstraint(SHACL.QualifiedMaxCountConstraintComponent));
}
}
use of org.apache.jena.shacl.parser.Constraint in project jena by apache.
the class VLib method validateShape.
public static void validateShape(ValidationContext vCxt, Graph data, Shape shape, Node focusNode) {
if (shape.deactivated())
return;
if (vCxt.isVerbose())
out.println("S: " + shape);
Path path;
Set<Node> vNodes;
if (shape instanceof NodeShape) {
path = null;
vNodes = null;
} else if (shape instanceof PropertyShape) {
PropertyShape propertyShape = (PropertyShape) shape;
path = propertyShape.getPath();
vNodes = ShaclPaths.valueNodes(data, focusNode, propertyShape.getPath());
} else {
if (vCxt.isVerbose())
out.println("Z: " + shape);
return;
}
// Constraints of this shape.
for (Constraint c : shape.getConstraints()) {
if (vCxt.isVerbose())
out.println("C: " + c);
evalConstraint(vCxt, data, shape, focusNode, path, vNodes, c);
}
// Reachable shapes.
// Follow sh:property (sh:node behaves as a constraint).
validationPropertyShapes(vCxt, data, shape.getPropertyShapes(), focusNode);
if (vCxt.isVerbose())
out.println();
}
use of org.apache.jena.shacl.parser.Constraint in project jena by apache.
the class VLib method validationPropertyShape.
// This is nearly validationShape. The difference is passing in of vNodes
// evalConstraint (null for a NodeShape) and the loop on vNodes for
// getPropertyShapes(). Having extra verbose output helps.
private static void validationPropertyShape(ValidationContext vCxt, Graph data, PropertyShape propertyShape, Node focusNode) {
if (propertyShape.deactivated())
return;
if (vCxt.isVerbose())
out.println("P: " + propertyShape);
Path path = propertyShape.getPath();
Set<Node> vNodes = ShaclPaths.valueNodes(data, focusNode, path);
for (Constraint c : propertyShape.getConstraints()) {
if (vCxt.isVerbose())
out.println("C: " + focusNode + " :: " + c);
// Pass vNodes here.
evalConstraint(vCxt, data, propertyShape, focusNode, path, vNodes, c);
}
vNodes.forEach(vNode -> {
validationPropertyShapes(vCxt, data, propertyShape.getPropertyShapes(), vNode);
});
}
use of org.apache.jena.shacl.parser.Constraint in project jena by apache.
the class ShNot method printCompact.
@Override
public void printCompact(IndentedWriter out, NodeFormatter nodeFmt) {
// "other" must be a node shape with no property shapes and one constraint.
Constraint constraint = CompactWriter.getCompactPrintable(other);
if (constraint == null)
throw new ShaclNotCompactException("sh:not(" + other + ")");
out.print("! ");
constraint.printCompact(out, nodeFmt);
}
use of org.apache.jena.shacl.parser.Constraint in project jena by apache.
the class ShOr method printCompact.
@Override
public void printCompact(IndentedWriter out, NodeFormatter nodeFmt) {
boolean first = true;
for (Shape shape : others) {
if (!first)
out.print(" | ");
first = false;
Constraint c = CompactWriter.getCompactPrintable(shape);
if (c == null)
throw new ShaclNotCompactException("or");
c.printCompact(out, nodeFmt);
}
}
Aggregations