Search in sources :

Example 1 with RDFCollections

use of org.eclipse.rdf4j.model.util.RDFCollections in project rdf4j by eclipse.

the class Connections method consumeRDFCollection.

/**
 * Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
 * resource and send them to the supplied {@link Consumer}.
 *
 * @param conn
 *        the {@link RepositoryConnection} to use for statement retrieval.
 * @param head
 *        the start resource of the RDF Collection. May not be {@code null}.
 * @param collectionConsumer
 *        a {@link Consumer} function to which all retrieved statements will be reported. May not be
 *        {@code null}.
 * @param contexts
 *        the context(s) from which to read the RDF Collection. This argument is an optional vararg and
 *        can be left out.
 * @throws RepositoryException
 *         if an error occurred while reading the collection statements, for example if a cycle is
 *         detected in the RDF collection, or some other anomaly which makes it non-wellformed.
 * @see RDFCollections
 * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
 *      vocabulary</a>.
 */
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
    GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
    Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
    RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) Collection(java.util.Collection) RepositoryResult(org.eclipse.rdf4j.repository.RepositoryResult) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Model(org.eclipse.rdf4j.model.Model) Value(org.eclipse.rdf4j.model.Value) Objects(java.util.Objects) Consumer(java.util.function.Consumer) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RDFCollections(org.eclipse.rdf4j.model.util.RDFCollections) Statement(org.eclipse.rdf4j.model.Statement) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Optional(java.util.Optional) IRI(org.eclipse.rdf4j.model.IRI) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Supplier(java.util.function.Supplier)

Aggregations

Collection (java.util.Collection)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 IRI (org.eclipse.rdf4j.model.IRI)1 Model (org.eclipse.rdf4j.model.Model)1 Resource (org.eclipse.rdf4j.model.Resource)1 Statement (org.eclipse.rdf4j.model.Statement)1 Value (org.eclipse.rdf4j.model.Value)1 GetStatementOptional (org.eclipse.rdf4j.model.util.GetStatementOptional)1 RDFCollections (org.eclipse.rdf4j.model.util.RDFCollections)1 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1 RepositoryResult (org.eclipse.rdf4j.repository.RepositoryResult)1