Function rdf_canon::api::canonicalize_quads_with
source · pub fn canonicalize_quads_with<D: Digest>(
input_quads: &[Quad],
options: &CanonicalizationOptions
) -> Result<String, CanonicalizationError>
Expand description
Given some options (e.g., call limit), returns the serialized canonical form of the canonicalized dataset, where any blank nodes in the input quads are assigned deterministic identifiers.
§Examples
use oxrdf::Quad;
use oxttl::NQuadsParser;
use rdf_canon::{canonicalize_quads_with, CanonicalizationOptions};
use sha2::Sha256;
use std::io::Cursor;
let input = r#"_:e0 <http://example.org/vocab#next> _:e1 _:g .
_:e0 <http://example.org/vocab#prev> _:e2 _:g .
_:e1 <http://example.org/vocab#next> _:e2 _:g .
_:e1 <http://example.org/vocab#prev> _:e0 _:g .
_:e2 <http://example.org/vocab#next> _:e0 _:g .
_:e2 <http://example.org/vocab#prev> _:e1 _:g .
<urn:ex:s> <urn:ex:p> "\u0008\u0009\u000a\u000b\u000c\u000d\u0022\u005c\u007f" _:g .
"#;
let expected = r#"<urn:ex:s> <urn:ex:p> "\b\t\n\u000B\f\r\"\\\u007F" _:c14n0 .
_:c14n1 <http://example.org/vocab#next> _:c14n2 _:c14n0 .
_:c14n1 <http://example.org/vocab#prev> _:c14n3 _:c14n0 .
_:c14n2 <http://example.org/vocab#next> _:c14n3 _:c14n0 .
_:c14n2 <http://example.org/vocab#prev> _:c14n1 _:c14n0 .
_:c14n3 <http://example.org/vocab#next> _:c14n1 _:c14n0 .
_:c14n3 <http://example.org/vocab#prev> _:c14n2 _:c14n0 .
"#;
let input_quads: Vec<Quad> = NQuadsParser::new()
.parse_read(Cursor::new(input))
.map(|x| x.unwrap())
.collect();
let options = CanonicalizationOptions {
hndq_call_limit: Some(10000),
};
let canonicalized = canonicalize_quads_with::<Sha256>(&input_quads, &options).unwrap();
assert_eq!(canonicalized, expected);