TurtleEncoder constructor
TurtleEncoder({
- RdfNamespaceMappings? namespaceMappings,
- TurtleEncoderOptions options = const TurtleEncoderOptions(),
Creates a new Turtle encoder with the specified options.
Parameters:
namespaceMappingsOptional custom namespace mappings to use for resolving prefixes. If not provided, default RDF namespace mappings are used.optionsConfiguration options that control encoding behavior. Default options include automatic prefix generation.
Example:
// Create an encoder with custom options
final encoder = TurtleEncoder(
namespaceMappings: extendedNamespaces,
options: TurtleEncoderOptions(generateMissingPrefixes: false)
);
Implementation
TurtleEncoder({
RdfNamespaceMappings? namespaceMappings,
TurtleEncoderOptions options = const TurtleEncoderOptions(),
}) : _options = options,
// Use default namespace mappings if none provided
_namespaceMappings = namespaceMappings ?? RdfNamespaceMappings() {
_iriCompaction = IriCompaction(
_namespaceMappings,
IriCompactionSettings(
generateMissingPrefixes: options.generateMissingPrefixes,
renderFragmentsAsPrefixed: options.renderFragmentsAsPrefixed,
iriRelativization: options.iriRelativization,
allowedCompactionTypes: {
...allowedCompactionTypesAll,
IriRole.predicate: {
IriCompactionType.full,
IriCompactionType.prefixed,
// Allow relative IRIs for predicates when fragments should be rendered as relative
if (!options.renderFragmentsAsPrefixed) IriCompactionType.relative
},
IriRole.type: {IriCompactionType.full, IriCompactionType.prefixed}
},
specialPredicates: {
Rdf.type,
},
specialDatatypes: {
_booleanDatatype,
_decimalDatatype,
//_doubleDatatype,
_integerDatatype,
_stringDatatype,
Rdf.langString,
}),
(String localPart) => RdfNamespaceMappings.isValidLocalPart(localPart,
allowNumericLocalNames: options.useNumericLocalNames),
);
}