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.
|
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()
createBlankNode in interface RDFpublic JenaBlankNode createBlankNode(String name)
createBlankNode in interface RDFpublic JenaDataset createDataset()
createDataset in interface RDFpublic JenaGraph createGraph()
createGraph in interface RDFpublic JenaLiteral createLiteral(String lexicalForm)
createLiteral in interface RDFpublic JenaLiteral createLiteral(String lexicalForm, IRI dataType)
createLiteral in interface RDFpublic JenaLiteral createLiteral(String lexicalForm, String languageTag)
createLiteral in interface RDFpublic JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
createTriple in interface RDFpublic JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException, UnsupportedOperationException
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 RDFIllegalArgumentExceptionUnsupportedOperationExceptionpublic 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(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, 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(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(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(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, 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(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(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().
public JenaGraph asGraph(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().
public JenaDataset asDataset(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(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, 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(Lang lang)
lang - Lang to convertRDFSyntax, otherwise Optional.empty()public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax)
rdfSyntax - RDFSyntax to convertLang, otherwise Optional.empty()public static StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer)
StreamRDF instance that inserts the converted
Quads. into a the provided Consumer.
The returned StreamRDF can be used for instance with Jena's
RDFDataMgr.parse(StreamRDF, String).
public 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 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 Graph asJenaGraph(Graph graph)
public Node asJenaNode(RDFTerm term)
public 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–2020 The Apache Software Foundation. All rights reserved.