RDF Canonicalization is a process that transforms RDF graphs into a deterministic, standard form. This is essential for:
import 'package:rdf_canonicalization/rdf_canonicalization.dart';
import 'package:rdf_core/rdf_core.dart';
void main() {
// Two N-Quads with same meaning, different blank node labels
final nquads1 = '''
_:alice <http://xmlns.com/foaf/0.1/name> "Alice" .
_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .
_:bob <http://xmlns.com/foaf/0.1/name> "Bob" .
''';
final nquads2 = '''
_:person1 <http://xmlns.com/foaf/0.1/name> "Alice" .
_:person1 <http://xmlns.com/foaf/0.1/knows> _:person2 .
_:person2 <http://xmlns.com/foaf/0.1/name> "Bob" .
''';
final dataset1 = nquads.decode(nquads1);
final dataset2 = nquads.decode(nquads2);
// Test semantic equivalence
print('Are isomorphic: ${isIsomorphic(dataset1, dataset2)}'); // true
// Get canonical forms (identical for isomorphic graphs)
final canonical1 = canonicalize(dataset1);
final canonical2 = canonicalize(dataset2);
print('Canonical forms match: ${canonical1 == canonical2}'); // true
}
Produces identical canonical forms for semantically equivalent RDF graphs, enabling reliable digital signatures and caching.
Efficient blank node labeling algorithm with configurable hash functions (SHA-256, SHA-384) for speed vs security trade-offs.
Fast semantic equivalence testing between RDF graphs and datasets, essential for data comparison workflows.
Full support for RDF datasets with named graphs, not just simple RDF graphs. Handle complex multi-graph scenarios.
Implements the W3C RDF Dataset Canonicalization specification for interoperability with other systems.
Works seamlessly with rdf_core library for complete RDF processing workflows in Dart applications.
This canonicalization library works together with other RDF packages for complete RDF functionality:
# Add to your pubspec.yaml dart pub add rdf_canonicalization dart pub add rdf_core # For creating RDF graphs
| Function/Class | Description |
|---|---|
canonicalize() |
Canonicalize an RdfDataset to N-Quads string |
canonicalizeGraph() |
Canonicalize an RdfGraph to N-Quads string |
isIsomorphic() |
Test if two RdfDatasets are isomorphic |
isIsomorphicGraphs() |
Test if two RdfGraphs are isomorphic |
CanonicalRdfGraph |
Cached canonical representation of an RdfGraph |
CanonicalRdfDataset |
Cached canonical representation of an RdfDataset |