locorda_rdf_jelly 0.12.2 copy "locorda_rdf_jelly: ^0.12.2" to clipboard
locorda_rdf_jelly: ^0.12.2 copied to clipboard

Jelly RDF binary serialization codec for Dart. High-performance streaming RDF format based on Protocol Buffers for linked data and knowledge graph applications.

example/main.dart

/// Jelly RDF Batch Encode/Decode Example
///
/// Demonstrates the batch API for encoding an [RdfGraph] to Jelly binary
/// format and decoding it back, using the global [jellyGraph] codec.
///
/// The Jelly format uses Protocol Buffers wire format with IRI lookup-table
/// compression, achieving significantly smaller output than text-based RDF
/// formats like Turtle or N-Triples.
library;

import 'package:locorda_rdf_core/core.dart';
import 'package:locorda_rdf_jelly/jelly.dart';
import 'package:locorda_rdf_terms_common/foaf.dart';

void main() {
  print('Jelly RDF Batch Encode/Decode Example');
  print('=====================================\n');

  final ex = 'http://example.org/';

  // Build a small RDF graph
  final graph = RdfGraph(triples: [
    Triple(IriTerm('${ex}alice'), Foaf.name, LiteralTerm.string('Alice')),
    Triple(IriTerm('${ex}alice'), Foaf.knows, IriTerm('${ex}bob')),
    Triple(IriTerm('${ex}bob'), Foaf.name, LiteralTerm.string('Bob')),
  ]);

  print('Original graph: ${graph.triples.length} triples');
  for (final t in graph.triples) {
    print('  $t');
  }

  // Encode to Jelly binary format
  final bytes = jellyGraph.encode(graph);
  print('\nEncoded to ${bytes.length} bytes (Jelly binary)');

  // Decode back to an RdfGraph
  final decoded = jellyGraph.decode(bytes);
  print('Decoded graph: ${decoded.triples.length} triples');
  for (final t in decoded.triples) {
    print('  $t');
  }

  // Verify roundtrip
  final originalSet = graph.triples.toSet();
  final decodedSet = decoded.triples.toSet();
  print(
      '\nRoundtrip OK: ${originalSet.length == decodedSet.length && originalSet.containsAll(decodedSet)}');
}
0
likes
160
points
306
downloads

Documentation

Documentation
API reference

Publisher

verified publisherlocorda.dev

Weekly Downloads

Jelly RDF binary serialization codec for Dart. High-performance streaming RDF format based on Protocol Buffers for linked data and knowledge graph applications.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#rdf #linked-data #semantic-web #binary #protobuf

License

MIT (license)

Dependencies

locorda_rdf_core, logging, protobuf

More

Packages that depend on locorda_rdf_jelly