convert method

  1. @override
RdfDataset convert(
  1. String input, {
  2. String? documentUrl,
})

Decodes an RDF dataset document and returns an RDF dataset

This method transforms a textual RDF dataset document into a structured RdfDataset object containing quads parsed from the input and organized into default and named graphs. It implements the convert method from the Converter interface.

Parameters:

  • input The RDF dataset document to decode, as a string.
  • documentUrl The absolute URL of the document, used for resolving relative IRIs. If not provided, relative IRIs will be kept as-is or handled according to format-specific rules.

Returns:

  • An RdfDataset containing the quads parsed from the input, organized into graphs.

The specific decoding behavior depends on the implementation of this interface, which will handle format-specific details like prefix resolution, blank node handling, and graph context management, etc.

May throw format-specific parsing exceptions if the input is malformed.

Implementation

@override
RdfDataset convert(String input, {String? documentUrl}) {
  final parsedInput = parseJsonValueOrThrow(input, format: _format);
  final effectiveInput = _options.expandContext == null
      ? input
      : jsonEncode(_applyExpandContext(parsedInput, _options.expandContext!));
  final parser = JsonLdParser(
    effectiveInput,
    baseUri: _options.baseUri ?? documentUrl,
    iriTermFactory: _iriTermFactory,
    format: _format,
    rdfDirection: _options.rdfDirection,
    processingMode: _options.processingMode,
    contextDocumentProvider: _options.contextDocumentProvider,
    skipInvalidRdfTerms: _options.skipInvalidRdfTerms,
  );
  return RdfDataset.fromQuads(parser.parse());
}