quads property

Iterable<Quad> get quads

Get all statements in this dataset as quads

Returns an iterable collection of all RDF statements in this dataset as Quad objects, preserving graph context information. This provides a unified view of the entire dataset where:

  • Default graph triples become quads with null graph names
  • Named graph triples become quads with their respective graph names

This is particularly useful for:

  • N-Quads serialization where graph context is required
  • Dataset-wide operations that need graph context
  • Converting datasets to quad-based processing pipelines
  • Bulk operations across all graphs in the dataset

Returns: An iterable collection of Quad objects representing all statements in the dataset with their graph context. The order is not guaranteed.

Example:

// Process all statements with graph context
for (final quad in dataset.quads) {
  if (quad.isDefaultGraph) {
    print('Default: ${quad.triple}');
  } else {
    print('Graph ${quad.graphName}: ${quad.triple}');
  }
}

// Count total statements across all graphs
final totalStatements = dataset.quads.length;

// Filter quads by graph
final peopleQuads = dataset.quads
    .where((quad) => quad.graphName?.iri.contains('people') ?? false);

Implementation

Iterable<Quad> get quads sync* {
  // Yield default graph quads (with null graph name)
  for (final triple in defaultGraph.triples) {
    yield Quad.fromTriple(triple);
  }

  // Yield named graph quads (with their graph names)
  for (final entry in _namedGraphs.entries) {
    final graphName = entry.key;
    final graph = entry.value;
    for (final triple in graph.triples) {
      yield Quad.fromTriple(triple, graphName);
    }
  }
}