Search in sources :

Example 6 with ReportItem

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

the class DatatypeConstraint method nodeSatisfies.

@Override
public ReportItem nodeSatisfies(ValidationContext vCxt, Node n) {
    if (n.isLiteral() && dtURI.equals(n.getLiteralDatatypeURI())) {
        // Must be valid for the type
        if (!rdfDatatype.isValid(n.getLiteralLexicalForm())) {
            String errMsg = toString() + " : Not valid value : Node " + displayStr(n);
            return new ReportItem(errMsg, n);
        }
        return null;
    }
    if (!n.isLiteral())
        return new ReportItem(toString() + " : Not a literal", n);
    // String dtStr = vCxt.getShapesGraph().getPrefixMapping().qnameFor(dtURI);
    Node dt = NodeFactory.createURI(n.getLiteralDatatypeURI());
    String errMsg = toString() + " -- Wrong datatype: " + strDatatype(n) + " for focus node: " + displayStr(n);
    return new ReportItem(errMsg, n);
}
Also used : Node(org.apache.jena.graph.Node) ReportItem(org.apache.jena.shex.sys.ReportItem)

Example 7 with ReportItem

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

the class NumRangeConstraint method nodeSatisfies.

@Override
public ReportItem nodeSatisfies(ValidationContext vCxt, Node n) {
    if (!n.isLiteral())
        return new ReportItem("NumRange: Not a literal number", n);
    NodeValue nv = NodeValue.makeNode(n);
    int r = NodeValue.compare(nv, numericValue);
    switch(rangeKind) {
        case MAXEXCLUSIVE:
            if (r < 0)
                return null;
            break;
        case MAXINCLUSIVE:
            if (r <= 0)
                return null;
            break;
        case MINEXCLUSIVE:
            if (r > 0)
                return null;
            break;
        case MININCLUSIVE:
            if (r >= 0)
                return null;
            break;
        default:
            break;
    }
    String msg = format("Expected %s %s : got = %s", rangeKind.label(), NodeFmtLib.strTTL(nv.getNode()), NodeFmtLib.strTTL(n));
    return new ReportItem(msg, n);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ReportItem(org.apache.jena.shex.sys.ReportItem)

Example 8 with ReportItem

use of org.apache.jena.shex.sys.ReportItem 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)8 Node (org.apache.jena.graph.Node)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 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 XSDDatatype (org.apache.jena.datatypes.xsd.XSDDatatype)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 NodeValue (org.apache.jena.sparql.expr.NodeValue)1