Class RDF4J
- All Implemented Interfaces:
org.apache.commons.rdf.api.RDF
The RDF4J()
constructor uses a SimpleValueFactory
to create
corresponding RDF4J Value
instances. Alternatively, this factory can
be constructed with a different ValueFactory
using
RDF4J(ValueFactory)
.
asRDFTerm(Value)
can be used to convert any RDF4J Value
to
an RDFTerm. Note that adapted BNode
s are considered equal if they are
converted with the same RDF4J
instance and have the same
BNode.getID()
.
createGraph()
creates a new Graph backed by LinkedHashModel
.
To use other models, see asGraph(Model)
.
To adapt a RDF4J Repository
as a Dataset
or Graph
,
use asDataset(Repository, Option...)
or
asGraph(Repository, Option...)
.
asTriple(Statement)
can be used to convert a RDF4J Statement
to a Commons RDF Triple
, and equivalent asQuad(Statement)
to
convert a Quad
.
To convert any Triple
or Quad
to RDF4J Statement
,
use asStatement(TripleLike)
. This recognizes previously converted
RDF4JTriple
s and RDF4JQuad
s without re-converting their
RDF4JTripleLike.asStatement()
.
Likewise, asValue(RDFTerm)
can be used to convert any Commons RDF
RDFTerm
to a corresponding RDF4J Value
. This recognizes
previously converted RDF4JTerm
s without re-converting their
RDF4JTerm.asValue()
.
For the purpose of BlankNode
equivalence, this factory contains an
internal UUID
salt that is used by adapter methods like
asQuad(Statement)
, asTriple(Statement)
,
asRDFTerm(Value)
as well as createBlankNode(String)
. As
RDF4J BNode
instances from multiple repositories or models may have
the same BNode.getID()
, converting them with the above methods might
cause accidental BlankNode
equivalence. Note that the Graph
and Dataset
adapter methods like
asDataset(Repository, Option...)
and
asGraph(Repository, Option...)
therefore uses a unique RDF4J
internally.
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionasDataset
(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFDataset
.asGraph
(org.eclipse.rdf4j.model.Model model) Adapt an RDF4JModel
as a Commons RDFGraph
.asGraph
(org.eclipse.rdf4j.repository.Repository repository, Set<? extends org.apache.commons.rdf.api.BlankNodeOrIRI> contexts, RDF4J.Option... option) Adapt an RDF4JRepository
as a Commons RDFGraph
.asGraph
(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFGraph
.asGraphUnion
(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFGraph
.asQuad
(org.eclipse.rdf4j.model.Statement statement) Adapt a RDF4JStatement
as a Commons RDFQuad
.asRDFTerm
(org.eclipse.rdf4j.model.BNode value) Adapt a RDF4JBNode
as a Commons RDFBlankNode
asRDFTerm
(org.eclipse.rdf4j.model.IRI value) Adapt a RDF4JIRI
as a Commons RDFIRI
asRDFTerm
(org.eclipse.rdf4j.model.Literal value) Adapt a RDF4JLiteral
as a Commons RDFLiteral
asRDFTerm
(org.eclipse.rdf4j.model.Resource value) Adapt a RDF4JResource
as a Commons RDFBlankNodeOrIRI
asRDFTerm
(org.eclipse.rdf4j.model.Value value) Adapt a RDF4JValue
as a Commons RDFRDFTerm
.static RDF4JTerm
Adapt a RDF4JValue
as a Commons RDFRDFTerm
.org.eclipse.rdf4j.model.Statement
asStatement
(org.apache.commons.rdf.api.TripleLike tripleLike) Adapt a Commons RDFTriple
orQuad
as a RDF4JStatement
.asTriple
(org.eclipse.rdf4j.model.Statement statement) Adapt a RDF4JStatement
as a Commons RDFTriple
.org.eclipse.rdf4j.model.Value
asValue
(org.apache.commons.rdf.api.RDFTerm term) Adapt a Commons RDFRDFTerm
as a RDF4JValue
.createBlankNode
(String name) createLiteral
(String lexicalForm) org.apache.commons.rdf.api.Literal
createLiteral
(String lexicalForm, String languageTag) org.apache.commons.rdf.api.Literal
createLiteral
(String lexicalForm, org.apache.commons.rdf.api.IRI dataType) org.apache.commons.rdf.api.Quad
createQuad
(org.apache.commons.rdf.api.BlankNodeOrIRI graphName, org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) createTriple
(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) org.eclipse.rdf4j.model.ValueFactory
-
Constructor Details
-
RDF4J
public RDF4J()Constructs anRDF4J
. -
RDF4J
Constructs anRDF4J
.This constructor may be used if reproducible
BlankNode.uniqueReference()
inBlankNode
is desirable.- Parameters:
salt
- AnUUID
salt to be used by any createdBlankNode
s for the purpose ofBlankNode.uniqueReference()
-
RDF4J
public RDF4J(org.eclipse.rdf4j.model.ValueFactory valueFactory) Constructs anRDF4J
.This constructor is intended for use with the value factory from
Repository.getValueFactory()
when using Repository-based graphs and datasets.- Parameters:
valueFactory
- The RDF4JValueFactory
to use
-
RDF4J
Constructs anRDF4J
.This constructor may be used if reproducible
BlankNode.uniqueReference()
inBlankNode
is desirable.- Parameters:
valueFactory
- The RDF4JValueFactory
to usesalt
- AnUUID
salt to be used by any createdBlankNode
s for the purpose ofBlankNode.uniqueReference()
-
-
Method Details
-
asRDFTerm
Adapt a RDF4JValue
as a Commons RDFRDFTerm
.The value will be of the same kind as the term, e.g. a
BNode
is converted to aBlankNode
, aIRI
is converted to aIRI
and aLiteral
. is converted to aLiteral
- Parameters:
value
- The RDF4JValue
to convert.salt
- AUUID
salt to use for uniquely mapping anyBNode
s. The salt should typically be the same for multiple statements in the sameRepository
orModel
to ensureBlankNode.equals(Object)
andBlankNode.uniqueReference()
works as intended.- Returns:
- A
RDFTerm
that corresponds to the RDF4J value - Throws:
IllegalArgumentException
- if the value is not a BNode, Literal or IRI
-
asDataset
public RDF4JDataset asDataset(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFDataset
.Changes to the dataset are reflected in the repository, and vice versa.
Note: Some operations on the
RDF4JDataset
requires the use of try-with-resources to close underlyingRepositoryConnection
s, includingRDF4JDataset.iterate()
,RDF4JDataset.stream()
andRDF4JDataset.getGraphNames()
.- Parameters:
repository
- RDF4JRepository
to connect to.options
- Zero or moreRDF4J.Option
- Returns:
- A
Dataset
backed by the RDF4J repository.
-
asGraph
Adapt an RDF4JModel
as a Commons RDFGraph
.Changes to the graph are reflected in the model, and vice versa.
- Parameters:
model
- RDF4JModel
to adapt.- Returns:
- Adapted
Graph
.
-
asGraph
public RDF4JGraph asGraph(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFGraph
.The graph will only include triples in the default graph (equivalent to context
new Resource[0]{null})
in RDF4J).Changes to the graph are reflected in the repository, and vice versa.
Note: Some operations on the
RDF4JGraph
requires the use of try-with-resources to close underlyingRepositoryConnection
s, includingRDF4JGraph.iterate()
andRDF4JGraph.stream()
.- Parameters:
repository
- RDF4JRepository
to connect to.options
- Zero or moreRDF4J.Option
- Returns:
- A
Graph
backed by the RDF4J repository.
-
asGraph
public RDF4JGraph asGraph(org.eclipse.rdf4j.repository.Repository repository, Set<? extends org.apache.commons.rdf.api.BlankNodeOrIRI> contexts, RDF4J.Option... option) Adapt an RDF4JRepository
as a Commons RDFGraph
.The graph will include triples in the specified contexts.
Changes to the graph are reflected in the repository, and vice versa. Triples added/removed to the graph are reflected in all the specified contexts.
Note: Some operations on the
RDF4JGraph
requires the use of try-with-resources to close underlyingRepositoryConnection
s, includingRDF4JGraph.iterate()
andRDF4JGraph.stream()
.- Parameters:
repository
- RDF4JRepository
to connect to.contexts
- ASet
ofBlankNodeOrIRI
specifying the graph names to use as a context. The set may include the valuenull
to indicate the default graph. The empty set indicates any context, e.g. the union graph.option
- Zero or moreRDF4J.Option
s- Returns:
- A
Graph
backed by the RDF4J repository.
-
asGraphUnion
public RDF4JGraph asGraphUnion(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepository
as a Commons RDFGraph
.The graph will include triples in any contexts (e.g. the union graph).
Changes to the graph are reflected in the repository, and vice versa.
- Parameters:
repository
- RDF4JRepository
to connect to.options
- Zero or moreRDF4J.Option
- Returns:
- A union
Graph
backed by the RDF4J repository.
-
asQuad
Adapt a RDF4JStatement
as a Commons RDFQuad
.For the purpose of
BlankNode
equivalence, this method will use an internal salt UUID that is unique per instance ofRDF4J
.NOTE: If combining RDF4J
Statement
s multiple repositories or models, then theirBNode
s may have the sameBNode.getID()
, which with this method would become equivalent according toBlankNode.equals(Object)
andBlankNode.uniqueReference()
, unless a separateRDF4J
instance is used per RDF4J repository/model.- Parameters:
statement
- The statement to convert- Returns:
- A
RDF4JQuad
that is equivalent to the statement
-
asRDFTerm
Adapt a RDF4JBNode
as a Commons RDFBlankNode
For the purpose of
BlankNode
equivalence, this method will use an internal salt UUID that is unique per instance ofRDF4J
.NOTE: If combining RDF4J values from multiple repositories or models, then their
BNode
s may have the sameBNode.getID()
, which with this method would become equivalent according toBlankNode.equals(Object)
andBlankNode.uniqueReference()
, unless a separateRDF4J
instance is used per RDF4J repository/model.- Parameters:
value
- The RDF4JBNode
to convert.- Returns:
- A
RDF4JBlankNode
that corresponds to the RDF4J BNode
-
asRDFTerm
Adapt a RDF4JLiteral
as a Commons RDFLiteral
- Parameters:
value
- The RDF4JLiteral
to convert.- Returns:
- A
RDF4JLiteral
that corresponds to the RDF4J literal
-
asRDFTerm
Adapt a RDF4JIRI
as a Commons RDFIRI
- Parameters:
value
- The RDF4JValue
to convert.- Returns:
- A
RDF4JIRI
that corresponds to the RDF4J IRI
-
asRDFTerm
Adapt a RDF4JResource
as a Commons RDFBlankNodeOrIRI
- Parameters:
value
- The RDF4JValue
to convert.- Returns:
- A
RDF4JBlankNodeOrIRI
that corresponds to the RDF4J Resource
-
asRDFTerm
Adapt a RDF4JValue
as a Commons RDFRDFTerm
.The value will be of the same kind as the term, e.g. a
BNode
is converted to aBlankNode
, aIRI
is converted to aIRI
and aLiteral
. is converted to aLiteral
For the purpose of
BlankNode
equivalence, this method will use an internal salt UUID that is unique per instance ofRDF4J
.NOTE: If combining RDF4J values from multiple repositories or models, then their
BNode
s may have the sameBNode.getID()
, which with this method would become equivalent according toBlankNode.equals(Object)
andBlankNode.uniqueReference()
, unless a separateRDF4J
instance is used per RDF4J repository/model.- Parameters:
value
- The RDF4JValue
to convert.- Returns:
- A
RDFTerm
that corresponds to the RDF4J value - Throws:
IllegalArgumentException
- if the value is not a BNode, Literal or IRI
-
asStatement
public org.eclipse.rdf4j.model.Statement asStatement(org.apache.commons.rdf.api.TripleLike tripleLike) Adapt a Commons RDFTriple
orQuad
as a RDF4JStatement
.If the
tripleLike
argument is anRDF4JTriple
or aRDF4JQuad
, then itsRDF4JTripleLike.asStatement()
is returned as-is. Note that this means that aRDF4JTriple
would preserve itsStatement.getContext()
, and that anyBlankNode
s would be deemed equivalent in RDF4J if they have the sameBNode.getID()
.- Parameters:
tripleLike
- ATriple
orQuad
to adapt- Returns:
- A corresponding
Statement
-
asTriple
Adapt a RDF4JStatement
as a Commons RDFTriple
.For the purpose of
BlankNode
equivalence, this method will use an internal salt UUID that is unique per instance ofRDF4J
.NOTE: If combining RDF4J statements from multiple repositories or models, then their
BNode
s may have the sameBNode.getID()
, which with this method would become equivalent according toBlankNode.equals(Object)
andBlankNode.uniqueReference()
, unless a separateRDF4J
instance is used per RDF4J repository/model.- Parameters:
statement
- The RDF4JStatement
to adapt.- Returns:
- A
RDF4JTriple
that is equivalent to the statement
-
asValue
public org.eclipse.rdf4j.model.Value asValue(org.apache.commons.rdf.api.RDFTerm term) Adapt a Commons RDFRDFTerm
as a RDF4JValue
.The value will be of the same kind as the term, e.g. a
BlankNode
is converted to aBNode
, aIRI
is converted to aIRI
and aLiteral
is converted to aLiteral
.If the provided
RDFTerm
isnull
, then the returned value isnull
.If the provided term is an instance of
RDF4JTerm
, then theRDF4JTerm.asValue()
is returned without any conversion. Note that this could mean that aValue
from a different kind ofValueFactory
could be returned.- Parameters:
term
- RDFTerm to adapt to RDF4J Value- Returns:
- Adapted RDF4J
Value
-
createBlankNode
- Specified by:
createBlankNode
in interfaceorg.apache.commons.rdf.api.RDF
-
createBlankNode
- Specified by:
createBlankNode
in interfaceorg.apache.commons.rdf.api.RDF
-
createDataset
Note: Some operations on the
RDF4JDataset
requires the use of try-with-resources to close underlyingRepositoryConnection
s, includingRDF4JDataset.iterate()
,RDF4JDataset.stream()
andRDF4JDataset.getGraphNames()
.- Specified by:
createDataset
in interfaceorg.apache.commons.rdf.api.RDF
-
createGraph
- Specified by:
createGraph
in interfaceorg.apache.commons.rdf.api.RDF
-
createIRI
- Specified by:
createIRI
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
createLiteral
- Specified by:
createLiteral
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
createLiteral
public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType) throws IllegalArgumentException - Specified by:
createLiteral
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
createLiteral
public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag) throws IllegalArgumentException - Specified by:
createLiteral
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
createQuad
public org.apache.commons.rdf.api.Quad createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI graphName, org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) throws IllegalArgumentException - Specified by:
createQuad
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
createTriple
public RDF4JTriple createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) throws IllegalArgumentException - Specified by:
createTriple
in interfaceorg.apache.commons.rdf.api.RDF
- Throws:
IllegalArgumentException
-
getValueFactory
public org.eclipse.rdf4j.model.ValueFactory getValueFactory()
-