public final class JenaRDF extends Object implements RDF
Instances of JenaRDF can also convert existing objects from Jena with methods
like asRDFTerm(Node) and
asGraph(org.apache.jena.graph.Graph), and vice versa from any
Commons RDF object to Jena with the asJena* methods like
asJenaNode(RDFTerm) and asJenaGraph(Graph).
Note that Commons RDF objects created by this class implement the
specializations interfaces like JenaRDFTerm, JenaGraph and
JenaTriple, which provide access to the underlying Jena objects, e.g.
with JenaRDFTerm.asJenaNode().
For the purpose of BlankNode identity when using
createBlankNode(String) (see BlankNode.equals(Object) and
BlankNode.uniqueReference()), each instance of JenaRDF uses an
internal random state. If for some reason consistent/reproducible BlankNode
identity is desired, it is possible to retrieve the state as a UUID using
salt() for subsequent use with JenaRDF(UUID) - note
that such consistency is only guaranteed within the same minor version of
Commons RDF.
RDF| Constructor and Description |
|---|
JenaRDF()
Create a JenaRDF.
|
JenaRDF(UUID salt)
Create a JenaRDF.
|
| Modifier and Type | Method and Description |
|---|---|
JenaDataset |
asDataset(org.apache.jena.query.Dataset datasetGraph)
Adapt an existing Jena
Dataset to
CommonsRDF Dataset. |
JenaDataset |
asDataset(org.apache.jena.sparql.core.DatasetGraph datasetGraph)
Adapt an existing Jena
DatasetGraph to CommonsRDF
Dataset. |
JenaQuadLike<RDFTerm> |
asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad)
Adapt a generalized Jena
Quad to a
CommonsRDF QuadLike. |
JenaTripleLike |
asGeneralizedTriple(org.apache.jena.graph.Triple triple)
Adapt a generalized Jena
Triple to a
CommonsRDF TripleLike. |
JenaGraph |
asGraph(org.apache.jena.graph.Graph graph)
Adapt an existing Jena
Graph to CommonsRDF
Graph. |
JenaGraph |
asGraph(org.apache.jena.rdf.model.Model model)
Adapt an existing Jena
Model to
CommonsRDF Graph. |
org.apache.jena.query.Dataset |
asJenaDataset(Dataset dataset)
Convert a CommonsRDF Dataset to a Jena Dataset.
|
org.apache.jena.sparql.core.DatasetGraph |
asJenaDatasetGraph(Dataset dataset)
Convert a CommonsRDF Dataset to a Jena DatasetGraph.
|
org.apache.jena.graph.Graph |
asJenaGraph(Graph graph)
Convert a CommonsRDF Graph to a Jena Graph.
|
Optional<org.apache.jena.riot.Lang> |
asJenaLang(RDFSyntax rdfSyntax)
Return Jena
Lang corresponding to a RDFSyntax. |
org.apache.jena.graph.Node |
asJenaNode(RDFTerm term)
Convert a CommonsRDF RDFTerm to a Jena Node.
|
org.apache.jena.sparql.core.Quad |
asJenaQuad(Quad quad)
Convert a CommonsRDF
Quad to a Jena
Quad. |
org.apache.jena.graph.Triple |
asJenaTriple(Triple triple)
Convert a CommonsRDF
Triple to a Jena
Triple. |
JenaQuad |
asQuad(org.apache.jena.sparql.core.Quad quad)
Adapt an existing Jena
Quad to
CommonsRDF Quad. |
static Quad |
asQuad(RDF factory,
org.apache.jena.sparql.core.Quad quad)
Convert from Jena
Quad to a Commons
RDF Quad. |
Optional<RDFSyntax> |
asRDFSyntax(org.apache.jena.riot.Lang lang)
Return
RDFSyntax corresponding to a Jena Lang. |
JenaRDFTerm |
asRDFTerm(org.apache.jena.graph.Node node)
Adapt an existing Jena Node to CommonsRDF
RDFTerm. |
static RDFTerm |
asRDFTerm(RDF factory,
org.apache.jena.graph.Node node)
Convert from Jena
Node to any Commons RDF implementation. |
static Triple |
asTriple(RDF factory,
org.apache.jena.graph.Triple triple)
Convert from Jena
Triple to a Commons RDF
Triple. |
JenaTriple |
asTriple(org.apache.jena.graph.Triple triple)
Adapt an existing Jena Triple to CommonsRDF
Triple. |
JenaBlankNode |
createBlankNode()
Create a new blank node.
|
JenaBlankNode |
createBlankNode(String name)
Create a blank node based on the given name.
|
JenaDataset |
createDataset()
Create a new dataset.
|
JenaGeneralizedQuadLike |
createGeneralizedQuad(RDFTerm subject,
RDFTerm predicate,
RDFTerm object,
RDFTerm graphName)
Create a generalized Jena quad.
|
JenaGeneralizedTripleLike |
createGeneralizedTriple(RDFTerm subject,
RDFTerm predicate,
RDFTerm object)
Create a generalized Jena triple.
|
JenaGraph |
createGraph()
Create a new graph.
|
JenaIRI |
createIRI(String iri)
Create an IRI from a (possibly escaped) String.
|
JenaLiteral |
createLiteral(String lexicalForm)
Create a simple literal.
|
JenaLiteral |
createLiteral(String lexicalForm,
IRI dataType)
Create a literal with the specified data type.
|
JenaLiteral |
createLiteral(String lexicalForm,
String languageTag)
Create a language-tagged literal.
|
JenaQuad |
createQuad(BlankNodeOrIRI graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Create a quad.
|
JenaTriple |
createTriple(BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Create a triple.
|
UUID |
salt()
Return the
UUID salt used by this factory. |
org.apache.jena.riot.system.StreamRDF |
streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer)
Create a
StreamRDF instance that inserts generalized
QuadLikes. |
org.apache.jena.riot.system.StreamRDF |
streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer)
Create a
StreamRDF instance that inserts generalized
TripleLikes. |
static org.apache.jena.riot.system.StreamRDF |
streamJenaToQuad(RDF factory,
Consumer<Quad> consumer)
Create a
StreamRDF instance that inserts the converted
Quads. |
public JenaRDF()
public JenaRDF(UUID salt)
This constructor will use the specified UUID as a salt for the
purposes of BlankNode identity, and should only be used in cases
where predictable and consistent BlankNode.uniqueReference() are
important.
public JenaBlankNode createBlankNode()
RDF
The returned blank node MUST NOT be equal to any existing
BlankNode instances according to
BlankNode.equals(Object).
createBlankNode in interface RDFBlankNodepublic JenaBlankNode createBlankNode(String name)
RDF
All BlankNodes created with the given name on a
particular instance of RDF MUST be equivalent according
to BlankNode.equals(Object),
The returned BlankNode MUST NOT be equal to BlankNode
instances returned for any other name or those returned from
RDF.createBlankNode().
The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
on a different RDF instance, e.g. different
instances of RDF should produce different blank nodes for
the same name unless they purposely are intending to create
equivalent BlankNode instances (e.g. a reinstated
Serializable factory).
createBlankNode in interface RDFname - A non-empty, non-null, String that is unique to this blank
node in the context of this RDF.public JenaDataset createDataset()
RDFcreateDataset in interface RDFpublic JenaGraph createGraph()
RDFcreateGraph in interface RDFpublic JenaIRI createIRI(String iri)
RDFpublic JenaLiteral createLiteral(String lexicalForm)
RDFLiteral.getLexicalForm() that is
equal to the provided lexical form, MUST NOT have a
Literal.getLanguageTag() present, and SHOULD return a
Literal.getDatatype() that is equal to the IRI
http://www.w3.org/2001/XMLSchema#string.createLiteral in interface RDFlexicalForm - The literal value in plain textpublic JenaLiteral createLiteral(String lexicalForm, IRI dataType)
RDFLiteral.getLexicalForm() that
is equal to the provided lexicalForm, MUST NOT have a
Literal.getLanguageTag() present, and MUST return a
Literal.getDatatype() that is equivalent to the provided dataType
IRI.createLiteral in interface RDFlexicalForm - The literal valuedataType - The data type IRI for the literal value, e.g.
http://www.w3.org/2001/XMLSchema#integerpublic JenaLiteral createLiteral(String lexicalForm, String languageTag)
RDFen.
The provided language tag
MAY be converted to lower case.
The returned Literal SHOULD have a Literal.getLexicalForm() which
is equal to the provided lexicalForm, MUST return a
Literal.getDatatype() that is equal to the IRI
http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, and
MUST have a Literal.getLanguageTag() present which SHOULD be
equal to the provided language tag (compared as
String.toLowerCase(Locale) using Locale.ENGLISH).createLiteral in interface RDFlexicalForm - The literal valuelanguageTag - The non-empty language tag as defined by
BCP47public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
RDFTriple.getSubject() that is
equal to the provided subject, a Triple.getPredicate() that is
equal to the provided predicate, and a Triple.getObject() that is
equal to the provided object.createTriple in interface RDFsubject - 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 triplepublic JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException, UnsupportedOperationException
The returned Quad SHOULD have a Quad.getGraphName() that is equal
to the provided graphName, a Quad.getSubject() that is equal to
the provided subject, a Quad.getPredicate() that is equal to the
provided predicate, and a Quad.getObject() that is equal to the
provided object.
In addition to supporting a graphName of null
for representing a triple in the default graph, this method also
recognize a JenaIRI which JenaRDFTerm.asJenaNode()
represent the default graph according to
Quad.isDefaultGraph(Node), in which
case the returned JenaQuad will have a Quad.getGraphName() of
Optional.empty() rather than the provided IRI.
createQuad in interface RDFgraphName - The IRI or BlankNode that this quad belongs to, or
null for 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 quadIllegalArgumentException - 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.UnsupportedOperationExceptionpublic JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object)
The generalized triple supports any RDFTerm as its
TripleLike.getSubject() TripleLike.getPredicate() or
TripleLike.getObject().
subject - The subject of the statementpredicate - The predicate of the statementobject - The object of the statementTripleLike. Note that the generalized triple
does not implement Triple.equals(Object)
or Triple.hashCode().createTriple(BlankNodeOrIRI, IRI, RDFTerm),
createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName)
The generalized quad supports any RDFTerm as its
TripleLike.getSubject() TripleLike.getPredicate(),
TripleLike.getObject() or TripleLike.getObject().
In addition to supporting a graphName of null
for representing a triple in the default graph, this method also
recognize a JenaIRI which JenaRDFTerm.asJenaNode()
represent the default graph according to
Quad.isDefaultGraph(Node), in which
case the returned JenaQuad will have a Quad.getGraphName() of
Optional.empty() rather than the provided IRI.
subject - The subject of the statementpredicate - The predicate of the statementobject - The object of the statementgraphName - The graph name of the statementQuadLike. Note that the generalized quad does
not implement Quad.equals(Object) or
Quad.hashCode().createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm),
createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)public JenaRDFTerm asRDFTerm(org.apache.jena.graph.Node node) throws ConversionException
RDFTerm.
If Node.isLiteral(), then the returned value is a
Literal. If Node.isURI(), the returned value is a IRI. If
{$@link Node#isBlank()}, the returned value is a BlankNode, which
will use a UUID salt from this JenaRDF instance in
combination with Node.getBlankNodeId() for the purpose of its
BlankNode.uniqueReference().
node - The Jena Node to adapt. It's Node.isConcrete() must be
true.JenaRDFTermConversionException - If the Node can't be represented as an
RDFTerm, e.g. if the node is not concrete or
represents a variable in Jena.asRDFTerm(RDF, Node)public static RDFTerm asRDFTerm(RDF factory, org.apache.jena.graph.Node node)
Node to any Commons RDF implementation.
Note that if the Node.isBlank(), then the factory's
RDF.createBlankNode(String) will be used, meaning that care
should be taken if reusing an RDF instance for multiple
conversion sessions.
factory - RDF to use for creating RDFTerm.node - The Jena Node to adapt. It's Node.isConcrete() must be
true.RDFTermConversionException - If the Node can't be represented as an
RDFTerm, e.g. if the node is not concrete or
represents a variable in Jena.asRDFTerm(Node)public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException
Triple.
If the triple contains any Node.isBlank(), then any corresponding
BlankNode will use a UUID salt from this JenaRDF
instance in combination with Node.getBlankNodeId() for the
purpose of its BlankNode.uniqueReference().
triple - Jena Triple to adaptJenaTripleConversionException - if any of the triple's nodes are not concrete or the triple
is a generalized tripleasTriple(RDF, org.apache.jena.graph.Triple)public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException
Triple to a
CommonsRDF TripleLike.
The generalized triple supports any RDFTerm as its
TripleLike.getSubject() TripleLike.getPredicate() or
TripleLike.getObject().
If the Jena triple contains any Node.isBlank(), then any
corresponding BlankNode will use a UUID salt from this
JenaRDF instance in combination with
Node.getBlankNodeId() for the purpose of its
BlankNode.uniqueReference().
triple - Jena tripleTripleLike. Note that the generalized triple does
not implement Triple.equals(Object) or
Triple.hashCode().ConversionException - if any of the triple's nodes are not concreteasTriple(RDF, org.apache.jena.graph.Triple)public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException
Quad to a
CommonsRDF QuadLike.
The generalized quad supports any RDFTerm as its
QuadLike.getGraphName(), TripleLike.getSubject()
TripleLike.getPredicate() or TripleLike.getObject().
If the Jena quad contains any Node.isBlank(), then any
corresponding BlankNode will use a UUID salt from this
JenaRDF instance in combination with
Node.getBlankNodeId() for the purpose of its
BlankNode.uniqueReference().
If the provided quad Quad.isDefaultGraph(),
the returned JenaQuadLike has a QuadLike.getGraphName()
of Optional.empty().
quad - Jena quadQuadLike. Note that the generalized quad does
not implement Quad.equals(Object) or
Quad.hashCode().ConversionException - if any of the quad nodes are not concreteasQuad(org.apache.jena.sparql.core.Quad),
asGeneralizedTriple(org.apache.jena.graph.Triple)public static Triple asTriple(RDF factory, org.apache.jena.graph.Triple triple) throws ConversionException
Triple to a Commons RDF
Triple.
Note that if any of the triple's nodes Node.isBlank(), then the
factory's RDF.createBlankNode(String) will be used, meaning that
care should be taken if reusing an RDF instance for multiple
conversion sessions.
factory - RDF to use for creating the Triple and its
RDFTerms.triple - Jena tripleConversionException - if any of the triple's nodes are not concrete or the triple
is a generalized tripleasTriple(org.apache.jena.graph.Triple)public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad)
Quad to
CommonsRDF Quad.
If the quad contains any Node.isBlank(), then any corresponding
BlankNode will use a UUID salt from this JenaRDF
instance in combination with Node.getBlankNodeId() for the
purpose of its BlankNode.uniqueReference().
If the provided quad Quad.isDefaultGraph(),
the returned JenaQuad has a Quad.getGraphName()
of Optional.empty().
quad - Jena quadpublic JenaGraph asGraph(org.apache.jena.graph.Graph graph)
Graph to CommonsRDF
Graph.
This does not take a copy, changes to the CommonsRDF Graph are reflected
in the jena graph, which is accessible from
JenaGraph.asJenaGraph().
If the graph contains any Node.isBlank(), then any corresponding
BlankNode will use a UUID salt from this JenaRDF
instance in combination with Node.getBlankNodeId() for the
purpose of its BlankNode.uniqueReference().
graph - Jena Graph to adaptJenaGraphpublic JenaGraph asGraph(org.apache.jena.rdf.model.Model model)
Model to
CommonsRDF Graph.
This does not ake a copy, changes to the CommonsRDF Graph are reflected
in the jena graph, which is accessible from
JenaGraph.asJenaGraph().
If the graph contains any Node.isBlank(), then any corresponding
BlankNode will use a UUID salt from this JenaRDF
instance in combination with Node.getBlankNodeId() for the
purpose of its BlankNode.uniqueReference().
model - Jena Model to adaptJenaGraphpublic JenaDataset asDataset(org.apache.jena.sparql.core.DatasetGraph datasetGraph)
DatasetGraph to CommonsRDF
Dataset.
This does not take a copy, changes to the CommonsRDF Dataset are
reflected in the jena dataset graph, which is accessible from
JenaDataset.asJenaDatasetGraph().
If the dataset contains any Node.isBlank(), then any
corresponding BlankNode will use a UUID salt from this
JenaRDF instance in combination with
Node.getBlankNodeId() for the purpose of its
BlankNode.uniqueReference().
datasetGraph - Jena DatasetGraph to adaptJenaDatasetpublic JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph)
Dataset to
CommonsRDF Dataset.
This does not take a copy, changes to the CommonsRDF Dataset are
reflected in the jena dataset graph, which is accessible from
JenaDataset.asJenaDatasetGraph().
If the dataset contains any Node.isBlank(), then any
corresponding BlankNode will use a UUID salt from this
JenaRDF instance in combination with
Node.getBlankNodeId() for the purpose of its
BlankNode.uniqueReference().
datasetGraph - Jena Dataset to adaptJenaDatasetpublic static Quad asQuad(RDF factory, org.apache.jena.sparql.core.Quad quad)
Quad to a Commons
RDF Quad.
Note that if any of the quad's nodes Node.isBlank(), then the
factory's RDF.createBlankNode(String) will be used, meaning that
care should be taken if reusing an RDF instance for multiple
conversion sessions.
If the provided quad Quad.isDefaultGraph(),
the returned JenaQuadLike has a QuadLike.getGraphName()
of Optional.empty().
factory - RDF to use for creating the Triple and its
RDFTerms.quad - Jena Quad to adaptQuadConversionException - if any of the quad's nodes are not concrete or the quad is a
generalized quadasQuad(org.apache.jena.sparql.core.Quad),
asGeneralizedQuad(org.apache.jena.sparql.core.Quad)public Optional<RDFSyntax> asRDFSyntax(org.apache.jena.riot.Lang lang)
RDFSyntax corresponding to a Jena Lang.lang - Lang to convertRDFSyntax, otherwise Optional.empty()public Optional<org.apache.jena.riot.Lang> asJenaLang(RDFSyntax rdfSyntax)
Lang corresponding to a RDFSyntax.rdfSyntax - RDFSyntax to convertLang, otherwise Optional.empty()public static org.apache.jena.riot.system.StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer)
public org.apache.jena.riot.system.StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer)
StreamRDF instance that inserts generalized
TripleLikes. into a the provided Consumer.
A generalized triple allows any RDFTerm for
TripleLike.getSubject(), TripleLike.getPredicate() and
TripleLike.getObject().
The returned StreamRDF can be used for instance with Jena's
RDFDataMgr.parse(StreamRDF, String).
generalizedConsumer - A Consumer of generalized TripleLikesStreamRDF that will stream generalized triples to the
consumerpublic org.apache.jena.riot.system.StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer)
StreamRDF instance that inserts generalized
QuadLikes. into a the provided Consumer.
A generalized quad allows any RDFTerm for
TripleLike.getSubject(), TripleLike.getPredicate(),
TripleLike.getObject() and QuadLike.getGraphName() .
The returned StreamRDF can be used for instance with Jena's
RDFDataMgr.parse(StreamRDF, String).
public org.apache.jena.query.Dataset asJenaDataset(Dataset dataset)
dataset - Commons RDF Dataset to convertDatasetpublic org.apache.jena.sparql.core.DatasetGraph asJenaDatasetGraph(Dataset dataset)
dataset - Commons RDF Dataset to convertDatasetGraphpublic org.apache.jena.graph.Graph asJenaGraph(Graph graph)
graph - Commons RDF Graph to convertGraphpublic org.apache.jena.graph.Node asJenaNode(RDFTerm term)
term - Commons RDF RDFTerm to convertNodepublic org.apache.jena.graph.Triple asJenaTriple(Triple triple)
Triple to a Jena
Triple.
If the triple was from Jena originally, return that original object, else create a copy using Jena objects.
triple - Commons RDF Triple to convertTriplepublic org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad)
Quad to a Jena
Quad.
If the quad was from Jena originally, return that original object, otherwise create a copy using Jena objects.
quad - Commons RDF Quad to convertQuadpublic UUID salt()
UUID salt used by this factory.
The salt is used for the purposes of BlankNode identity, see
BlankNode.uniqueReference() for details.
This salt can be used with the constructor JenaRDF(UUID)
if consistent or reproducible BlankNodes are desirable.
UUID used as saltCopyright © 2015–2018 The Apache Software Foundation. All rights reserved.