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));
}
Aggregations