Search in sources :

Example 6 with ShaclParseException

use of org.apache.jena.shacl.parser.ShaclParseException in project jena by apache.

the class ShaclPaths method path.

// XXX Better error checking.
private static Path path(Graph graph, Node node) {
    if (node.isURI() && !C.NIL.equals(node))
        return PathFactory.pathLink(node);
    if (isList(graph, node)) {
        List<Node> nodes = G.rdfList(graph, node);
        if (nodes.isEmpty())
            throw new ShaclParseException("Empty list for path sequence");
        Path path = null;
        // Left deep. Like the jena path parser.
        for (Node n : nodes) {
            Path p = path(graph, n);
            if (path == null)
                path = p;
            else
                path = PathFactory.pathSeq(path, p);
        }
        // }
        return path;
    }
    if (node.isBlank()) {
        if (G.hasProperty(graph, node, SHACL.inversePath)) {
            Node x = G.getSP(graph, node, SHACL.inversePath);
            Path p = path(graph, x);
            return PathFactory.pathInverse(p);
        }
        if (G.hasProperty(graph, node, SHACL.zeroOrMorePath)) {
            Node x = G.getSP(graph, node, SHACL.zeroOrMorePath);
            Path p = path(graph, x);
            return PathFactory.pathZeroOrMore1(p);
        }
        if (G.hasProperty(graph, node, SHACL.oneOrMorePath)) {
            Node x = G.getSP(graph, node, SHACL.oneOrMorePath);
            Path p = path(graph, x);
            return PathFactory.pathOneOrMore1(p);
        }
        if (G.hasProperty(graph, node, SHACL.zeroOrOnePath)) {
            Node x = G.getSP(graph, node, SHACL.zeroOrOnePath);
            Path p = path(graph, x);
            return PathFactory.pathZeroOrOne(p);
        }
        if (G.hasProperty(graph, node, SHACL.alternativePath)) {
            Node x = G.getSP(graph, node, SHACL.alternativePath);
            if (!isList(graph, x)) {
                throw new ShaclParseException("Not a list for path alternativePath");
            }
            List<Node> nodes = G.rdfList(graph, x);
            Path path = null;
            for (Node n : nodes) {
                Path p = path(graph, n);
                if (path == null)
                    path = p;
                else
                    path = PathFactory.pathAlt(path, p);
            }
            return path;
        }
    }
    throw new ShaclParseException("Bad list: " + ShLib.displayStr(node));
}
Also used : ShaclParseException(org.apache.jena.shacl.parser.ShaclParseException) Node(org.apache.jena.graph.Node)

Aggregations

ShaclParseException (org.apache.jena.shacl.parser.ShaclParseException)6 Node (org.apache.jena.graph.Node)4 RDFNode (org.apache.jena.rdf.model.RDFNode)2 PrintStream (java.io.PrintStream)1 Graph (org.apache.jena.graph.Graph)1 Shapes (org.apache.jena.shacl.Shapes)1 ShaclcParseException (org.apache.jena.shacl.compact.reader.ShaclcParseException)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 GNode (org.apache.jena.sparql.util.graph.GNode)1