TriGEncoder class
Encoder for serializing RDF datasets to TriG syntax.
The TriG format is an extension of Turtle that supports named graphs, allowing multiple RDF graphs to be represented in a single document. This encoder implements the W3C TriG recommendation, with additional optimizations for readability and compactness.
Features:
- Automatic namespace prefix generation
- Compact representation for blank nodes and collections
- Proper indentation and formatting for readability
- Support for base URI relative references
- Special handling for common datatypes (integers, decimals, booleans)
- Named graph support with GRAPH keyword and shorthand syntax
Example usage:
import 'package:locorda_rdf_core/core.dart';
final dataset = RdfDataset.fromQuads([Quad(
const IriTerm('http://example.org/subject'),
const IriTerm('http://example.org/predicate'),
LiteralTerm('object')
)]);
final encoder = TriGEncoder();
final trig = encoder.convert(dataset);
See: TriG - RDF Dataset Language
NOTE: Always use canonical RDF vocabularies (e.g., http://xmlns.com/foaf/0.1/) with http://, not https:// This encoder will warn if it detects use of https:// for a namespace that is canonical as http://.
- Inheritance
-
- Object
- Converter<
RdfDataset, String> - RdfEncoder<
RdfDataset> - RdfDatasetEncoder
- TriGEncoder
Constructors
- TriGEncoder({RdfNamespaceMappings? namespaceMappings, TriGEncoderOptions options = const TriGEncoderOptions()})
- Creates a new TriG encoder with the specified options.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- options → RdfGraphEncoderOptions
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
Stream< RdfDataset> stream) → Stream<String> -
Transforms the provided
stream.inherited -
cast<
RS, RT> () → Converter< RS, RT> -
Provides a
Converter<RS, RT>view of this stream transformer.inherited -
compactDatasetIris(
List< RdfGraph> allGraphs, RdfDataset dataset, String? baseUri) → IriCompactionResult -
convert(
RdfDataset dataset, {String? baseUri}) → String -
Converts an RDF graph to a Turtle string representation.
override
-
fuse<
TT> (Converter< String, TT> other) → Converter<RdfDataset, TT> -
Fuses
thiswithother.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startChunkedConversion(
Sink< String> sink) → Sink<RdfDataset> -
Starts a chunked conversion.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withOptions(
RdfGraphEncoderOptions options) → RdfDatasetEncoder -
Creates a new encoder with the specified options, preserving the current namespace mappings.
override
-
writeTerm(
RdfTerm term, {required IriRole iriRole, required IriCompactionResult compactedIris, required Map< BlankNodeTerm, String> blankNodeLabels}) → String - Convert RDF terms to Turtle syntax string representation
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited