Search in sources :

Example 1 with ReportItem

use of org.apache.jena.shacl.validation.ReportItem 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 2 with ReportItem

use of org.apache.jena.shacl.validation.ReportItem 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 3 with ReportItem

use of org.apache.jena.shacl.validation.ReportItem in project jena by apache.

the class StrLanguageIn method validate.

@Override
public ReportItem validate(ValidationContext vCxt, Node n) {
    if (!n.isLiteral())
        return new ReportItem(toString() + ": Not a literal", n);
    String langTag = n.getLiteralLanguage();
    if (langTag == null || langTag.isEmpty()) {
        if (vCxt.isStrict()) {
            if (Util.isSimpleString(n))
                return new ReportItem(toString() + ": xsd:string (no language tag)", n);
            else
                return new ReportItem(toString() + ": No language tag", n);
        }
        if (!Util.isSimpleString(n))
            return new ReportItem(toString() + ": Not an rdf:langString or xsd:string", n);
        // Allow "" to mean xsd:string "none".
        if (langs.contains(langTag))
            return null;
        return new ReportItem(toString() + ": No matching language tag", n);
    }
    for (String langPattern : langs) {
        boolean b = NodeFunctions.langMatches(langTag, langPattern);
        if (b)
            return null;
    }
    String msg = toString() + ": No matching language tag " + langTag;
    return new ReportItem(msg, n);
}
Also used : CompactOut.compactArrayString(org.apache.jena.shacl.compact.writer.CompactOut.compactArrayString) ReportItem(org.apache.jena.shacl.validation.ReportItem)

Example 4 with ReportItem

use of org.apache.jena.shacl.validation.ReportItem in project jena by apache.

the class ValueRangeConstraint method validate.

@Override
public final ReportItem validate(ValidationContext vCxt, Node n) {
    NodeValue nv = NodeValue.makeNode(n);
    ValueSpaceClassification vs = NodeValue.classifyValueOp(nodeValue, nv);
    try {
        int r = NodeValue.compare(nodeValue, nv);
        if (r == Expr.CMP_INDETERMINATE)
            return new ReportItem(toString() + " indeterminant to " + n, n);
        boolean b = test(r);
        if (b)
            return null;
        return new ReportItem(getErrorMessage(n), n);
    } catch (ExprNotComparableException ex) {
        return new ReportItem(toString() + " can't compare to " + n, n);
    }
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ExprNotComparableException(org.apache.jena.sparql.expr.ExprNotComparableException) ReportItem(org.apache.jena.shacl.validation.ReportItem) ValueSpaceClassification(org.apache.jena.sparql.expr.ValueSpaceClassification)

Example 5 with ReportItem

use of org.apache.jena.shacl.validation.ReportItem in project jena by apache.

the class DatatypeConstraint method validate.

@Override
public ReportItem validate(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);
    if (dtStr == null) {
        Node dt = NodeFactory.createURI(n.getLiteralDatatypeURI());
        dtStr = ShLib.displayStr(dt);
    }
    String errMsg = toString() + " : Got datatype " + dtStr + " : Node " + displayStr(n);
    return new ReportItem(errMsg, n);
}
Also used : Node(org.apache.jena.graph.Node) ReportItem(org.apache.jena.shacl.validation.ReportItem)

Aggregations

ReportItem (org.apache.jena.shacl.validation.ReportItem)11 ValidationContext (org.apache.jena.shacl.engine.ValidationContext)5 Shape (org.apache.jena.shacl.parser.Shape)3 Node (org.apache.jena.graph.Node)1 CompactOut.compactArrayString (org.apache.jena.shacl.compact.writer.CompactOut.compactArrayString)1 ExprNotComparableException (org.apache.jena.sparql.expr.ExprNotComparableException)1 NodeValue (org.apache.jena.sparql.expr.NodeValue)1 ValueSpaceClassification (org.apache.jena.sparql.expr.ValueSpaceClassification)1