convert method
Converts an RDF graph to a JSON-LD string representation.
This method analyzes the graph structure and automatically determines the most appropriate JSON-LD representation:
- For empty graphs, it returns an empty JSON object
{} - For graphs with a single subject, it creates a single JSON-LD object with all properties of that subject
- For graphs with multiple subjects, it creates a JSON-LD document with
a top-level
@grapharray containing all subject nodes
The method also:
- Generates consistent labels for blank nodes
- Creates a
@contextobject with meaningful prefixes based on the graph content - Groups triples by subject for better structure
- Handles typed literals appropriately
graph The RDF graph to convert to JSON-LD.
baseUri Optional base URI for relative IRIs. When provided and
includeBaseDeclaration is true, it will be included in the @context.
Returns a formatted JSON-LD string with 2-space indentation.
Implementation
@override
String convert(RdfGraph graph, {String? baseUri}) {
return _encoder.convert(RdfDataset.fromDefaultGraph(graph),
baseUri: baseUri);
}