Class ModelGraphImpl
- All Implemented Interfaces:
AutoCloseable, Graph, GraphLike<Triple>, RDF4JGraph, RDF4JGraphLike<Triple>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.voidAdds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.Optional<org.eclipse.rdf4j.model.Model> asModel()Return the corresponding RDF4JModel, if present.Optional<org.eclipse.rdf4j.repository.Repository> Return the corresponding RDF4JRepository, if present.voidclear()Clears the graph, removing all triples.booleancontains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Checks if graph contains a pattern of triples.booleanChecks if graph contains triple.Return a copy of the context mask as aSetofRDF4JBlankNodeOrIRIgraph names.iterate()Gets an Iterable for iterating over all triples in the graph.iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Gets an Iterable for iterating over the triples in the graph that match the pattern.voidremove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Removes a concrete pattern of triples from the graph.voidRemoves a concrete triple from the graph.longsize()Number of triples contained by the graph.stream()Gets all triples contained by the graph.stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Gets all triples contained by the graph matched with the pattern.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Graph
close, getTriples, getTriples
-
Field Details
-
model
private final org.eclipse.rdf4j.model.Model model -
rdf4jTermFactory
-
-
Constructor Details
-
ModelGraphImpl
ModelGraphImpl(org.eclipse.rdf4j.model.Model model, RDF4J rdf4jTermFactory)
-
-
Method Details
-
add
Description copied from interface:GraphAdds a triple to the graph, possibly mapping any of the components to those supported by this Graph. -
add
Description copied from interface:GraphAdds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph. -
asModel
Description copied from interface:RDF4JGraphLikeReturn the corresponding RDF4JModel, if present.The return value is
Optional.isPresent()if this is backed by a Model.Changes to the Model are reflected in both directions.
- Specified by:
asModelin interfaceRDF4JGraphLike<Triple>- Returns:
- The corresponding RDF4J Model.
-
asRepository
Description copied from interface:RDF4JGraphLikeReturn the corresponding RDF4JRepository, if present.The return value is
Optional.isPresent()if this is backed by a Repository.Changes to the Repository are reflected in both directions.
- Specified by:
asRepositoryin interfaceRDF4JGraphLike<Triple>- Returns:
- The corresponding RDF4J Repository.
-
clear
-
contains
Description copied from interface:GraphChecks if graph contains a pattern of triples. -
contains
Description copied from interface:GraphChecks if graph contains triple. -
remove
Description copied from interface:GraphRemoves a concrete pattern of triples from the graph. -
remove
-
size
public long size()Description copied from interface:GraphNumber 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
Description copied from interface:RDF4JGraphGets 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
Streamis not specified ifGraph.add(Triple),Graph.remove(Triple)orGraph.clear()are called on theGraphbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.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() } -
stream
Description copied from interface:RDF4JGraphGets 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
Streamis not specified ifGraph.add(Triple),Graph.remove(Triple)orGraph.clear()are called on theGraphbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.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:
streamin interfaceGraph- Specified by:
streamin interfaceRDF4JGraph- 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
Streamover the matched triples.
-
getContextMask
Description copied from interface:RDF4JGraphReturn a copy of the context mask as aSetofRDF4JBlankNodeOrIRIgraph names.If the set is not
Set.isEmpty(), the mask determines which contexts in the corresponding RDF4JModelorRepositorythat 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...)- Specified by:
getContextMaskin interfaceRDF4JGraph- Returns:
- The context mask as a set of
BlankNodeOrIRIgraph names, which may contain the valuenull.
-
iterate
Description copied from interface:RDF4JGraphGets 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
Graph.add(Triple),Graph.remove(Triple)orGraph.clear(), are called on theGraphbefore 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
Graph.stream(BlankNodeOrIRI, IRI, RDFTerm)to return itsBaseStream.iterator().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:
iteratein interfaceGraph- Specified by:
iteratein interfaceRDF4JGraph- 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
Iterablethat returnsIteratorover the matching triples in the graph
-
iterate
public ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateExceptionDescription copied from interface:RDF4JGraphGets 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 ifGraph.add(Triple),Graph.remove(Triple)orGraph.clear(), are called on theGraphbefore 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
Graph.stream()to return itsBaseStream.iterator().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()) { 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:
iteratein interfaceGraph- Specified by:
iteratein interfaceGraphLike<Triple>- Specified by:
iteratein interfaceRDF4JGraph- Returns:
- A
Iterablethat returnsIteratorover all of the triples in the graph - Throws:
ConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.IllegalStateException- if theIterablehas been reused
-