Interface RDF4JGraph
- All Superinterfaces:
AutoCloseable
,org.apache.commons.rdf.api.Graph
,org.apache.commons.rdf.api.GraphLike<org.apache.commons.rdf.api.Triple>
,RDF4JGraphLike<org.apache.commons.rdf.api.Triple>
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGets a copy of the context mask as aSet
ofRDF4JBlankNodeOrIRI
graph names.ClosableIterable
<org.apache.commons.rdf.api.Triple> iterate()
ClosableIterable
<org.apache.commons.rdf.api.Triple> iterate
(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) stream()
stream
(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) Methods inherited from interface org.apache.commons.rdf.api.Graph
add, add, clear, close, contains, contains, getTriples, getTriples, remove, remove, size
Methods inherited from interface org.apache.commons.rdfrdf4j.RDF4JGraphLike
asModel, asRepository
-
Method Details
-
getContextMask
Set<RDF4JBlankNodeOrIRI> getContextMask()Gets a copy of the context mask as aSet
ofRDF4JBlankNodeOrIRI
graph names.If the set is not
Set.isEmpty()
, the mask determines which contexts in the corresponding RDF4JModel
orRepository
that this graph reflect. Modifications to the graph (e.g.Graph.add(Triple)
will be performed for all the specified contexts, while retrieval (e.g.Graph.contains(Triple)
) will succeed if the triple is in at least one of the specified contexts.The context mask array may contain
null
, indicating the default context (the default graph in RDF datasets).If the context mask is
Set.isEmpty()
, then this is a union graph which triples reflect statements in any contexts. Triples added to the graph will be added in the default context, e.g. equivalent tonew Resource[1]{null}
) in RDF4J.Note that the context mask itself cannot be
null
.The returned set is an immutable copy; to specify a different mask, use
RDF4J.asGraph(Repository, Set, Option...)
- Returns:
- The context mask as a set of
BlankNodeOrIRI
graph names, which may contain the valuenull
.
-
iterate
ClosableIterable<org.apache.commons.rdf.api.Triple> iterate() throws ConcurrentModificationException, IllegalStateExceptionNote that for graphs backed by a repository (
RDF4JGraphLike.asRepository()
is present), the iterable must be closed withAutoCloseable.close()
.This can generally achieved using a try-with-resources block, e.g.:
try (ClosableIterable<Triple> s : graph.iterate()) { for (Triple t : triples) { return t; // OK to terminate for-loop early } }
If you don't use a try-with-resources block, the iterator will attempt to close the ClosableIterable when reaching the end of the iteration.- Specified by:
iterate
in interfaceorg.apache.commons.rdf.api.Graph
- Specified by:
iterate
in interfaceorg.apache.commons.rdf.api.GraphLike<org.apache.commons.rdf.api.Triple>
- Throws:
ConcurrentModificationException
IllegalStateException
-
iterate
ClosableIterable<org.apache.commons.rdf.api.Triple> iterate(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) Note that for graphs backed by a repository (
RDF4JGraphLike.asRepository()
is present), the iterable must be closed withAutoCloseable.close()
.This can generally achieved using a try-with-resources block, e.g.:
try (ClosableIterable<Triple> s : graph.iterate(s,p,o)) { for (Triple t : triples) { return t; // OK to terminate for-loop early } }
If you don't use a try-with-resources block, the iterator will attempt to close the ClosableIterable when reaching the end of the iteration.- Specified by:
iterate
in interfaceorg.apache.commons.rdf.api.Graph
-
stream
Stream<RDF4JTriple> stream()Note that for graphs backed by a repository (
RDF4JGraphLike.asRepository()
is present), the stream must be closed withBaseStream.close()
.This can generally achieved using a try-with-resources block, e.g.:
int subjects; try (Stream<RDF4JTriple> s : graph.stream()) { subjects = s.map(RDF4JTriple::getSubject).distinct().count() }
- Specified by:
stream
in interfaceorg.apache.commons.rdf.api.Graph
- Specified by:
stream
in interfaceorg.apache.commons.rdf.api.GraphLike<org.apache.commons.rdf.api.Triple>
-
stream
Stream<RDF4JTriple> stream(org.apache.commons.rdf.api.BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, org.apache.commons.rdf.api.RDFTerm object) Note that for graphs backed by a repository (
RDF4JGraphLike.asRepository()
is present), the stream must be closed withBaseStream.close()
.This can generally achieved using a try-with-resources block, e.g.:
int subjects; try (Stream<RDF4JTriple> s : graph.stream(s,p,o)) { subjects = s.map(RDF4JTriple::getSubject).distinct().count() }
- Specified by:
stream
in interfaceorg.apache.commons.rdf.api.Graph
-