RdfGraph class final

Represents an immutable RDF graph with triple pattern matching capabilities

An RDF graph is formally defined as a set of RDF triples. This class provides functionality for working with such graphs, including:

  • Creating graphs from sets of triples
  • Adding or removing triples (creating new graph instances)
  • Merging graphs
  • Querying triples based on patterns
  • Optional lazy indexing for improved query performance

The class is designed to be immutable for thread safety and to prevent accidental modification. All operations that would modify the graph return a new instance.

Indexing Behavior: When indexing is enabled (default), an internal index is created lazily on the first query operation that can benefit from it. This means there is no immediate memory cost for enabling indexing - the memory is only used when and if queries are performed.

Example:

// Create a graph with some initial triples
final graph = RdfGraph(triples: [
  Triple(john, name, johnSmith),
  Triple(john, knows, jane)
]);

// Create a new graph with an additional triple
final updatedGraph = graph.withTriple(Triple(jane, name, janeSmith));

Constructors

RdfGraph.new({Iterable<Triple> triples = const [], bool enableIndexing = true})
Creates an immutable RDF graph from a list of triples

Properties

hashCode int
Provides a consistent hash code for this graph based on its triples.
no setteroverride
indexingEnabled bool
final
isEmpty bool
Whether this graph contains any triples
no setter
isNotEmpty bool
Whether this graph contains at least one triple
no setter
objects Set<RdfObject>
Get all unique objects (values) in this graph
no setter
predicates Set<RdfPredicate>
Get all unique predicates (properties) in this graph
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Number of triples in this graph
no setter
subjects Set<RdfSubject>
Get all unique subjects in this graph
no setter
triples List<Triple>
Get all triples in the graph
no setter

Methods

findTriples({RdfSubject? subject, RdfPredicate? predicate, RdfObject? object}) List<Triple>
Find all triples matching the given pattern
getObjects(RdfSubject subject, RdfPredicate predicate) List<RdfObject>
Get all objects for a given subject and predicate
getSubjects(RdfPredicate predicate, RdfObject object) List<RdfSubject>
Get all subjects with a given predicate and object
hasTriples({RdfSubject? subject, RdfPredicate? predicate, RdfObject? object}) bool
Checks if the graph contains any triples matching the given pattern
matching({RdfSubject? subject, RdfPredicate? predicate, RdfObject? object}) RdfGraph
Creates a new graph containing only triples that match the given pattern
merge(RdfGraph other, {dynamic removeDuplicates = true}) RdfGraph
Merges this graph with another, producing a new graph
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subgraph(RdfSubject root, {TraversalFilter? filter}) RdfGraph
Extracts a subgraph starting from a root subject with optional traversal control
toString() String
A string representation of this object.
inherited
withOptions({bool? enableIndexing}) RdfGraph
Creates a new graph with modified configuration options
without(RdfGraph other) RdfGraph
Creates a new graph by removing all triples from another graph
withoutMatching({RdfSubject? subject, RdfPredicate? predicate, RdfObject? object}) RdfGraph
Creates a new graph by filtering out triples that match a pattern
withoutTriples(Iterable<Triple> triples) RdfGraph
Creates a new graph with the specified triples removed
withTriple(Triple triple) RdfGraph
Creates a new graph with the specified triple added
withTriples(Iterable<Triple> triples, {bool removeDuplicates = true}) RdfGraph
Creates a new graph with all the specified triples added

Operators

operator ==(Object other) bool
We are implementing equals ourselves instead of using equatable, because we want to compare the sets of triples, not the order
override

Static Methods

fromTriples(Iterable<Triple> triples, {bool enableIndexing = true}) RdfGraph
Creates an RDF graph from a list of triples (factory constructor)