Search in sources :

Example 1 with Imports

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;
}
Also used : java.util(java.util) Imports(org.apache.jena.shacl.Imports) JLogConstraint(org.apache.jena.shacl.engine.constraint.JLogConstraint) G(org.apache.jena.riot.other.G) Graph(org.apache.jena.graph.Graph) ShLib(org.apache.jena.shacl.lib.ShLib) RDFDataException(org.apache.jena.riot.other.RDFDataException) Severity(org.apache.jena.shacl.validation.Severity) Path(org.apache.jena.sparql.path.Path) ShLib.displayStr(org.apache.jena.shacl.lib.ShLib.displayStr) SHACL(org.apache.jena.shacl.vocabulary.SHACL) C.rdfsClass(org.apache.jena.shacl.sys.C.rdfsClass) Triple(org.apache.jena.graph.Triple) ShaclSystem(org.apache.jena.shacl.sys.ShaclSystem) Collectors(java.util.stream.Collectors) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) ShaclPaths(org.apache.jena.shacl.engine.ShaclPaths) NodeConst(org.apache.jena.sparql.graph.NodeConst) Node(org.apache.jena.graph.Node) ShaclPaths.pathToString(org.apache.jena.shacl.engine.ShaclPaths.pathToString) XSDDatatype(org.apache.jena.datatypes.xsd.XSDDatatype) Target(org.apache.jena.shacl.engine.Target) Targets(org.apache.jena.shacl.engine.Targets) Pair(org.apache.jena.atlas.lib.Pair) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) TargetType(org.apache.jena.shacl.engine.TargetType) JenaException(org.apache.jena.shared.JenaException) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Shapes(org.apache.jena.shacl.Shapes) Node(org.apache.jena.graph.Node) Targets(org.apache.jena.shacl.engine.Targets)

Aggregations

java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 Pair (org.apache.jena.atlas.lib.Pair)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 XSDDatatype (org.apache.jena.datatypes.xsd.XSDDatatype)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 G (org.apache.jena.riot.other.G)1 RDFDataException (org.apache.jena.riot.other.RDFDataException)1 Imports (org.apache.jena.shacl.Imports)1 Shapes (org.apache.jena.shacl.Shapes)1 ShaclPaths (org.apache.jena.shacl.engine.ShaclPaths)1 ShaclPaths.pathToString (org.apache.jena.shacl.engine.ShaclPaths.pathToString)1 Target (org.apache.jena.shacl.engine.Target)1 TargetType (org.apache.jena.shacl.engine.TargetType)1 Targets (org.apache.jena.shacl.engine.Targets)1 JLogConstraint (org.apache.jena.shacl.engine.constraint.JLogConstraint)1 ShLib (org.apache.jena.shacl.lib.ShLib)1