Class RDFContainers
Collection
classes.
RDF Containers are represented using 3 different types of structures:
1. RDF.BAG
: A Bag (a resource having type rdf:Bag) represents a group of resources or literals, possibly
including duplicate members, where there is no significance in the order of the members.
2. RDF.SEQ
: A Sequence or Seq (a resource having type rdf:Seq) represents a group of resources or literals,
possibly including duplicate members, where the order of the members is significant.
3. RDF.ALT
: An Alternative or Alt (a resource having type rdf:Alt) represents a group of resources or
literals that are alternatives (typically for a single value of a property).
So, in each of the above types, the container starts with a first resource node, via the rdf:_1 relation. Similarly,
the next member is connected via the rdf:_2 relation and so on.
For eg. Bag containing three literal values "A", "B", and "C" looks like this as an RDF Container:
_:n1 -rdf:type--> rdf:Bag | +---rdf:_1--> "A" | +---rdf:_2--> "B" | +---rdf:_3--> "C"
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
consumeContainer
(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter.static void
consumeContainer
(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, ValueFactory vf, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Container.static void
consumeValues
(Model m, Resource container, IRI containerType, Consumer<Value> consumer, Resource... contexts) static void
extract
(IRI containerType, Model sourceModel, Resource container, Consumer<Statement> consumer, Resource... contexts) Extracts the RDF Container starting with suppliedhead
resource from the supplied sourceModel
and sends the statements that make up the collection to the suppliedConsumer
.static <E extends RDF4JException>
voidextract
(IRI containerType, GetStatementOptional statementSupplier, Resource container, Consumer<Statement> collectionConsumer, Function<String, Supplier<E>> exceptionSupplier, Resource... contexts) Extracts an RDF Container starting with the supplied container head from the statement supplier and sends all statements that make up the collection to the suppliedConsumer
function.static <C extends Collection<Statement>>
CgetContainer
(IRI containerType, Model sourceModel, Resource container, C sink, Resource... contexts) static <C extends Collection<Statement>>
CConverts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter.static <C extends Collection<Statement>>
CtoRDF
(IRI containerType, Iterable<?> values, Resource container, C sink, ValueFactory vf, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter.static <C extends Collection<Value>>
CConverts an RDF Containter to a JavaCollection
ofValue
objects.
-
Constructor Details
-
RDFContainers
public RDFContainers()
-
-
Method Details
-
toRDF
public static <C extends Collection<Statement>> C toRDF(IRI containerType, Iterable<?> values, Resource container, C sink, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter. The statements making up the new RDF Containter will be added to the supplied statement collection.- Parameters:
containerType
- defines the type of RDF Containervalues
- anIterable
of objects (such as a JavaCollection
), which will be converted to an RDF Containter. May not benull
. The method attempts to convert each value that is not already an instance ofValue
to aLiteral
. This conversion will fail with aLiteralUtilException
if the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)
for an overview of supported types.container
- aResource
which will be used as the head of the container, that is, the starting point of the created RDF Container. May benull
, in which case a new resource is generated to represent the container head.sink
- aCollection
ofStatement
objects (for example aModel
) to which the RDF Collection statements will be added. May not benull
.contexts
- the context(s) in which to add the RDF Containter. This argument is an optional vararg and can be left out.- Returns:
- the supplied sink
Collection
ofStatement
s, with the new Statements forming the RDF Collection added. - Throws:
LiteralUtilException
- if one of the supplied values can not be converted to a Literal.- See Also:
-
toRDF
public static <C extends Collection<Statement>> C toRDF(IRI containerType, Iterable<?> values, Resource container, C sink, ValueFactory vf, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter. The statements making up the new RDF Containter will be added to the supplied statement collection.- Parameters:
containerType
- defines the type of RDF Containervalues
- anIterable
of objects (such as a JavaCollection
), which will be converted to an RDF Containter. May not benull
. The method attempts to convert each value that is not already an instance ofValue
to aLiteral
. This conversion will fail with aLiteralUtilException
if the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)
for an overview of supported types.container
- aResource
which will be used as the head of the container, that is, the starting point of the created RDF Container. May benull
, in which case a new resource is generated to represent the container head.sink
- aCollection
ofStatement
objects (for example aModel
) to which the RDF Collection statements will be added. May not benull
.vf
- theValueFactory
to be used for creation of RDF model objects. May not benull
.contexts
- the context(s) in which to add the RDF Containter. This argument is an optional vararg and can be left out.- Returns:
- the supplied sink
Collection
ofStatement
s, with the new Statements forming the RDF Collection added. - Throws:
LiteralUtilException
- if one of the supplied values can not be converted to a Literal.- See Also:
-
toValues
public static <C extends Collection<Value>> C toValues(IRI containerType, Model m, Resource container, C collection, Resource... contexts) throws ModelException Converts an RDF Containter to a JavaCollection
ofValue
objects. The RDF Containter is given by the suppliedModel
andcontainer
. This method expects the RDF Containter to be well-formed. If the collection is not well-formed the method may return part of the collection, or may throw aModelException
.- Parameters:
containerType
- defines the type of RDF Containerm
- the Model containing the collection to read.container
- theResource
that represents the container head, that is the start resource of the RDF Container to be read. May not benull
.collection
- the JavaCollection
to add the collection items to.contexts
- the context(s) from which to read the RDF Containter. This argument is an optional vararg and can be left out.- Returns:
- the supplied Java
Collection
, filled with the items from the RDF Containter (if any). - Throws:
ModelException
- if a problem occurs reading the RDF Containter, for example if the Collection is not well-formed.- See Also:
-
consumeContainer
public static void consumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Containter. The statements making up the new RDF Containter will be reported to the suppliedConsumer
function.- Parameters:
containerType
- defines the type of RDF Containervalues
- anIterable
of objects (such as a JavaCollection
), which will be converted to an RDF Containter. May not benull
. The method attempts to convert each value that is not already an instance ofValue
to aLiteral
. This conversion will fail with aLiteralUtilException
if the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)
for an overview of supported types.container
- aResource
which will be used as the head of the container, that is, the starting point of the created RDF Containter. May benull
, in which case a new resource is generated to represent the containter head.consumer
- theConsumer
function for the Statements of the RDF Containter. May not benull
.contexts
- the context(s) in which to add the RDF Containter. This argument is an optional vararg and can be left out.- Throws:
LiteralUtilException
- if one of the supplied values can not be converted to a Literal.- See Also:
-
consumeContainer
public static void consumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, ValueFactory vf, Resource... contexts) Converts the suppliedIterable
to an RDF Container, using the suppliedhead
resource as the starting resource of the RDF Container. The statements making up the new RDF Container will be reported to the suppliedConsumer
function.- Parameters:
containerType
- defines the type of RDF Containervalues
- anIterable
of objects (such as a JavaCollection
), which will be converted to an RDF Container. May not benull
. The method attempts to convert each value that is not already an instance ofValue
to aLiteral
. This conversion will fail with aLiteralUtilException
if the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)
for an overview of supported types.container
- aResource
which will be used as the head of the container, that is, the starting point of the created RDF Container. May benull
, in which case a new resource is generated to represent the containter head.consumer
- theConsumer
function for the Statements of the RDF Container. May not benull
.vf
- theValueFactory
to use for creation of new model objects. May not benull
contexts
- the context(s) in which to add the RDF Container. This argument is an optional vararg and can be left out.- Throws:
LiteralUtilException
- if one of the supplied values can not be converted to a Literal.- Since:
- 3.3.0
- See Also:
-
consumeValues
public static void consumeValues(Model m, Resource container, IRI containerType, Consumer<Value> consumer, Resource... contexts) throws ModelException Reads an RDF Container starting with the supplied containter head from the suppliedModel
and sends each collection memberValue
to the suppliedConsumer
function. This method expects the RDF Container to be well-formed. If the collection is not well-formed the method may report only part of the collection, or may throw aModelException
.- Parameters:
m
- the Model containing the collection to read.container
- theResource
that represents the containter head, that is the start resource of the RDF Container to be read. May not benull
.containerType
- defines the type of RDF Containerconsumer
- the JavaConsumer
function to which the collection items are reported.contexts
- the context(s) from which to read the RDF Container. This argument is an optional vararg and can be left out.- Throws:
ModelException
- if a problem occurs reading the RDF Container, for example if the Collection is not well-formed.- See Also:
-
getContainer
public static <C extends Collection<Statement>> C getContainer(IRI containerType, Model sourceModel, Resource container, C sink, Resource... contexts) Extracts the RDF Container starting with the suppliedhead
resource from the supplied sourceModel
. The statements making up the RDF Container will be added to the supplied statement collection, which will also be returned.- Parameters:
containerType
- defines the type of RDF ContainersourceModel
- the source model, containing the RDF Container to be read.container
- theResource
that represents the container head, that is the start resource of the RDF Container to be read. May not benull
. aCollection
ofStatement
objects (for example aModel
) to which the RDF Container statements will be added. May not benull
.sink
- aCollection
ofStatement
objects (for example aModel
) to which the RDF Container statements will be added. May not benull
.contexts
- the context(s) from which to read the RDF Container. This argument is an optional vararg and can be left out.- Returns:
- the supplied sink
Collection
ofStatement
s, with the Statements of the RDF Container added.
-
extract
public static void extract(IRI containerType, Model sourceModel, Resource container, Consumer<Statement> consumer, Resource... contexts) Extracts the RDF Container starting with suppliedhead
resource from the supplied sourceModel
and sends the statements that make up the collection to the suppliedConsumer
.- Parameters:
containerType
- defines the type of RDF ContainersourceModel
- the source model, containing the RDF Container to be read.container
- theResource
that represents the container head, that is the start resource of the RDF Container to be read. May not benull
. aCollection
ofStatement
objects (for example aModel
) to which the RDF Container statements will be added. May not benull
.consumer
- theConsumer
function for the Statements of the RDF Container. May not benull
.contexts
- the context(s) from which to read the RDF Container. This argument is an optional vararg and can be left out.
-
extract
public static <E extends RDF4JException> void extract(IRI containerType, GetStatementOptional statementSupplier, Resource container, Consumer<Statement> collectionConsumer, Function<String, Supplier<E>> exceptionSupplier, Resource... contexts) throws EExtracts an RDF Container starting with the supplied container head from the statement supplier and sends all statements that make up the collection to the suppliedConsumer
function. This method expects the RDF Container to be well-formed. If the collection is not well-formed the method may report only part of the collection, or may throw an exception.- Parameters:
containerType
- defines the type of RDF ContainerstatementSupplier
- the source of the statements from which the RDF Container is to be read, specified as a functional interface.container
- theResource
that represents the container head, that is the start resource of the RDF Container to be read. May not benull
.collectionConsumer
- the JavaConsumer
function to which the collection statements are reported.exceptionSupplier
- a functional interface that produces the exception type this method will throw when an error occurs.contexts
- the context(s) from which to read the RDF Container. This argument is an optional vararg and can be left out.- Throws:
E
- if a problem occurs reading the RDF Container, for example if it is not well-formed.
-