convert method
Converts an RDF graph to a Turtle string representation.
This method serializes the given RDF graph to the Turtle format with advanced formatting features including:
- Automatically detecting and writing prefix declarations
- Grouping triples by subject for more compact output
- Proper indentation and formatting for readability
- Optimizing blank nodes that appear only once as objects by inlining them
- Serializing RDF collections (lists) in the compact Turtle '(item1 item2)' notation
Parameters:
graphThe RDF graph to serialize to TurtlebaseUriOptional base URI to use for resolving relative IRIs and generating shorter references. When provided and includeBaseDeclaration is true, a @base directive will be included in the output. When includeBaseDeclaration is false, the baseUri is still used for URI relativization but not declared in the output.
Returns:
- A properly formatted Turtle string representation of the input graph.
Example:
final graph = RdfGraph();
// Add some triples to the graph
Implementation
@override
String convert(RdfGraph graph, {String? baseUri}) =>
_encoder.convert(RdfDataset.fromDefaultGraph(graph), baseUri: baseUri);