Interface Dataset
-
- All Known Subinterfaces:
JsonLdDataset,RDF4JDataset
- All Known Implementing Classes:
DatasetImpl,JsonLdDatasetImpl,RepositoryDatasetImpl
public interface Dataset extends java.lang.AutoCloseable, GraphLike<Quad>
An RDF 1.1 Dataset, a set of RDF quads, as defined by RDF-1.1 Concepts and Abstract Syntax, a W3C Recommendation published on 25 February 2014.- Since:
- 0.3.0-incubating
- See Also:
RDF.createDataset()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidadd(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)Add a quad to the dataset, possibly mapping any of the components to those supported by this dataset.voidadd(Quad quad)Add a quad to the dataset, possibly mapping any of the components of the Quad to those supported by this dataset.voidclear()Clear the dataset, removing all quads.default voidclose()Close the dataset, relinquishing any underlying resources.booleancontains(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)Check if dataset contains a pattern of quads.booleancontains(Quad quad)Check if dataset contains quad.GraphgetGraph()Get the default graph of this dataset.java.util.Optional<Graph>getGraph(BlankNodeOrIRI graphName)Get a named graph in this dataset.java.util.stream.Stream<BlankNodeOrIRI>getGraphNames()Get the graph names in this Dataset.default java.lang.Iterable<Quad>iterate()Get an Iterable for iterating over all quads in the dataset.default java.lang.Iterable<Quad>iterate(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)Get an Iterable for iterating over the quads in the dataset that match the pattern.voidremove(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)Remove a concrete pattern of quads from the default graph of the dataset.voidremove(Quad quad)Remove a concrete quad from the dataset.longsize()Number of quads contained by the dataset.java.util.stream.Stream<? extends Quad>stream()Get all quads contained by the dataset.java.util.stream.Stream<? extends Quad>stream(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)Get all quads contained by the dataset matched with the pattern.
-
-
-
Method Detail
-
add
void add(Quad quad)
Add a quad to the dataset, possibly mapping any of the components of the Quad to those supported by this dataset.
-
add
void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Add a quad to the dataset, possibly mapping any of the components to those supported by this dataset.- Parameters:
graphName- The graph the quad belongs to, ornullfor the default graphsubject- The quad subjectpredicate- The quad predicateobject- The quad object
-
contains
boolean contains(Quad quad)
Check if dataset contains quad.
-
contains
boolean contains(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Check if dataset contains a pattern of quads.- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- True if the dataset contains any quads that match the given pattern.
-
close
default void close() throws java.lang.ExceptionClose the dataset, relinquishing any underlying resources.For example, this would close any open file and network streams and free database locks held by the dataset implementation.
The behaviour of the other dataset methods are undefined after closing the dataset.
Implementations might not need
close(), hence the default implementation does nothing.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
getGraph
Graph getGraph()
Get the default graph of this dataset.The
Triples of the default graph are equivalent to theQuads in this Dataset which has theQuad.getGraphName()set toOptional.empty().It is unspecified if modifications to the returned Graph are reflected in this Dataset.
The returned graph MAY be empty.
- Returns:
- The default graph of this Dataset
- See Also:
getGraph(BlankNodeOrIRI)
-
getGraph
java.util.Optional<Graph> getGraph(BlankNodeOrIRI graphName)
Get a named graph in this dataset.The
Triples of the named graph are equivalent to the the Quads of this Dataset which has theQuad.getGraphName()equal to the providedgraphName, or equal toOptional.empty()if the providedgraphNameisnull.It is unspecified if modifications to the returned Graph are reflected in this Dataset.
It is unspecified if requesting an unknown or empty graph will return
Optional.empty()or create a new emptyGraph.- Parameters:
graphName- The name of the graph, ornullfor the default graph.- Returns:
- The named Graph, or
Optional.empty()if the dataset do not contain the named graph. - See Also:
getGraph(),getGraphNames()
-
getGraphNames
java.util.stream.Stream<BlankNodeOrIRI> getGraphNames()
Get the graph names in this Dataset.The set of returned graph names is equivalent to the set of unique
Quad.getGraphName()of all thestream()of this dataset (excluding the default graph).The returned
StreamSHOULD NOT contain duplicate graph names.The graph names can be used with
getGraph(BlankNodeOrIRI)to retrieve the correspondingGraph, however callers should be aware of any concurrent modifications to the Dataset may cause such calls to returnOptional.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
getGraph()or by usingOptional.empty()in the Quad access methods).- Returns:
- A
Streamof the graph names of this Dataset.
-
remove
void remove(Quad quad)
Remove a concrete quad from the dataset.
-
remove
void remove(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Remove a concrete pattern of quads from the default graph of the dataset.- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)
-
clear
void clear()
Clear the dataset, removing all quads.
-
size
long size()
Number of quads contained by the dataset.The count of a set does not include duplicates, consistent with the
Quad.equals(Object)equals method for eachQuad.
-
stream
java.util.stream.Stream<? extends Quad> stream()
Get all quads contained by the dataset.
The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object)method for eachQuad.The behaviour of the
Streamis not specified ifadd(Quad),remove(Quad)orclear()are called on theDatasetbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.
-
stream
java.util.stream.Stream<? extends Quad> stream(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Get all quads contained by the dataset matched with the pattern.The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object)method for eachQuad.The behaviour of the
Streamis not specified ifadd(Quad),remove(Quad)orclear()are called on theDatasetbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- A
Streamover the matched quads.
-
iterate
default java.lang.Iterable<Quad> iterate() throws java.util.ConcurrentModificationException, java.lang.IllegalStateException
Get an Iterable for iterating over all quads in the dataset.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 ifadd(Quad),remove(Quad)orclear(), are called on theDatasetbefore it terminates. It is undefined if the returnedIteratorsupports theIterator.remove()method.Implementations may throw
ConcurrentModificationExceptionfrom 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. AIllegalStateExceptionmay be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream()to return itsBaseStream.iterator().- Specified by:
iteratein interfaceGraphLike<Quad>- Returns:
- A
Iterablethat returnsIteratorover all of the quads in the dataset - Throws:
java.lang.IllegalStateException- if theIterablehas been reusedjava.util.ConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.
-
iterate
default java.lang.Iterable<Quad> iterate(java.util.Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws java.util.ConcurrentModificationException, java.lang.IllegalStateException
Get an Iterable for iterating over the quads in the dataset that match the pattern.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
add(Quad),remove(Quad)orclear(), are called on theDatasetbefore it terminates. It is undefined if the returnedIteratorsupports theIterator.remove()method.Implementations may throw
ConcurrentModificationExceptionfrom 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. AIllegalStateExceptionmay be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream(Optional, BlankNodeOrIRI, IRI, RDFTerm)to return itsBaseStream.iterator().- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- A
Iterablethat returnsIteratorover the matching quads in the dataset - Throws:
java.lang.IllegalStateException- if theIterablehas been reusedjava.util.ConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.
-
-