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