Search in sources :

Example 1 with ValidationContext

use of org.apache.jena.shex.sys.ValidationContext in project jena by apache.

the class ShapeExprNOT method satisfies.

@Override
public boolean satisfies(ValidationContext vCxt, Node data) {
    ValidationContext vCxt2 = ValidationContext.create(vCxt);
    boolean innerSatisfies = other.satisfies(vCxt2, data);
    if (!innerSatisfies)
        return true;
    ReportItem item = new ReportItem("NOT: Term reject because it conforms", data);
    vCxt.reportEntry(item);
    return false;
}
Also used : ReportItem(org.apache.jena.shex.sys.ReportItem) ValidationContext(org.apache.jena.shex.sys.ValidationContext)

Example 2 with ValidationContext

use of org.apache.jena.shex.sys.ValidationContext in project jena by apache.

the class ShapeEvalTripleConstraint method matchesCardinalityTC.

/**
 * Triple Constraint, with cardinality
 */
static boolean matchesCardinalityTC(ValidationContext vCxt, Set<Triple> matchables, Node node, TripleConstraint tripleConstraint, Set<Node> extras) {
    Node predicate = tripleConstraint.getPredicate();
    if (tripleConstraint.reverse()) {
        // [shex] A bit of a fudge.
        matchables = G.find(vCxt.getData(), null, predicate, node).toSet();
    } else {
        if (!matchables.stream().allMatch(t -> predicate.equals(t.getPredicate()))) {
            // Other predicates present.
            return false;
        }
    }
    // Find same predicate.
    Set<Triple> triples = StreamOps.toSet(matchables.stream().filter(t -> predicate.equals(t.getPredicate())));
    int min = tripleConstraint.min();
    int max = tripleConstraint.max();
    ShapeExpression shExpr = tripleConstraint.getShapeExpression();
    Set<Triple> positive = triples.stream().filter(t -> {
        Node v = tripleConstraint.reverse() ? t.getSubject() : t.getObject();
        return shExpr.satisfies(vCxt, v);
    }).collect(Collectors.toSet());
    int N = positive.size();
    if (min >= 0 && N < min) {
        vCxt.reportEntry(new ReportItem("Cardinality violation (min=" + min + "): " + N, null));
        return false;
    }
    // Remove extras.
    if (extras == null || !extras.contains(predicate)) {
        if (positive.size() != triples.size())
            // Something did not match.
            return false;
    }
    if (max >= 0 && N > max) {
        vCxt.reportEntry(new ReportItem("Cardinality violation (max=" + max + "): " + N, null));
        return false;
    }
    return true;
}
Also used : ShapeExpression(org.apache.jena.shex.expressions.ShapeExpression) ValidationContext(org.apache.jena.shex.sys.ValidationContext) Node(org.apache.jena.graph.Node) StreamOps(org.apache.jena.atlas.lib.StreamOps) ReportItem(org.apache.jena.shex.sys.ReportItem) Set(java.util.Set) Triple(org.apache.jena.graph.Triple) TripleConstraint(org.apache.jena.shex.expressions.TripleConstraint) Collectors(java.util.stream.Collectors) G(org.apache.jena.riot.other.G) Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) ShapeExpression(org.apache.jena.shex.expressions.ShapeExpression) ReportItem(org.apache.jena.shex.sys.ReportItem) TripleConstraint(org.apache.jena.shex.expressions.TripleConstraint)

Example 3 with ValidationContext

use of org.apache.jena.shex.sys.ValidationContext in project jena by apache.

the class ShapeExprOR method satisfies.

@Override
public boolean satisfies(ValidationContext vCxt, Node data) {
    // We need to ignore validation failures from expressions - we need to find one success.
    for (ShapeExpression shExpr : shapeExpressions) {
        ValidationContext vCxt2 = ValidationContext.create(vCxt);
        boolean innerSatisfies = shExpr.satisfies(vCxt2, data);
        if (innerSatisfies)
            return true;
    }
    ReportItem item = new ReportItem("OR expression not satisfied:", data);
    vCxt.reportEntry(item);
    return false;
}
Also used : ReportItem(org.apache.jena.shex.sys.ReportItem) ValidationContext(org.apache.jena.shex.sys.ValidationContext)

Aggregations

ReportItem (org.apache.jena.shex.sys.ReportItem)3 ValidationContext (org.apache.jena.shex.sys.ValidationContext)3 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StreamOps (org.apache.jena.atlas.lib.StreamOps)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 G (org.apache.jena.riot.other.G)1 ShapeExpression (org.apache.jena.shex.expressions.ShapeExpression)1 TripleConstraint (org.apache.jena.shex.expressions.TripleConstraint)1