SimplePath(Resource id, SailRepositoryConnection connection) { super(id); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.PATH, null, true))) { path = stream.map(Statement::getObject).map(v -> (IRI) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:path on " + id)); } }
MinCountPropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.MIN_COUNT, null, true))) { minCount = stream.map(Statement::getObject).map(v -> (Literal) v).map(Literal::longValue).findAny().orElseThrow(() -> new RuntimeException("Expect to find sh:minCount on " + id)); } }
DatatypePropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.DATATYPE, null, true))) { datatype = stream.map(Statement::getObject).map(v -> (Resource) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:datatype on " + id)); } }
SimplePath(Resource id, SailRepositoryConnection connection) { super(id); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.PATH, null, true))) { path = stream.map(Statement::getObject).map(v -> (IRI) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:path on " + id)); } }
TargetClass(Resource id, SailRepositoryConnection connection) { super(id, connection); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.TARGET_CLASS, null))) { targetClass = stream.map(Statement::getObject).map(v -> (Resource) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:targetClass on " + id)); } }
MinCountPropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.MIN_COUNT, null, true))) { minCount = stream.map(Statement::getObject).map(v -> (Literal) v).map(Literal::longValue).findAny().orElseThrow(() -> new RuntimeException("Expect to find sh:minCount on " + id)); } }
TargetClass(Resource id, SailRepositoryConnection connection) { super(id, connection); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.TARGET_CLASS, null))) { targetClass = stream.map(Statement::getObject).map(v -> (Resource) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:targetClass on " + id)); } }
MaxCountPropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.MAX_COUNT, null, true))) { maxCount = stream.map(Statement::getObject).map(v -> (Literal) v).map(Literal::longValue).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:maxCount on " + id)); } }
DatatypePropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.DATATYPE, null, true))) { datatype = stream.map(Statement::getObject).map(v -> (Resource) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:datatype on " + id)); } }
MaxCountPropertyShape(Resource id, SailRepositoryConnection connection, Shape shape) { super(id, connection, shape); try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.MAX_COUNT, null, true))) { maxCount = stream.map(Statement::getObject).map(v -> (Literal) v).map(Literal::longValue).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:maxCount on " + id)); } }
public static List<Shape> getShapes(SailRepositoryConnection connection) { try (Stream<Statement> stream = Iterations.stream(connection.getStatements(null, RDF.TYPE, SHACL.SHAPE))) { return stream.map(Statement::getSubject).map(shapeId -> { if (hasTargetClass(shapeId, connection)) { return new TargetClass(shapeId, connection); } else { return new Shape(shapeId, connection); // target class shapes are the only supported shapes } }) .filter(Objects::nonNull) .collect(Collectors.toList()); } }
public static List<Shape> getShapes(SailRepositoryConnection connection) { try (Stream<Statement> stream = Iterations.stream(connection.getStatements(null, RDF.TYPE, SHACL.SHAPE))) { return stream.map(Statement::getSubject).map(shapeId -> { if (hasTargetClass(shapeId, connection)) { return new TargetClass(shapeId, connection); } else { return new Shape(shapeId, connection); // target class shapes are the only supported shapes } }) .filter(Objects::nonNull) .collect(Collectors.toList()); } }
static List<PropertyShape> getProprtyShapes(Resource ShapeId, SailRepositoryConnection connection, Shape shape) { try (Stream<Statement> stream = Iterations.stream(connection.getStatements(ShapeId, SHACL.PROPERTY, null))) { return stream .map(Statement::getObject) .map(v -> (Resource) v) .flatMap(propertyShapeId -> { List<PropertyShape> propertyShapes = new ArrayList<>(2); if (hasMinCount(propertyShapeId, connection)) { propertyShapes.add(new MinCountPropertyShape(propertyShapeId, connection, shape)); } if (hasMaxCount(propertyShapeId, connection)) { propertyShapes.add(new MaxCountPropertyShape(propertyShapeId, connection, shape)); } if (hasDatatype(propertyShapeId, connection)) { propertyShapes.add(new DatatypePropertyShape(propertyShapeId, connection, shape)); } return propertyShapes.stream(); }) .collect(Collectors.toList()); } }
static List<PropertyShape> getProprtyShapes(Resource ShapeId, SailRepositoryConnection connection, Shape shape) { try (Stream<Statement> stream = Iterations.stream(connection.getStatements(ShapeId, SHACL.PROPERTY, null))) { return stream .map(Statement::getObject) .map(v -> (Resource) v) .flatMap(propertyShapeId -> { List<PropertyShape> propertyShapes = new ArrayList<>(2); if (hasMinCount(propertyShapeId, connection)) { propertyShapes.add(new MinCountPropertyShape(propertyShapeId, connection, shape)); } if (hasMaxCount(propertyShapeId, connection)) { propertyShapes.add(new MaxCountPropertyShape(propertyShapeId, connection, shape)); } if (hasDatatype(propertyShapeId, connection)) { propertyShapes.add(new DatatypePropertyShape(propertyShapeId, connection, shape)); } return propertyShapes.stream(); }) .collect(Collectors.toList()); } }
@Override public void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { handler.startRDF(); // Export namespace information CloseableIteration<? extends Namespace, RepositoryException> nsIter = getNamespaces(); try { while (nsIter.hasNext()) { Namespace ns = nsIter.next(); handler.handleNamespace(ns.getPrefix(), ns.getName()); } } finally { nsIter.close(); } // Export statements CloseableIteration<? extends Statement, RepositoryException> stIter = getStatements(subj, pred, obj, includeInferred, contexts); try { while (stIter.hasNext()) { handler.handleStatement(stIter.next()); } } finally { stIter.close(); } handler.endRDF(); }