Class RDFContainers
- java.lang.Object
-
- org.eclipse.rdf4j.model.util.RDFContainers
-
public class RDFContainers extends Object
Utilities for working with RDF Containers and converting to/from JavaCollectionclasses.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
Constructors Constructor Description RDFContainers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconsumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, Resource... contexts)Converts the suppliedIterableto an RDF Container, using the suppliedheadresource as the starting resource of the RDF Containter.static voidconsumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, ValueFactory vf, Resource... contexts)Converts the suppliedIterableto an RDF Container, using the suppliedheadresource as the starting resource of the RDF Container.static voidconsumeValues(Model m, Resource container, IRI containerType, Consumer<Value> consumer, Resource... contexts)static voidextract(IRI containerType, Model sourceModel, Resource container, Consumer<Statement> consumer, Resource... contexts)Extracts the RDF Container starting with suppliedheadresource from the supplied sourceModeland 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 suppliedConsumerfunction.static <C extends Collection<Statement>>
CgetContainer(IRI containerType, Model sourceModel, Resource container, C sink, Resource... contexts)static <C extends Collection<Statement>>
CtoRDF(IRI containerType, Iterable<?> values, Resource container, C sink, Resource... contexts)Converts the suppliedIterableto an RDF Container, using the suppliedheadresource 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 suppliedIterableto an RDF Container, using the suppliedheadresource as the starting resource of the RDF Containter.static <C extends Collection<Value>>
CtoValues(IRI containerType, Model m, Resource container, C collection, Resource... contexts)Converts an RDF Containter to a JavaCollectionofValueobjects.
-
-
-
Method Detail
-
toRDF
public static <C extends Collection<Statement>> C toRDF(IRI containerType, Iterable<?> values, Resource container, C sink, Resource... contexts)
Converts the suppliedIterableto an RDF Container, using the suppliedheadresource 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- anIterableof 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 ofValueto aLiteral. This conversion will fail with aLiteralUtilExceptionif the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)for an overview of supported types.container- aResourcewhich 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- aCollectionofStatementobjects (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
CollectionofStatements, 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:
- RDF Schema 1.1 section on Collection vocabulary
-
toRDF
public static <C extends Collection<Statement>> C toRDF(IRI containerType, Iterable<?> values, Resource container, C sink, ValueFactory vf, Resource... contexts)
Converts the suppliedIterableto an RDF Container, using the suppliedheadresource 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- anIterableof 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 ofValueto aLiteral. This conversion will fail with aLiteralUtilExceptionif the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)for an overview of supported types.container- aResourcewhich 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- aCollectionofStatementobjects (for example aModel) to which the RDF Collection statements will be added. May not benull.vf- theValueFactoryto 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
CollectionofStatements, 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:
- RDF Schema 1.1 section on Collection vocabulary
-
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 JavaCollectionofValueobjects. The RDF Containter is given by the suppliedModelandcontainer. 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- theResourcethat represents the container head, that is the start resource of the RDF Container to be read. May not benull.collection- the JavaCollectionto 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:
- RDF Schema 1.1 section on Collection vocabulary
-
consumeContainer
public static void consumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, Resource... contexts)
Converts the suppliedIterableto an RDF Container, using the suppliedheadresource as the starting resource of the RDF Containter. The statements making up the new RDF Containter will be reported to the suppliedConsumerfunction.- Parameters:
containerType- defines the type of RDF Containervalues- anIterableof 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 ofValueto aLiteral. This conversion will fail with aLiteralUtilExceptionif the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)for an overview of supported types.container- aResourcewhich 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- theConsumerfunction 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:
- RDF Schema 1.1 section on Collection vocabulary,
Literals.createLiteralOrFail(ValueFactory, Object)
-
consumeContainer
public static void consumeContainer(IRI containerType, Iterable<?> values, Resource container, Consumer<Statement> consumer, ValueFactory vf, Resource... contexts)
Converts the suppliedIterableto an RDF Container, using the suppliedheadresource as the starting resource of the RDF Container. The statements making up the new RDF Container will be reported to the suppliedConsumerfunction.- Parameters:
containerType- defines the type of RDF Containervalues- anIterableof 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 ofValueto aLiteral. This conversion will fail with aLiteralUtilExceptionif the value's object type is not supported. SeeLiterals.createLiteralOrFail(ValueFactory, Object)for an overview of supported types.container- aResourcewhich 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- theConsumerfunction for the Statements of the RDF Container. May not benull.vf- theValueFactoryto use for creation of new model objects. May not benullcontexts- 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:
- RDF Schema 1.1 section on Collection vocabulary,
Literals.createLiteralOrFail(ValueFactory, Object)
-
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 suppliedModeland sends each collection memberValueto the suppliedConsumerfunction. 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- theResourcethat 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 JavaConsumerfunction 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:
- RDF Schema 1.1 section on Collection vocabulary
-
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 suppliedheadresource 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- theResourcethat represents the container head, that is the start resource of the RDF Container to be read. May not benull. aCollectionofStatementobjects (for example aModel) to which the RDF Container statements will be added. May not benull.sink- aCollectionofStatementobjects (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
CollectionofStatements, 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 suppliedheadresource from the supplied sourceModeland 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- theResourcethat represents the container head, that is the start resource of the RDF Container to be read. May not benull. aCollectionofStatementobjects (for example aModel) to which the RDF Container statements will be added. May not benull.consumer- theConsumerfunction 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 E extends RDF4JException
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 suppliedConsumerfunction. 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- theResourcethat represents the container head, that is the start resource of the RDF Container to be read. May not benull.collectionConsumer- the JavaConsumerfunction 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.E extends RDF4JException
-
-