Interface Graph
-
- All Known Subinterfaces:
JsonLdGraph
,JsonLdUnionGraph
,RDF4JGraph
- All Known Implementing Classes:
DatasetGraphView
,GraphImpl
,JsonLdGraphImpl
,JsonLdUnionGraphImpl
,ModelGraphImpl
,RepositoryGraphImpl
public interface Graph extends java.lang.AutoCloseable, GraphLike<Triple>
An RDF 1.1 Graph, a set of RDF triples, as defined by RDF-1.1 Concepts and Abstract Syntax, a W3C Recommendation published on 25 February 2014.- See Also:
RDF.createGraph()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.void
add(Triple triple)
Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.void
clear()
Clears the graph, removing all triples.default void
close()
Closes the graph, relinquishing any underlying resources.boolean
contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Checks if graph contains a pattern of triples.boolean
contains(Triple triple)
Checks if graph contains triple.default java.util.stream.Stream<? extends Triple>
getTriples()
Deprecated.default java.util.stream.Stream<? extends Triple>
getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Deprecated.default java.lang.Iterable<Triple>
iterate()
Gets an Iterable for iterating over all triples in the graph.default java.lang.Iterable<Triple>
iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Gets an Iterable for iterating over the triples in the graph that match the pattern.void
remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Removes a concrete pattern of triples from the graph.void
remove(Triple triple)
Removes a concrete triple from the graph.long
size()
Number of triples contained by the graph.java.util.stream.Stream<? extends Triple>
stream()
Gets all triples contained by the graph.java.util.stream.Stream<? extends Triple>
stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Gets all triples contained by the graph matched with the pattern.
-
-
-
Method Detail
-
add
void add(Triple triple)
Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.
-
add
void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.- Parameters:
subject
- The triple subjectpredicate
- The triple predicateobject
- The triple object
-
contains
boolean contains(Triple triple)
Checks if graph contains triple.
-
contains
boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Checks if graph contains a pattern of triples.- Parameters:
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)- Returns:
- True if the Graph contains any Triples that match the given pattern.
-
close
default void close() throws java.lang.Exception
Closes the graph, relinquishing any underlying resources.For example, this would close any open file and network streams and free database locks held by the Graph implementation.
The behaviour of the other Graph methods are undefined after closing the graph.
Implementations might not need
close()
, hence the default implementation does nothing.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
remove
void remove(Triple triple)
Removes a concrete triple from the graph.
-
remove
void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Removes a concrete pattern of triples from the graph.- Parameters:
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)
-
clear
void clear()
Clears the graph, removing all triples.
-
size
long size()
Number of triples contained by the graph.The count of a set does not include duplicates, consistent with the
Triple.equals(Object)
equals method for eachTriple
.
-
stream
java.util.stream.Stream<? extends Triple> stream()
Gets all triples contained by the graph.
The iteration does not contain any duplicate triples, as determined by the
Triple.equals(Object)
method for eachTriple
.The behaviour of the
Stream
is not specified ifadd(Triple)
,remove(Triple)
orclear()
are called on theGraph
before it terminates.Implementations may throw
ConcurrentModificationException
from Stream methods if they detect a conflict while the Stream is active.
-
stream
java.util.stream.Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Gets all triples contained by the graph matched with the pattern.The iteration does not contain any duplicate triples, as determined by the
Triple.equals(Object)
method for eachTriple
.The behaviour of the
Stream
is not specified ifadd(Triple)
,remove(Triple)
orclear()
are called on theGraph
before it terminates.Implementations may throw
ConcurrentModificationException
from Stream methods if they detect a conflict while the Stream is active.- Parameters:
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)- Returns:
- A
Stream
over the matched triples. - Since:
- 0.3.0-incubating
-
getTriples
@Deprecated default java.util.stream.Stream<? extends Triple> getTriples()
Deprecated.This method is deprecated, use the equivalent methodstream()
instead.- Returns:
- A
Stream
over all triples.
-
getTriples
@Deprecated default java.util.stream.Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Deprecated.This method is deprecated, use the equivalent methodstream(BlankNodeOrIRI, IRI, RDFTerm)
instead.- Parameters:
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)- Returns:
- A
Stream
over the matched triples.
-
iterate
default java.lang.Iterable<Triple> iterate() throws java.util.ConcurrentModificationException, java.lang.IllegalStateException
Gets an Iterable for iterating over all triples in the graph.This method is meant to be used with a Java for-each loop, e.g.:
for (Triple t : graph.iterate()) { System.out.println(t); }
The behaviour of the iterator is not specified ifadd(Triple)
,remove(Triple)
orclear()
, are called on theGraph
before it terminates. It is undefined if the returnedIterator
supports theIterator.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. AIllegalStateException
may be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream()
to return itsBaseStream.iterator()
.- Specified by:
iterate
in interfaceGraphLike<Triple>
- Returns:
- A
Iterable
that returnsIterator
over all of the triples in the graph - Throws:
java.lang.IllegalStateException
- if theIterable
has been reusedjava.util.ConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is active.
-
iterate
default java.lang.Iterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws java.util.ConcurrentModificationException, java.lang.IllegalStateException
Gets an Iterable for iterating over the triples in the graph 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 (Triple t : graph.iterate(alice, knows, null)) { System.out.println(t.getObject()); }
The behaviour of the iterator is not specified if
add(Triple)
,remove(Triple)
orclear()
, are called on theGraph
before it terminates. It is undefined if the returnedIterator
supports theIterator.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. AIllegalStateException
may be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream(BlankNodeOrIRI, IRI, RDFTerm)
to return itsBaseStream.iterator()
.- Parameters:
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)- Returns:
- A
Iterable
that returnsIterator
over the matching triples in the graph - Throws:
java.lang.IllegalStateException
- if theIterable
has been reusedjava.util.ConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is active.
-
-