Search in sources :

Example 1 with G

use of org.apache.jena.riot.other.G in project jena by apache.

the class Constraints method parseConstraint.

/**
 * The translate of an RDF triple into a {@link Constraint}.
 * Constraints require more that just the triple being inspected.
 */
private static Constraint parseConstraint(Graph g, Node s, Node p, Node o, Map<Node, Shape> parsed, Set<Node> traversed) {
    // Test for single triple constraints.
    ConstraintMaker maker = dispatch.get(p);
    if (maker != null)
        return maker.make(g, s, p, o);
    // These require the "parsed" map.
    if (p.equals(SHACL.not)) {
        Shape shape = ShapesParser.parseShapeStep(traversed, parsed, g, o);
        return new ShNot(shape);
    }
    if (p.equals(SHACL.or)) {
        List<Node> elts = list(g, o);
        List<Shape> shapes = elts.stream().map(x -> ShapesParser.parseShapeStep(traversed, parsed, g, x)).collect(Collectors.toList());
        return new ShOr(shapes);
    }
    if (p.equals(SHACL.and)) {
        List<Node> elts = list(g, o);
        List<Shape> shapes = elts.stream().map(x -> ShapesParser.parseShapeStep(traversed, parsed, g, x)).collect(Collectors.toList());
        return new ShAnd(shapes);
    }
    if (p.equals(SHACL.xone)) {
        List<Node> elts = list(g, o);
        List<Shape> shapes = elts.stream().map(x -> ShapesParser.parseShapeStep(traversed, parsed, g, x)).collect(Collectors.toList());
        return new ShXone(shapes);
    }
    if (p.equals(SHACL.node)) {
        Shape other = ShapesParser.parseShapeStep(traversed, parsed, g, o);
        if (other instanceof PropertyShape)
            throw new ShaclParseException("Object of sh:node must be a node shape, not a property shape");
        return new ShNode(other);
    }
    // sh:pattern is influenced by an adjacent sh:flags.
    if (p.equals(SHACL.pattern)) {
        Node pat = o;
        if (!Util.isSimpleString(pat))
            throw new ShaclParseException("Pattern is not a string: Node = " + displayStr(s) + " : Pattern = " + displayStr(pat));
        Node flagsNode = G.getSP(g, s, SHACL.flags);
        if (flagsNode != null && !Util.isSimpleString(flagsNode))
            throw new ShaclParseException("Pattern flags not a string: Node = " + displayStr(s) + " : Pattern = " + displayStr(flagsNode));
        return new PatternConstraint(pat.getLiteralLexicalForm(), (flagsNode != null) ? flagsNode.getLiteralLexicalForm() : null);
    }
    // Known component parameters.
    if (p.equals(SHACL.ignoredProperties))
        return null;
    if (p.equals(SHACL.qualifiedValueShape))
        return parseQualifiedValueShape(g, s, p, o, parsed, traversed);
    // sh:qualifiedValueShape parameters.
    if (p.equals(SHACL.QualifiedMinCountConstraintComponent) || p.equals(SHACL.QualifiedMaxCountConstraintComponent) || p.equals(SHACL.qualifiedValueShapesDisjoint))
        return null;
    if (p.equals(SHACL.path))
        throw new ShaclParseException("Unexpected constraint: " + displayStr(p) + " on " + s);
    if (p.equals(SHACL.property))
        throw new ShaclParseException("Unexpected constraint: " + displayStr(p) + " on " + s);
    return null;
}
Also used : java.util(java.util) C(org.apache.jena.shacl.sys.C) SHACL(org.apache.jena.shacl.vocabulary.SHACL) SparqlConstraints(org.apache.jena.shacl.engine.SparqlConstraints) org.apache.jena.shacl.engine.constraint(org.apache.jena.shacl.engine.constraint) Triple(org.apache.jena.graph.Triple) Collectors(java.util.stream.Collectors) G(org.apache.jena.riot.other.G) Graph(org.apache.jena.graph.Graph) ShLib(org.apache.jena.shacl.lib.ShLib) Util(org.apache.jena.rdf.model.impl.Util) NotImplemented(org.apache.jena.atlas.lib.NotImplemented) Node(org.apache.jena.graph.Node) ShLib.displayStr(org.apache.jena.shacl.lib.ShLib.displayStr) Node(org.apache.jena.graph.Node)

Aggregations

java.util (java.util)1 Collectors (java.util.stream.Collectors)1 NotImplemented (org.apache.jena.atlas.lib.NotImplemented)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 Util (org.apache.jena.rdf.model.impl.Util)1 G (org.apache.jena.riot.other.G)1 SparqlConstraints (org.apache.jena.shacl.engine.SparqlConstraints)1 org.apache.jena.shacl.engine.constraint (org.apache.jena.shacl.engine.constraint)1 ShLib (org.apache.jena.shacl.lib.ShLib)1 ShLib.displayStr (org.apache.jena.shacl.lib.ShLib.displayStr)1 C (org.apache.jena.shacl.sys.C)1 SHACL (org.apache.jena.shacl.vocabulary.SHACL)1