Class RDF4J
- All Implemented Interfaces:
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 BNodes 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 to RDF4J Statement,
use asStatement(TripleLike). This recognises previously converted
RDF4JTriples and RDF4JQuads without re-converting their
RDF4JTripleLike.asStatement().
Likewise, asValue(RDFTerm) can be used to convert any Commons RDF
RDFTerm to a corresponding RDF4J Value. This recognises
previously converted RDF4JTerms 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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static InternalRDF4JFactoryInternalRDF4JFactory is deliberately abstractprivate final UUIDprivate final org.eclipse.rdf4j.model.ValueFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasDataset(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepositoryas a Commons RDFDataset.asGraph(org.eclipse.rdf4j.model.Model model) Adapt an RDF4JModelas a Commons RDFGraph.asGraph(org.eclipse.rdf4j.repository.Repository repository, Set<? extends BlankNodeOrIRI> contexts, RDF4J.Option... option) Adapt an RDF4JRepositoryas a Commons RDFGraph.asGraph(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepositoryas a Commons RDFGraph.asGraphUnion(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepositoryas a Commons RDFGraph.asQuad(org.eclipse.rdf4j.model.Statement statement) Adapt a RDF4JStatementas a Commons RDFQuad.asRDFTerm(org.eclipse.rdf4j.model.BNode value) Adapt a RDF4JBNodeas a Commons RDFBlankNodeasRDFTerm(org.eclipse.rdf4j.model.IRI value) Adapt a RDF4JIRIas a Commons RDFIRIasRDFTerm(org.eclipse.rdf4j.model.Literal value) Adapt a RDF4JLiteralas a Commons RDFLiteralasRDFTerm(org.eclipse.rdf4j.model.Resource value) Adapt a RDF4JResourceas a Commons RDFBlankNodeOrIRIasRDFTerm(org.eclipse.rdf4j.model.Value value) Adapt a RDF4JValueas a Commons RDFRDFTerm.static RDF4JTermAdapt a RDF4JValueas a Commons RDFRDFTerm.org.eclipse.rdf4j.model.StatementasStatement(TripleLike tripleLike) asTriple(org.eclipse.rdf4j.model.Statement statement) Adapt a RDF4JStatementas a Commons RDFTriple.org.eclipse.rdf4j.model.ValueAdapt a Commons RDFRDFTermas a RDF4JValue.Create a new blank node.createBlankNode(String name) Create a blank node based on the given name.Create a new dataset.Create a new graph.Create an IRI from a (possibly escaped) String.createLiteral(String lexicalForm) Create a simple literal.createLiteral(String lexicalForm, String languageTag) Create a language-tagged literal.createLiteral(String lexicalForm, IRI dataType) Create a literal with the specified data type.createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Create a quad.createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Create a triple.org.eclipse.rdf4j.model.ValueFactoryprivate EnumSet<RDF4J.Option> optionSet(RDF4J.Option... options)
-
Field Details
-
rdf4j
InternalRDF4JFactory is deliberately abstract -
salt
-
valueFactory
private final org.eclipse.rdf4j.model.ValueFactory valueFactory
-
-
Constructor Details
-
RDF4J
public RDF4J()Construct anRDF4J. -
RDF4J
public RDF4J(org.eclipse.rdf4j.model.ValueFactory valueFactory) Construct anRDF4J.This constructor is intended for use with the value factory from
Repository.getValueFactory()when using Repository-based graphs and datasets.- Parameters:
valueFactory- The RDF4JValueFactoryto use
-
RDF4J
Construct anRDF4J.This constructor may be used if reproducible
BlankNode.uniqueReference()inBlankNodeis desirable.- Parameters:
salt- AnUUIDsalt to be used by any createdBlankNodes for the purpose ofBlankNode.uniqueReference()
-
RDF4J
Construct anRDF4J.This constructor may be used if reproducible
BlankNode.uniqueReference()inBlankNodeis desirable.- Parameters:
valueFactory- The RDF4JValueFactoryto usesalt- AnUUIDsalt to be used by any createdBlankNodes for the purpose ofBlankNode.uniqueReference()
-
-
Method Details
-
asQuad
Adapt a RDF4JStatementas a Commons RDFQuad.For the purpose of
BlankNodeequivalence, this method will use an internal salt UUID that is unique per instance ofRDF4J.NOTE: If combining RDF4J
Statements multiple repositories or models, then theirBNodes may have the sameBNode.getID(), which with this method would become equivalent according toBlankNode.equals(Object)andBlankNode.uniqueReference(), unless a separateRDF4Jinstance is used per RDF4J repository/model.- Parameters:
statement- The statement to convert- Returns:
- A
RDF4JQuadthat is equivalent to the statement
-
asRDFTerm
Adapt a RDF4JValueas a Commons RDFRDFTerm.The value will be of the same kind as the term, e.g. a
BNodeis converted to aBlankNode, aIRIis converted to aIRIand aLiteral. is converted to aLiteralFor the purpose of
BlankNodeequivalence, 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
BNodes may have the sameBNode.getID(), which with this method would become equivalent according toBlankNode.equals(Object)andBlankNode.uniqueReference(), unless a separateRDF4Jinstance is used per RDF4J repository/model.- Parameters:
value- The RDF4JValueto convert.- Returns:
- A
RDFTermthat corresponds to the RDF4J value - Throws:
IllegalArgumentException- if the value is not a BNode, Literal or IRI
-
asRDFTerm
Adapt a RDF4JBNodeas a Commons RDFBlankNodeFor the purpose of
BlankNodeequivalence, 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
BNodes may have the sameBNode.getID(), which with this method would become equivalent according toBlankNode.equals(Object)andBlankNode.uniqueReference(), unless a separateRDF4Jinstance is used per RDF4J repository/model.- Parameters:
value- The RDF4JBNodeto convert.- Returns:
- A
RDF4JBlankNodethat corresponds to the RDF4J BNode
-
asRDFTerm
Adapt a RDF4JLiteralas a Commons RDFLiteral- Parameters:
value- The RDF4JLiteralto convert.- Returns:
- A
RDF4JLiteralthat corresponds to the RDF4J literal
-
asRDFTerm
-
asRDFTerm
Adapt a RDF4JResourceas a Commons RDFBlankNodeOrIRI- Parameters:
value- The RDF4JValueto convert.- Returns:
- A
RDF4JBlankNodeOrIRIthat corresponds to the RDF4J Resource
-
asRDFTerm
Adapt a RDF4JValueas a Commons RDFRDFTerm.The value will be of the same kind as the term, e.g. a
BNodeis converted to aBlankNode, aIRIis converted to aIRIand aLiteral. is converted to aLiteral- Parameters:
value- The RDF4JValueto convert.salt- AUUIDsalt to use for uniquely mapping anyBNodes. The salt should typically be the same for multiple statements in the sameRepositoryorModelto ensureBlankNode.equals(Object)andBlankNode.uniqueReference()works as intended.- Returns:
- A
RDFTermthat 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 RDF4JRepositoryas a Commons RDFDataset.Changes to the dataset are reflected in the repository, and vice versa.
Note: Some operations on the
RDF4JDatasetrequires the use of try-with-resources to close underlyingRepositoryConnections, includingRDF4JDataset.iterate(),RDF4JDataset.stream()andRDF4JDataset.getGraphNames().- Parameters:
repository- RDF4JRepositoryto connect to.options- Zero or moreRDF4J.Option- Returns:
- A
Datasetbacked by the RDF4J repository.
-
asGraph
-
asGraph
public RDF4JGraph asGraph(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepositoryas 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
RDF4JGraphrequires the use of try-with-resources to close underlyingRepositoryConnections, includingRDF4JGraph.iterate()andRDF4JGraph.stream().- Parameters:
repository- RDF4JRepositoryto connect to.options- Zero or moreRDF4J.Option- Returns:
- A
Graphbacked by the RDF4J repository.
-
asGraphUnion
public RDF4JGraph asGraphUnion(org.eclipse.rdf4j.repository.Repository repository, RDF4J.Option... options) Adapt an RDF4JRepositoryas 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- RDF4JRepositoryto connect to.options- Zero or moreRDF4J.Option- Returns:
- A union
Graphbacked by the RDF4J repository.
-
asGraph
public RDF4JGraph asGraph(org.eclipse.rdf4j.repository.Repository repository, Set<? extends BlankNodeOrIRI> contexts, RDF4J.Option... option) Adapt an RDF4JRepositoryas 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
RDF4JGraphrequires the use of try-with-resources to close underlyingRepositoryConnections, includingRDF4JGraph.iterate()andRDF4JGraph.stream().- Parameters:
repository- RDF4JRepositoryto connect to.contexts- ASetofBlankNodeOrIRIspecifying the graph names to use as a context. The set may include the valuenullto indicate the default graph. The empty set indicates any context, e.g. the union graph.option- Zero or moreRDF4J.Options- Returns:
- A
Graphbacked by the RDF4J repository.
-
asStatement
Adapt a Commons RDFTripleorQuadas a RDF4JStatement.If the
tripleLikeargument is anRDF4JTripleor aRDF4JQuad, then itsRDF4JTripleLike.asStatement()is returned as-is. Note that this means that aRDF4JTriplewould preserve itsStatement.getContext(), and that anyBlankNodes would be deemed equivalent in RDF4J if they have the sameBNode.getID(). -
asTriple
Adapt a RDF4JStatementas a Commons RDFTriple.For the purpose of
BlankNodeequivalence, 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
BNodes may have the sameBNode.getID(), which with this method would become equivalent according toBlankNode.equals(Object)andBlankNode.uniqueReference(), unless a separateRDF4Jinstance is used per RDF4J repository/model.- Parameters:
statement- The RDF4JStatementto adapt.- Returns:
- A
RDF4JTriplethat is equivalent to the statement
-
asValue
Adapt a Commons RDFRDFTermas a RDF4JValue.The value will be of the same kind as the term, e.g. a
BlankNodeis converted to aBNode, aIRIis converted to aIRIand aLiteralis converted to aLiteral.If the provided
RDFTermisnull, 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 aValuefrom a different kind ofValueFactorycould be returned.- Parameters:
term- RDFTerm to adapt to RDF4J Value- Returns:
- Adapted RDF4J
Value
-
createBlankNode
Description copied from interface:RDFCreate a new blank node.The returned blank node MUST NOT be equal to any existing
BlankNodeinstances according toBlankNode.equals(Object).- Specified by:
createBlankNodein interfaceRDF- Returns:
- A new, unique
BlankNode
-
createBlankNode
Description copied from interface:RDFCreate a blank node based on the given name.All
BlankNodes created with the givennameon a particular instance ofRDFMUST be equivalent according toBlankNode.equals(Object),The returned BlankNode MUST NOT be equal to
BlankNodeinstances returned for any othernameor those returned fromRDF.createBlankNode().The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created on a different
RDFinstance, e.g. different instances ofRDFshould produce different blank nodes for the samenameunless they purposely are intending to create equivalentBlankNodeinstances (e.g. a reinstatedSerializablefactory).- Specified by:
createBlankNodein interfaceRDF- Parameters:
name- A non-empty, non-null, String that is unique to this blank node in the context of thisRDF.- Returns:
- A BlankNode for the given name
-
createDataset
Create a new dataset. It is undefined if the dataset will be persisted by any underlying storage mechanism.Note: Some operations on the
RDF4JDatasetrequires the use of try-with-resources to close underlyingRepositoryConnections, includingRDF4JDataset.iterate(),RDF4JDataset.stream()andRDF4JDataset.getGraphNames().- Specified by:
createDatasetin interfaceRDF- Returns:
- A new Dataset
-
createGraph
Description copied from interface:RDFCreate a new graph. It is undefined if the graph will be persisted by any underlying storage mechanism.- Specified by:
createGraphin interfaceRDF- Returns:
- A new Graph
-
createIRI
Description copied from interface:RDFCreate an IRI from a (possibly escaped) String. The provided iri string MUST be valid according to the W3C RDF-1.1 IRI definition.- Specified by:
createIRIin interfaceRDF- Parameters:
iri- Internationalized Resource Identifier- Returns:
- A new IRI
- Throws:
IllegalArgumentException- If the provided string is not acceptable, e.g. does not conform to the RFC3987 syntax.
-
createLiteral
Description copied from interface:RDFCreate a simple literal. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. The returned Literal MUST have aLiteral.getLexicalForm()that is equal to the provided lexical form, MUST NOT have aLiteral.getLanguageTag()present, and SHOULD return aLiteral.getDatatype()that is equal to the IRIhttp://www.w3.org/2001/XMLSchema#string.- Specified by:
createLiteralin interfaceRDF- Parameters:
lexicalForm- The literal value in plain text- Returns:
- The created Literal
- Throws:
IllegalArgumentException- If the provided lexicalForm is not acceptable, e.g. because it is too large for an underlying storage.
-
createLiteral
Description copied from interface:RDFCreate a literal with the specified data type. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. It is RECOMMENDED that the provided dataType is one of the RDF-compatible XSD types. The provided lexical form SHOULD be in the lexical space of the provided dataType. The returned Literal SHOULD have aLiteral.getLexicalForm()that is equal to the provided lexicalForm, MUST NOT have aLiteral.getLanguageTag()present, and MUST return aLiteral.getDatatype()that is equivalent to the provided dataType IRI.- Specified by:
createLiteralin interfaceRDF- Parameters:
lexicalForm- The literal valuedataType- The data type IRI for the literal value, e.g.http://www.w3.org/2001/XMLSchema#integer- Returns:
- The created Literal
- Throws:
IllegalArgumentException- If any of the provided arguments are not acceptable, e.g. because the provided dataType is not permitted.
-
createLiteral
public Literal createLiteral(String lexicalForm, String languageTag) throws IllegalArgumentException Description copied from interface:RDFCreate a language-tagged literal. The provided lexical form should not be escaped in any sense, e.g. should not include "quotes" unless those are part of the literal value. The provided language tag MUST be valid according to BCP47, e.g.en. The provided language tag MAY be converted to lower case. The returned Literal SHOULD have aLiteral.getLexicalForm()which is equal to the provided lexicalForm, MUST return aLiteral.getDatatype()that is equal to the IRIhttp://www.w3.org/1999/02/22-rdf-syntax-ns#langString, and MUST have aLiteral.getLanguageTag()present which SHOULD be equal to the provided language tag (compared asString.toLowerCase(Locale)usingLocale.ENGLISH).- Specified by:
createLiteralin interfaceRDF- Parameters:
lexicalForm- The literal valuelanguageTag- The non-empty language tag as defined by BCP47- Returns:
- The created Literal
- Throws:
IllegalArgumentException- If the provided values are not acceptable, e.g. because the languageTag was syntactically invalid.
-
createTriple
public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException Description copied from interface:RDFCreate a triple. The returned Triple SHOULD have aTriple.getSubject()that is equal to the provided subject, aTriple.getPredicate()that is equal to the provided predicate, and aTriple.getObject()that is equal to the provided object.- Specified by:
createTriplein interfaceRDF- Parameters:
subject- The IRI or BlankNode that is the subject of the triplepredicate- The IRI that is the predicate of the tripleobject- The IRI, BlankNode or Literal that is the object of the triple- Returns:
- The created Triple
- Throws:
IllegalArgumentException- If any of the provided arguments are not acceptable, e.g. because a Literal has a lexicalForm that is too large for an underlying storage.
-
createQuad
public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException Description copied from interface:RDFCreate a quad.The returned Quad SHOULD have a
Quad.getGraphName()that is equal to the provided graphName, aQuad.getSubject()that is equal to the provided subject, aQuad.getPredicate()that is equal to the provided predicate, and aQuad.getObject()that is equal to the provided object.- Specified by:
createQuadin interfaceRDF- Parameters:
graphName- The IRI or BlankNode that this quad belongs to, ornullfor the public graphsubject- The IRI or BlankNode that is the subject of the quadpredicate- The IRI that is the predicate of the quadobject- The IRI, BlankNode or Literal that is the object of the quad- Returns:
- The created Quad
- Throws:
IllegalArgumentException- If any of the provided arguments are not acceptable, e.g. because a Literal has a lexicalForm that is too large for an underlying storage.
-
getValueFactory
public org.eclipse.rdf4j.model.ValueFactory getValueFactory() -
optionSet
-