public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad>
| Modifier and Type | Method and Description |
|---|---|
Stream<BlankNodeOrIRI> |
getGraphNames()
Get the graph names in this Dataset.
|
ClosableIterable<Quad> |
iterate()
Get an Iterable for iterating over all quads in the dataset.
|
ClosableIterable<Quad> |
iterate(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Get an Iterable for iterating over the quads in the dataset that match
the pattern.
|
Stream<RDF4JQuad> |
stream()
Get all quads contained by the dataset.
|
Stream<RDF4JQuad> |
stream(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Get all quads contained by the dataset matched with the pattern.
|
add, add, clear, close, contains, contains, getGraph, getGraph, remove, remove, sizeasModel, asRepositoryStream<RDF4JQuad> stream()
The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object) method for each Quad.
The behaviour of the Stream is not specified if
Dataset.add(Quad), Dataset.remove(Quad) or Dataset.clear() are called
on the Dataset before it terminates.
Implementations may throw ConcurrentModificationException from
Stream methods if they detect a conflict while the Stream is active.
Note that for datasets backed by a repository (RDF4JGraphLike.asRepository() is
present), the stream must be closed with
BaseStream.close().
This can generally achieved using a try-with-resources block, e.g.:
int subjects;
try (Stream<RDF4JQuad> s : graph.stream()) {
subjects = s.map(RDF4JQuad::getSubject).distinct().count()
}
Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object) method for each Quad.
The behaviour of the Stream is not specified if
Dataset.add(Quad), Dataset.remove(Quad) or Dataset.clear() are called
on the Dataset before it terminates.
Implementations may throw ConcurrentModificationException from
Stream methods if they detect a conflict while the Stream is active.
Note that for datasets backed by a repository (RDF4JGraphLike.asRepository() is
present), the stream must be closed with
BaseStream.close().
This can generally achieved using a try-with-resources block, e.g.:
int subjects;
try (Stream<RDF4JQuad> s : graph.stream()) {
subjects = s.map(RDF4JQuad::getSubject).distinct().count()
}
stream in interface DatasetgraphName - The graph the quad belongs to, wrapped as an Optional
(null is a wildcard, Optional.empty() is
the default graph)subject - The quad subject (null is a wildcard)predicate - The quad predicate (null is a wildcard)object - The quad object (null is a wildcard)Stream over the matched quads.Stream<BlankNodeOrIRI> getGraphNames()
The set of returned graph names is equivalent to the set of unique
Quad.getGraphName() of all the Dataset.stream() of this dataset
(excluding the default graph).
The returned Stream SHOULD NOT contain duplicate graph names.
The graph names can be used with Dataset.getGraph(BlankNodeOrIRI) to
retrieve the corresponding Graph, however callers should be aware
of any concurrent modifications to the Dataset may cause such calls to
return Optional.empty().
Note that a Dataset always contains a default graph
which is not named, and thus is not represented in the returned Stream.
The default graph is accessible via Dataset.getGraph() or by using
Optional.empty() in the Quad access methods).
Note that for datasets backed by a repository (RDF4JGraphLike.asRepository() is
present), the stream must be closed with
BaseStream.close().
This can generally achieved using a try-with-resources block, e.g.:
int graphs;
try (Stream<BlankNodeOrIRI> s : graph.stream()) {
graphs = s.count()
}
getGraphNames in interface DatasetStream of the graph names of this Dataset.ClosableIterable<Quad> iterate()
This method is meant to be used with a Java for-each loop, e.g.:
for (Quad t : dataset.iterate()) {
System.out.println(t);
}
The behaviour of the iterator is not specified if Dataset.add(Quad),
Dataset.remove(Quad) or Dataset.clear(), are called on the
Dataset before it terminates. It is undefined if the returned
Iterator supports the Iterator.remove() method.
Implementations may throw ConcurrentModificationException from
Iterator methods if they detect a concurrency conflict while the Iterator
is active.
The Iterable.iterator() must only be called once, that is the
Iterable must only be iterated over once. A IllegalStateException
may be thrown on attempt to reuse the Iterable.
The default implementation of this method will call Dataset.stream() to
return its BaseStream.iterator().
Note that for datasets backed by a repository (RDF4JGraphLike.asRepository() is
present), the iterable must be closed with
AutoCloseable.close().
This can generally achieved using a try-with-resources block, e.g.:
try (ClosableIterable<Quad> s : graph.iterate()) {
for (Quad q : quads) {
return q; // 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.ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
This method is meant to be used with a Java for-each loop, e.g.:
IRI alice = factory.createIRI("http://example.com/alice");
IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
for (Quad t : dataset.iterate(null, alice, knows, null)) {
System.out.println(t.getGraphName());
System.out.println(t.getObject());
}
The behaviour of the iterator is not specified if Dataset.add(Quad),
Dataset.remove(Quad) or Dataset.clear(), are called on the
Dataset before it terminates. It is undefined if the returned
Iterator supports the Iterator.remove() method.
Implementations may throw ConcurrentModificationException from
Iterator methods if they detect a concurrency conflict while the Iterator
is active.
The Iterable.iterator() must only be called once, that is the
Iterable must only be iterated over once. A IllegalStateException
may be thrown on attempt to reuse the Iterable.
The default implementation of this method will call
Dataset.stream(Optional, BlankNodeOrIRI, IRI, RDFTerm) to return its
BaseStream.iterator().
Note that for datasets backed by a repository (RDF4JGraphLike.asRepository() is
present), the iterable must be closed with
AutoCloseable.close().
This can generally achieved using a try-with-resources block, e.g.:
try (ClosableIterable<Quad> s : graph.iterate(g,s,p,o)) {
for (Quad q : quads) {
return q; // 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.iterate in interface DatasetgraphName - The graph the quad belongs to, wrapped as an Optional
(null is a wildcard, Optional.empty() is
the default graph)subject - The quad subject (null is a wildcard)predicate - The quad predicate (null is a wildcard)object - The quad object (null is a wildcard)Iterable that returns Iterator over the
matching quads in the datasetCopyright © 2015–2018 The Apache Software Foundation. All rights reserved.