use of org.apache.jena.shacl.Imports in project jena by apache.
the class ShapesParser method parseProcess.
/* The parsing process.
* <p>
* Applications should call functions in {@link Shapes} rather than call the parser directly.
*/
public static ParserResult parseProcess(Graph shapesGraph, Collection<Node> declaredNodes) {
Targets targets = ShapesParser.targets(shapesGraph);
ConstraintComponents sparqlConstraintComponents = ConstraintComponents.parseSparqlConstraintComponents(shapesGraph);
TargetExtensions targetExtensions = TargetExtensions.parseSPARQLTargetType(shapesGraph);
// Parse from the targets.
Map<Node, Shape> shapesMap = ShapesParser.parseShapes(shapesGraph, targets, sparqlConstraintComponents, targetExtensions);
// Root shapes, after parsing from the targets.
Collection<Shape> rootShapes = shapesMap.values().stream().filter(sh -> sh.hasTarget()).collect(Collectors.toUnmodifiableList());
// Parse other shapes - i.e. addressable node and property shapes without
// target if they were not reached when parsing form the targets.
// This skips declared+targets because the shapesMap is in common.
Collection<Shape> declShapes = new ArrayList<>();
declaredNodes.forEach(shapeNode -> {
if (!shapesMap.containsKey(shapeNode)) {
Shape shape = ShapesParser.parseShape(shapesMap, shapesGraph, shapeNode);
declShapes.add(shape);
}
});
// rootShapes and declShapes are disjoint.
if (true) {
rootShapes.forEach(sh -> {
if (declShapes.contains(sh))
System.err.println("Shape in both: " + sh);
if (!sh.hasTarget())
System.err.println("Root shape with no target: " + sh);
});
declShapes.forEach(sh -> {
if (sh.hasTarget())
System.err.println("Declared shape with target: " + sh);
});
}
// Extract base and imports.
Pair<Node, List<Node>> pair = Imports.baseAndImports(shapesGraph);
Node shapesBase = pair.getLeft();
List<Node> imports = pair.getRight();
ParserResult x = new ParserResult(shapesBase, imports, shapesMap, targets, rootShapes, declShapes, sparqlConstraintComponents, targetExtensions);
return x;
}
Aggregations